javascript - React Native AlertIOS 占位符
问题描述
我正在使用带有输入 的AlertIOS :
AlertIOS.prompt(
'Reset password',
'Please enter your email in order to reset your password.',
[
{
text: 'Cancel',
onPress: () => console.log('Cancel Pressed'),
style: 'cancel',
},
{
text: 'Continue',
onPress: (password) => console.log('OK Pressed, password: ' + password),
},
],
'plain-text',
'',
'email-address'
);
我希望在该警报中为 TextInput 添加一个占位符。这可能吗?我知道有一个默认值选项,但是我希望有一个占位符来代替它。
解决方案
从技术上讲,在 iOS 中是可能的,在 react-native 中可能吗?目前的简短回答是否定的。
不可能的原因是 TextField 的占位符属性尚未暴露给 react-native 端。如果我们查看 st 中的代码,RCTAlertManager.m
我们可以看到为and选项placeholder
设置了默认值,但是无法设置选项的默认值Password
Login
plain-text
https://github.com/facebook/react-native/blob/master/React/Modules/RCTAlertManager.m
switch (type) {
case RCTAlertViewStylePlainTextInput: {
[alertController addTextFieldWithConfigurationHandler:^(UITextField *textField) {
textField.secureTextEntry = NO;
textField.text = defaultValue;
textField.keyboardType = keyboardType;
}];
break;
}
case RCTAlertViewStyleSecureTextInput: {
[alertController addTextFieldWithConfigurationHandler:^(UITextField *textField) {
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");
textField.secureTextEntry = YES;
}];
break;
}
case RCTAlertViewStyleDefault:
break;
}
完成这项工作的唯一方法是找到一个能够placeholder
在TextInput
. Alert
或者您可以根据RCTAlertManager.m
允许您设置placeholder
推荐阅读
- xquery - 在什么时候加载变量?
- javascript - 如何使用猫鼬进行分组/聚合?
- angular - 自动扩展所有延迟加载的配置节点
- google-apps-script - 更改 Google Doc 中的链接表源
- json - 使用 getter 和 setter 将 json 转换为构造函数
- python - /login/ 'is_login' 请求方法处的 KeyError:django
- java - 由于无法在循环期间再次获得用户输入,程序重复 switch-case
- java - 如何在 Eclipse 的 Package 视图中将多个源文件夹合并为单个条目
- python - 如何为列表中的出现次数制作字典
- php - 如何为特定用户禁用 WooCommerce 产品单独销售?