React Native:TextInput toUpperCase在onChangeText上的Android上不起作用

问题描述 投票:0回答:1

我有一个TextInput组件,应在键入时将输入转换为大写。我的代码如下:

import React, {Component} from 'react';
import { View, StyleSheet, Text, TextInput, Button } from 'react-native';

export default class ProfileTest extends React.Component {

 constructor(props) {
    super(props);
    this.state = {text : ''};
  }

  render() {
    return ( 
     <View>
          <TextInput
            style={{fontSize : 60}}
            onChangeText={text => {
              text = text
                .toUpperCase();
              this.setState({ text: text });
            }}
            value={this.state.text}
            placeholder="enter text"
          />

        </View>
    )
  }
}

在Expo上,这确实有效。但是,当我在Android设备上尝试此操作时,出现以下行为:

前两个字母可以正常工作,但是每当我添加第三个字母时,它都会突然重复前两个字母,以便ABC-> ABABC我不知道为什么要这么做,而且我似乎无法摆脱它。我已将“ .toUpperCase()”确定为罪魁祸首。

感谢您的帮助!

reactjs native repeat uppercase textinput
1个回答
0
投票

我在这里有同样的问题!看起来原因是toUpperCase方法,但找不到原因。到目前为止有什么解决方法吗?

© www.soinside.com 2019 - 2024. All rights reserved.