|
1 | 1 | --- |
2 | 2 | id: alertios |
3 | | -title: AlertIOS |
| 3 | +title: '❌ AlertIOS' |
4 | 4 | --- |
5 | 5 |
|
6 | | -`AlertIOS`用于弹出一个 iOS 提示对话框,可以通知用户一些信息或是提示用户输入一些文字。 |
7 | | - |
8 | | -弹出一个 iOS 提示框: |
9 | | - |
10 | | -``` |
11 | | -AlertIOS.alert( |
12 | | - 'Sync Complete', |
13 | | - 'All your data are belong to us.' |
14 | | -); |
15 | | -``` |
16 | | - |
17 | | -弹出一个带输入框的 iOS 提示框: |
18 | | - |
19 | | -``` |
20 | | -AlertIOS.prompt( |
21 | | - 'Enter a value', |
22 | | - null, |
23 | | - text => console.log("You entered "+text) |
24 | | -); |
25 | | -``` |
26 | | - |
27 | | -其他情况下,尤其是仅仅显示一个静态的提示框时,应该使用跨平台的[`Alert`](alert.md)。 |
28 | | - |
29 | | ---- |
30 | | - |
31 | | -# 文档 |
32 | | - |
33 | | -## 方法 |
34 | | - |
35 | | -### `alert()` |
36 | | - |
37 | | -```jsx |
38 | | -static alert(title: string, [message]: string, [callbackOrButtons]: ?(() => void), ButtonsArray, [type]: AlertType): [object Object] |
39 | | -``` |
40 | | - |
41 | | -创建并显示一个提示框。 |
42 | | - |
43 | | -**参数:** |
44 | | - |
45 | | -| 名称 | 类型 | 必需 | 说明 | |
46 | | -| ----------------- | ------------------------------------------------------ | ---- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | |
47 | | -| title | string | 是 | The dialog's title. Passing null or '' will hide the title. | |
48 | | -| message | string | 否 | An optional message that appears below the dialog's title. | |
49 | | -| callbackOrButtons | ?(() => void),[ButtonsArray](alertios.md#buttonsarray) | 否 | This optional argument should be either a single-argument function or an array of buttons. If passed a function, it will be called when the user taps 'OK'. If passed an array of button configurations, each button should include a `text` key, as well as optional `onPress` and `style` keys. `style` should be one of 'default', 'cancel' or 'destructive'. | |
50 | | -| 类型 | [AlertType](alertios.md#alerttype) | 否 | Deprecated, do not use. | |
51 | | - |
52 | | -Example with custom buttons: |
53 | | - |
54 | | -```jsx |
55 | | -AlertIOS.alert( |
56 | | - 'Update available', |
57 | | - 'Keep your app up to date to enjoy the latest features', |
58 | | - [ |
59 | | - { |
60 | | - text: 'Cancel', |
61 | | - onPress: () => console.log('Cancel Pressed'), |
62 | | - style: 'cancel', |
63 | | - }, |
64 | | - { |
65 | | - text: 'Install', |
66 | | - onPress: () => console.log('Install Pressed'), |
67 | | - }, |
68 | | - ], |
69 | | -); |
70 | | -``` |
71 | | - |
72 | | ---- |
73 | | - |
74 | | -### `prompt()` |
75 | | - |
76 | | -```jsx |
77 | | -static prompt(title: string, [message]: string, [callbackOrButtons]: ?((text: string) => void), ButtonsArray, [type]: AlertType, [defaultValue]: string, [keyboardType]: string): [object Object] |
78 | | -``` |
79 | | - |
80 | | -Create and display a prompt to enter some text. |
81 | | - |
82 | | -**参数:** |
83 | | - |
84 | | -| 名称 | 类型 | 必需 | 说明 | |
85 | | -| ----------------- | ------------------------------------------------------------------ | ---- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | |
86 | | -| title | string | 是 | The dialog's title. | |
87 | | -| message | string | 否 | An optional message that appears above the text input. | |
88 | | -| callbackOrButtons | ?((text: string) => void),[ButtonsArray](alertios.md#buttonsarray) | 否 | This optional argument should be either a single-argument function or an array of buttons. If passed a function, it will be called with the prompt's value when the user taps 'OK'. If passed an array of button configurations, each button should include a `text` key, as well as optional `onPress` and `style` keys (see example). `style` should be one of 'default', 'cancel' or 'destructive'. | |
89 | | -| 类型 | [AlertType](alertios.md#alerttype) | 否 | This configures the text input. One of 'plain-text', 'secure-text' or 'login-password'. | |
90 | | -| defaultValue | string | 否 | The default text in text input. | |
91 | | -| keyboardType | string | 否 | The keyboard type of first text field(if exists). One of 'default', 'email-address', 'numeric', 'phone-pad', 'ascii-capable', 'numbers-and-punctuation', 'url', 'number-pad', 'name-phone-pad', 'decimal-pad', 'twitter' or 'web-search'. | |
92 | | - |
93 | | -Example with custom buttons: |
94 | | - |
95 | | -```jsx |
96 | | -AlertIOS.prompt( |
97 | | - 'Enter password', |
98 | | - 'Enter your password to claim your $1.5B in lottery winnings', |
99 | | - [ |
100 | | - { |
101 | | - text: 'Cancel', |
102 | | - onPress: () => console.log('Cancel Pressed'), |
103 | | - style: 'cancel', |
104 | | - }, |
105 | | - { |
106 | | - text: 'OK', |
107 | | - onPress: password => |
108 | | - console.log('OK Pressed, password: ' + password), |
109 | | - }, |
110 | | - ], |
111 | | - 'secure-text', |
112 | | -); |
113 | | -``` |
114 | | - |
115 | | -, |
116 | | - |
117 | | -Example with the default button and a custom callback: |
118 | | - |
119 | | -```jsx |
120 | | -AlertIOS.prompt( |
121 | | - 'Update username', |
122 | | - null, |
123 | | - text => console.log('Your username is ' + text), |
124 | | - null, |
125 | | - 'default', |
126 | | -); |
127 | | -``` |
128 | | - |
129 | | -## 类型定义 |
130 | | - |
131 | | -### AlertType |
132 | | - |
133 | | -An Alert button type |
134 | | - |
135 | | -| 类型 | |
136 | | -| ----- | |
137 | | -| $Enum | |
138 | | - |
139 | | -**常量:** |
140 | | - |
141 | | -| Value | 说明 | |
142 | | -| -------------- | ---------------------------- | |
143 | | -| default | Default alert with no inputs | |
144 | | -| plain-text | Plain text input alert | |
145 | | -| secure-text | Secure text input alert | |
146 | | -| login-password | Login and password alert | |
147 | | - |
148 | | ---- |
149 | | - |
150 | | -### AlertButtonStyle |
151 | | - |
152 | | -An Alert button style |
153 | | - |
154 | | -| 类型 | |
155 | | -| ----- | |
156 | | -| $Enum | |
157 | | - |
158 | | -**常量:** |
159 | | - |
160 | | -| Value | 说明 | |
161 | | -| ----------- | ------------------------ | |
162 | | -| default | Default button style | |
163 | | -| cancel | Cancel button style | |
164 | | -| destructive | Destructive button style | |
165 | | - |
166 | | ---- |
167 | | - |
168 | | -### ButtonsArray |
169 | | - |
170 | | -Array or buttons |
171 | | - |
172 | | -| 类型 | |
173 | | -| ----- | |
174 | | -| Array | |
175 | | - |
176 | | -**属性:** |
177 | | - |
178 | | -| 名称 | 类型 | 说明 | |
179 | | -| --------- | ------------------------------------------------ | ------------------------------------- | |
180 | | -| [text] | string | Button label | |
181 | | -| [onPress] | function | Callback function when button pressed | |
182 | | -| [style] | [AlertButtonStyle](alertios.md#alertbuttonstyle) | Button style | |
183 | | - |
184 | | -**常量:** |
185 | | - |
186 | | -| Value | 说明 | |
187 | | -| ------- | ------------------------------------- | |
188 | | -| text | Button label | |
189 | | -| onPress | Callback function when button pressed | |
190 | | -| style | Button style | |
| 6 | +:::danger 已从 React Native 中移除 |
| 7 | +请改用 [`Alert`](alert)。 |
| 8 | +::: |
0 commit comments