Permalink
Browse files

Add one more parameter(keyboardType) to AlertIOS.promot().

Summary:
Add one more parameter which can specify the keyboard type of first text input(if exists) to AlertIOS.prompt().

Example usage:
`AlertIOS.prompt('Type a phone number', null, null, 'plain-text', undefined, 'phone-pad')`
Closes #8781

Differential Revision: D4437900

Pulled By: hramos

fbshipit-source-id: 8141cc0d7c70d13603cd5a1d5ea3f1ab1ce437a6
  • Loading branch information...
yueshuaijie authored and facebook-github-bot committed Jan 19, 2017
1 parent 06956e8 commit 94f71a38847a71735b9325a6af93467df3172b3d
Showing with 23 additions and 2 deletions.
  1. +11 −0 Examples/UIExplorer/js/AlertIOSExample.js
  2. +8 −2 Libraries/Alert/AlertIOS.js
  3. +4 −0 React/Modules/RCTAlertManager.m
@@ -144,6 +144,17 @@ class PromptOptions extends React.Component {
</View>
</TouchableHighlight>
+ <TouchableHighlight
+ style={styles.wrapper}
+ onPress={() => AlertIOS.prompt('Type a phone number', null, null, 'plain-text', undefined, 'phone-pad')}>
+
+ <View style={styles.button}>
+ <Text>
+ prompt with title & custom keyboard
+ </Text>
+ </View>
+ </TouchableHighlight>
+
<TouchableHighlight
style={styles.wrapper}
onPress={() => AlertIOS.prompt('Type a value', null, this.saveResponse, undefined, 'Default value')}>
@@ -164,6 +164,10 @@ class AlertIOS {
* @param type This configures the text input. One of 'plain-text',
* 'secure-text' or 'login-password'.
* @param defaultValue The default text in text input.
+ * @param keyboardType 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'.
*
* @example <caption>Example with custom buttons</caption>
*
@@ -193,13 +197,14 @@ class AlertIOS {
callbackOrButtons?: ?((text: string) => void) | ButtonsArray,
type?: ?AlertType = 'plain-text',
defaultValue?: string,
+ keyboardType?: string
): void {
if (typeof type === 'function') {
console.warn(
'You passed a callback function as the "type" argument to AlertIOS.prompt(). React Native is ' +
'assuming you want to use the deprecated AlertIOS.prompt(title, defaultValue, buttons, callback) ' +
- 'signature. The current signature is AlertIOS.prompt(title, message, callbackOrButtons, type, defaultValue) ' +
- 'and the old syntax will be removed in a future version.');
+ 'signature. The current signature is AlertIOS.prompt(title, message, callbackOrButtons, type, defaultValue, ' +
+ 'keyboardType) and the old syntax will be removed in a future version.');
var callback = type;
var defaultValue = message;
@@ -244,6 +249,7 @@ class AlertIOS {
defaultValue,
cancelButtonKey,
destructiveButtonKey,
+ keyboardType,
}, (id, value) => {
var cb = callbacks[id];
cb && cb(value);
@@ -72,6 +72,7 @@ - (void)invalidate
NSString *defaultValue = [RCTConvert NSString:args[@"defaultValue"]];
NSString *cancelButtonKey = [RCTConvert NSString:args[@"cancelButtonKey"]];
NSString *destructiveButtonKey = [RCTConvert NSString:args[@"destructiveButtonKey"]];
+ UIKeyboardType keyboardType = [RCTConvert UIKeyboardType:args[@"keyboardType"]];
if (!title && !message) {
RCTLogError(@"Must specify either an alert title, or message, or both");
@@ -106,6 +107,7 @@ - (void)invalidate
[alertController addTextFieldWithConfigurationHandler:^(UITextField *textField) {
textField.secureTextEntry = NO;
textField.text = defaultValue;
+ textField.keyboardType = keyboardType;
}];
break;
}
@@ -114,13 +116,15 @@ - (void)invalidate
textField.placeholder = RCTUIKitLocalizedString(@"Password");
textField.secureTextEntry = YES;
textField.text = defaultValue;
+ textField.keyboardType = keyboardType;
}];
break;
}
case RCTAlertViewStyleLoginAndPasswordInput: {
[alertController addTextFieldWithConfigurationHandler:^(UITextField *textField) {
textField.placeholder = RCTUIKitLocalizedString(@"Login");
textField.text = defaultValue;
+ textField.keyboardType = keyboardType;
}];
[alertController addTextFieldWithConfigurationHandler:^(UITextField *textField) {
textField.placeholder = RCTUIKitLocalizedString(@"Password");

0 comments on commit 94f71a3

Please sign in to comment.