react-native - React Native 只允许 TextInput 的小写输入

标签 react-native

是否有可能有一个只允许小写输入的用于 native react 的 TextInput?

截至目前,尝试了以下代码:

state = { login: '' }

changeUsernameToLowercase = (input) => {
  var temp = input.toLowerCase()
  this.setState({login: temp})
}

<TextInput
  onChangeText={(login) => this.changeUsernameToLowercase(login)}
  value={this.state.login}
  autoCapitalize='none' />

但它似乎不适用于某些 android 设备。

也许有更有效的方法来做到这一点?

最佳答案

这可能会解决您的问题,它对我有用。
TextInput 内添加这三行, 原创 answer source

 autoCapitalize="none"
 secureTextEntry={true}
 keyboardType={"visible-password"}

例子
import React, { useState } from "react";
import { View, TextInput } from "react-native";


export default function App () {
    const [text,setText] = useState('');
    
    return (
      <View>
        <TextInput
           autoCapitalize="none"
           secureTextEntry={true}
           keyboardType={"visible-password"}
          style={{height: 40, borderColor: 'gray', borderWidth: 1,width:"100%"}}
          value={text}
          onChangeText={ text => setText(text.toLowerCase()) }
        />
      </View>
    );
}

关于react-native - React Native 只允许 TextInput 的小写输入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53038187/

相关文章:

Xcode 不反射(reflect)来自 react-native 的最新应用程序代码

android - React Native 陷入配置 React-Native-gesture-handler 的困境

android - React Native Gradle assembleDebug 需要一个小时

react-native - React Native - 检查蓝牙是否打开,如果没有提醒用户?

android - React Native 输出是 .class(对于 android)和 .c(对于 iOS)

javascript - 如何正确从 firebase 访问 uid 以将记录添加到另一个数据库中?

javascript - 在 React Native App 的 WebView 中包含外部 JavaScript 文件

ios - react native 构建错误 : Could not read optimization profile file (even after change optimization configuration)

reactjs - 当多个组件使用复杂对象的一部分作为其源时,redux 如何工作

react-native - 在 native react 中显示 Base64 svg