Skip to content

Commit

Permalink
Add one more parameter(keyboardType) to AlertIOS.promot().
Browse files Browse the repository at this point in the history
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 94f71a3
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
11 changes: 11 additions & 0 deletions Examples/UIExplorer/js/AlertIOSExample.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')}>
Expand Down
10 changes: 8 additions & 2 deletions Libraries/Alert/AlertIOS.js
Original file line number Diff line number Diff line change
Expand Up @@ -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>
*
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -244,6 +249,7 @@ class AlertIOS {
defaultValue,
cancelButtonKey,
destructiveButtonKey,
keyboardType,
}, (id, value) => {
var cb = callbacks[id];
cb && cb(value);
Expand Down
4 changes: 4 additions & 0 deletions React/Modules/RCTAlertManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -106,6 +107,7 @@ - (void)invalidate
[alertController addTextFieldWithConfigurationHandler:^(UITextField *textField) {
textField.secureTextEntry = NO;
textField.text = defaultValue;
textField.keyboardType = keyboardType;
}];
break;
}
Expand All @@ -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");
Expand Down

0 comments on commit 94f71a3

Please sign in to comment.