首页 > 解决方案 > 很难在 Android 中选择 TextInput 条目

问题描述

我不知道为什么在 Android 中选择输入如此困难,我一直按 TextInput 但无论输入是否为空,都不会显示全选、粘贴或复制选项。在 iOS 中它运行良好!

<View style={styles.reporterView}>
    <Text style={styles.reporterText}>Reporter:</Text>
       <TextInput
           value={this.state.reporter}
           onChangeText={(reporter) => this.setState({reporter})}
           style={styles.reporterField}
           placeholder={'Name'}
           autoCorrect={false}
           textAlign={'left'}
           maxLength={20}
           scrollEnabled={false}
       />
</View>
  reporterView: {
    flex: 1, 
    flexDirection: 'row', 
    marginBottom: 25, 
    paddingTop: 15,
    paddingLeft: '22%'
  },
  reporterField: {
    flex: 1,
    fontSize: 22, 
    height: 55, 
    marginLeft: 30,
    marginTop: Platform.OS == 'android' ? -12 : 0
  }

标签: reactjsreact-native

解决方案


这看起来像是 React-Native 和 Android 的常见问题。我从支持页面中找到了一个似乎运行良好的解决方案。

removeClippedSubviews默认设置为true。所以你必须把它设置为false

这些是找到它并设置为 false 的可能路径;

..\node_modules\react-navigation-material-bottom-tabs\node_modules\react-navigation-tabs\src\views\ResourceSavingScene.js

..\node_modules\react-navigation-tabs\src\views\ResourceSavingScene.js

..\node_modules\react-navigation-drawer\dist\view\ResourceSavingScene.js

..\node_modules\react-navigation-material-bottom-tabs\node_modules\react-navigation-tabs\dist\views\ResourceSavingScene.js

..\node_modules\react-native-paper\src\components\BottomNavigation.js

--

这是要使用的代码

removeClippedSubviews={
                 // On iOS, set removeClippedSubviews to true only when not focused
                 // This is an workaround for a bug where the clipped view never re-appears
                 Platform.OS === 'ios' ? navigationState.index !== index : true  //<--  set this to false
               }

参考:https ://github.com/facebook/react-native/issues/25038

以下是 Git 和 stackoverflow 上的其他解决方案。让我知道这些是否有帮助。

Stackoverflow:在 TextInput 中启用粘贴和选择 - React Native

Git:https ://github.com/facebook/react-native/issues/20887


推荐阅读