React Native 键盘事件不适用于 android:windowSoftInputMode="adjustNothing"; [英] React Native keyboard events not working with android:windowSoftInputMode="adjustNothing"

查看:174
本文介绍了React Native 键盘事件不适用于 android:windowSoftInputMode="adjustNothing";的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在显示键盘时仅调整视图的一个组件,因此我设置了"adjustNothing" 在我的 android 清单文件中,我使用 "keyboardDidHide" 事件侦听器和 TextInput onFocus 处理组件的移动.我试过了,但是当键盘隐藏时我没有从听众那里得到任何东西......

I am trying to adjust only one component of my view when keyboard is shown so i set "adjustNothing" in my android manifest file and I handle the movement of the component with "keyboardDidHide" event listener and with TextInput onFocus. I tried this but I'm not getting anything from the listener when keyboard hides...

这是我的 AnidroidManifest 文件:

Here is my AnidroidManifest File:

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

<application
  android:name=".MainApplication"
  android:label="@string/app_name"
  android:icon="@mipmap/ic_launcher"
  android:allowBackup="false"
  android:theme="@style/AppTheme">
  <activity
    android:name=".MainActivity"
    android:label="@string/app_name"
    android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
    android:screenOrientation="portrait"
    android:windowSoftInputMode="adjustNothing">
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
  </activity>
  <activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />
</application>

这就是键盘隐藏时我想要做的:

And this is what i want to do when keyboard hides:

keyboardDidHide() {
this.animateS(false);
}

所以它动画回到原位.

我尝试了 adjustResizeadjustPan,但它们将整个视图向上移动,我不想要那样.动画是在显示键盘时向上平移,在隐藏事件触发时向下平移.

I tried with adjustResize and adjustPan but they move the whole view up and i don't want that. the animation is a simple translate up when keyboard is shown and down when did hide event triggers.

在文档中:

请注意,如果您将 android:windowSoftInputMode 设置为 adjustResize 或adjustNothing,只有 keyboardDidShow 和 keyboardDidHide 事件在安卓上可用https://facebook.github.io/react-native/docs/keyboard

Note that if you set android:windowSoftInputMode to adjustResize or adjustNothing, only keyboardDidShow and keyboardDidHide events will be available on Android https://facebook.github.io/react-native/docs/keyboard

这是反应原生的错误还是我做错了什么,有什么想法吗?

Is this a bug with react native or am i doing something wrong, any ideas?

推荐答案

这是 React Native 文档中的一个错误.

This is an error in the React Native Documentation.

正如 andreicoman11这个回复 github问题:...键盘事件实际上不是用adjustNothing触发的,因为它的实现方式,以及不幸的是没有办法解决...

As andreicoman11 stated in this reply to a github issue: ... keyboard events are actually not triggered with adjustNothing because of the way it's implemented, and unfortunately there's no way around that ...

React Native 未能在 https://facebook.github.io/react-native/docs/keyboard

React native failed to document that at https://facebook.github.io/react-native/docs/keyboard

这篇关于React Native 键盘事件不适用于 android:windowSoftInputMode="adjustNothing";的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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