非常教程

React native参考手册

APIs

AlertIOS

AlertIOS 提供了用消息创建iOS警报对话框或为用户输入创建提示的功能。

创建iOS提醒:

AlertIOS.alert(
 'Sync Complete',
 'All your data are belong to us.'
);

创建一个iOS提示符:

AlertIOS.prompt(
  'Enter a value',
  null,
  text => console.log("You entered "+text)
);

如果您不需要创建仅限iOS的提示,我们建议使用该Alert.alert方法进行跨平台支持。

方法

static alert(title: string, message?: string, callbackOrButtons?: ?(() => void), ButtonsArray, type?: AlertType)

创建并显示一个弹出警报。

参数:

名称和类型

描述

titlestring

对话框的标题。一个空字符串隐藏标题。

messagestring

显示在对话框标题下的可选消息。

callbackOrButtons?(()=> void)| ButtonsArray

此可选参数应该是单参数函数或一组按钮。如果传递了一个函数,当用户点击“OK”时会被调用。如果传递了一组按钮配置,则每个按钮应包含一个文本键以及可选的onPress和样式键。风格应该是'默认','取消'或'破坏性'之一。

typeAlertType

已弃用,请勿使用。

自定义按钮示例:

AlertIOS.alert(
 'Update available',
 'Keep your app up to date to enjoy the latest features',
 [
   {text: 'Cancel', onPress: () => console.log('Cancel Pressed'), style: 'cancel'},
   {text: 'Install', onPress: () => console.log('Install Pressed')},
 ],
);

static prompt(title: string, message?: string, callbackOrButtons?: ?((text: string) => void), ButtonsArray, type?: AlertType, defaultValue?: string, keyboardType?: string)

创建并显示提示以输入一些文本。

参数:

名称和类型

描述

titlestring

对话框的标题。

messagestring

显示在文本输入上方的可选消息。

callbackOrButtons?((text:string)=> void)| ButtonsArray

此可选参数应该是单参数函数或一组按钮。如果传递一个函数,当用户点击'OK'时,它将被提示的值调用。如果传递了一组按钮配置,则每个按钮应包含一个文本键以及可选的onPress和样式键(请参阅示例)。风格应该是'默认','取消'或'破坏性'之一。

typeAlertType

这配置文本输入。“纯文本”,“安全文本”或“登录密码”之一。

defaultValuestring

文本输入中的默认文本。

keyboardTypestring

第一个文本字段的键盘类型(如果存在)。“默认”,“电子邮件地址”,“数字”,“电话簿”,“ascii-capable”,“数字和标点符号”,“网址”,“号码簿”,“姓名电话” 'pad','小数点','twitter'或'web-search'。

自定义按钮示例:

AlertIOS.prompt(
  'Enter password',
  'Enter your password to claim your $1.5B in lottery winnings',
  [
    {text: 'Cancel', onPress: () => console.log('Cancel Pressed'), style: 'cancel'},
    {text: 'OK', onPress: password => console.log('OK Pressed, password: ' + password)},
  ],
  'secure-text'
);

默认按钮和自定义回调的示例:

AlertIOS.prompt(
  'Update username',
  null,
  text => console.log("Your username is "+text),
  null,
  'default'
);

类型定义

警告类型

警报按钮类型

类型:

$Enum

常量:

描述

默认

没有输入的默认警报

纯文本

纯文本输入警报

安全文字

安全文本输入警报

登录密码

登录和密码提醒

AlertButtonStyle

警报按钮样式

类型:

$Enum

常量:

描述

默认

默认按钮样式

取消

取消按钮样式

有害

破坏性的按钮样式

ButtonsArray

数组或按钮

类型:

Array

属性:

名称和类型

描述

文本字符串

按钮标签

onPressfunction

按下按钮时的回调功能

styleAlertButtonStyle

按钮样式

常量:

描述

文本

按钮标签

onPress

按下按钮时的回调功能

样式

按钮样式

React native

React Native 是一个 JavaScript 的框架,用来撰写实时的、可原生呈现 iOS 和 Android 的应用。

主页 https://facebook.github.io/react-native/
源码 https://github.com/facebook/react-native
发布版本 0.49

React native目录

1.开始 | Getting Started
2.指南 | Guides
3.APIs
4.组件:ActivityIndicator | Components: ActivityIndicator
5.组件:按钮 | Components: Button
6.组件:CheckBox | Components: CheckBox
7.组件:DatePickerIOS | Components: DatePickerIOS
8.组件:DrawerLayoutAndroid | Components: DrawerLayoutAndroid
9.组件:FlatList | Components: FlatList
10.组件:图像 | Components: Image
11.组件:KeyboardAvoidingView | Components: KeyboardAvoidingView
12.Components: ListView
13.Components: MaskedViewIOS
14.Components: Modal
15.Components: NavigatorIOS
16.Components: Picker
17.Components: PickerIOS
18.Components: ProgressBarAndroid
19.Components: ProgressViewIOS
20.Components: RefreshControl
21.Components: ScrollView
22.Components: SectionList
23.Components: SegmentedControlIOS
24.Components: Slider
25.Components: SnapshotViewIOS
26.Components: StatusBar
27.Components: Switch
28.Components: TabBarIOS
29.Components: TabBarIOS.Item
30.Components: Text
31.Components: TextInput
32.Components: ToolbarAndroid
33.Components: TouchableHighlight
34.Components: TouchableNativeFeedback
35.Components: TouchableOpacity
36.Components: TouchableWithoutFeedback
37.Components: View
38.Components: ViewPagerAndroid
39.Components: VirtualizedList
40.Components: WebView
41.创建 | Contributing
42.指南(Android) | Guides (Android)
43.指南(IOS) | Guides (iOS)
44.其他 | Miscellaneous