React-native:如何控制键盘向上推 [英] React-native: How to control what keyboard pushes up

查看:109
本文介绍了React-native:如何控制键盘向上推的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

该应用程序的结构相当简单:底部有一个搜索栏、一个列表视图和 react-native-tabs.问题:如果我点击 Android 上的搜索栏,它会将整个应用程序向上推,所以我会直接在键盘上看到选项卡.但是在 iOS 上,键盘覆盖了整个应用程序,没有向上推任何东西.有什么办法可以控制吗?
如果问题不清楚,我很乐意分享代码/屏幕截图.
谢谢

The structure of the app is fairly simple: A searchbar, a listview and react-native-tabs at the bottom. The problem: If I click on the searchbar on Android it pushes the whole app up, so I see the tabs directly over the keyboard. But on iOS the keyboard overlays the whole app, without pushing anything up. Is there any way to control that?
I'm happy to share code / screenshots if the question isn't clear.
Thanks

<View style={{flex:1, backgroundColor:'#f2f2f2'}}>
    <ListView
        dataSource={this.state.dataSource}
        renderRow={this.renderSearchResults.bind(this)}
        style={styles.listView}/>
    <KeyboardAvoidingView
        style={styles.addQuestionBar}
        behavior={'position'}>
        <Text>
            Don't see your question?
        </Text>
        <TouchableOpacity>
            <Text>
                Add it
            </Text>
        </TouchableOpacity>
    </KeyboardAvoidingView>
</View>

推荐答案

在您的清单文件中设置 android:windowSoftInputMode="adjustPan",它会按您的预期工作.

Set android:windowSoftInputMode="adjustPan" in your manifest file, and it will work as you expect.

例如

<application
  android:name=".MainApplication"
  android:allowBackup="true"
  ...
  <activity
    android:name=".MainActivity"
    android:label="@string/app_name"
    ...
    android:windowSoftInputMode="adjustPan">
    ...
  </activity>
  ...
</application>

这篇关于React-native:如何控制键盘向上推的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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