【问题标题】:There is an issue for using TextInput on android in react native在 react native 中使用 android 上的 TextInput 存在问题
【发布时间】:2018-12-03 15:25:56
【问题描述】:

我在使用 android 上的 TextInput 反应原生时遇到问题 我使用了以下代码。

导出默认类 App 扩展组件 { 使成为() { 返回 (

  </View>
);

} }

然后屏幕如下:

screenshot before tap TextInput

当我点击 TextInput 视图时,屏幕会像使用键盘避免视图一样出现。

screenshot after tap TextInput

它在android上,但在ios上没有任何效果。 我没有使用任何其他组件。

我的 package.json 如下:

{
  "name": "example",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "start": "node node_modules/react-native/local-cli/cli.js start",
    "test": "jest"
  },
  "dependencies": {
    "react": "16.6.1",
    "react-native": "0.57.7",
    "react-native-gesture-handler": "^1.0.10",
    "react-native-indicators": "^0.13.0",
    "react-native-maps": "^0.22.1",
    "react-native-maps-directions": "^1.6.0",
    "react-native-modal": "^7.0.1",
    "react-navigation": "^3.0.4"
  },
  "devDependencies": {
    "babel-jest": "23.6.0",
    "jest": "23.6.0",
    "metro-react-native-babel-preset": "0.50.0",
    "react-test-renderer": "16.6.1"
  },
  "jest": {
    "preset": "react-native"
  }
}

在 Android 上,尽管我从未使用过该组件,但为什么会有类似使用 KeyboardAvoidingView 的效果? 为什么在ios上可以? 我很高兴听到你的进步。 谢谢。

【问题讨论】:

    标签: android react-native


    【解决方案1】:

    每当您使用TextInput 时,建议您使用Scrollview 作为它的父视图,并带有一个道具keyboardShouldPersistTaps="always"。这将在键盘弹出时产生一致性。

    已编辑:

    <View style={{flex:1}}>
        <ScrollView keyboardShouldPersistTaps="always">
          <View style={{paddingTop:20}}> //Inside ScrollView flex doesn't work so use padding to control spacing 
    
              // Add your <TextInput> Tag here !!
    
           </View>
         </ScrollView>
    </View>
    

    希望能帮到你。

    【讨论】:

    • 嗨,罗恩。我很高兴听到你的回答。正如您在点击 TextInput 时可以看到我的屏幕截图那样,这个组件布局发生了变化,我不喜欢这样。你可以为我分享示例代码吗?
    • 我已编辑。做检查
    • 效果很好。非常感谢。我希望你以后能帮助我。
    • 嘿@WaterFlower,因为您是 Stack Overflow 的新贡献者。对于您完全满意的答案,如果您只能为这些答案打勾或投票,那就太好了。这将有助于鼓励社区更多地参与。谢谢。
    • 是的。我是 StackOverflow 的新手。你能告诉我如何为你的答案打勾或投票吗?
    猜你喜欢
    • 2021-03-29
    • 2018-09-11
    • 1970-01-01
    • 1970-01-01
    • 2023-02-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-29
    相关资源
    最近更新 更多