React Native 只允许 TextInput 的小写输入 [英] React Native Allow only lowercase input for TextInput

查看:37
本文介绍了React Native 只允许 TextInput 的小写输入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能有一个只允许小写输入的用于本机反应的 TextInput?

Is it possible to have a TextInput for react native that allows only lowercase input?

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

As of now, tried this code:

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 设备.

But it seems to not work on some android devices.

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

Maybe there is a more efficient way on doing this?

推荐答案

这可能会解决您的问题,它对我有用.
TextInput中添加这三行,原answer来源

This might solve your problem, it works for me.
Add these three lines inside TextInput, original 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 只允许 TextInput 的小写输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆