React Native 键盘事件不适用于 android:windowSoftInputMode="adjustNothing"

J. *_*Koe 5 android react-native

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

这是我的 AnidroidManifest 文件:

<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>
Run Code Online (Sandbox Code Playgroud)

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

keyboardDidHide() {
this.animateS(false);
}
Run Code Online (Sandbox Code Playgroud)

所以它会动画回到原位。

我尝试使用adjustmentResizeadjustmentPan,但它们将整个视图向上移动,我不希望这样。动画是一个简单的翻译,当键盘显示时向上翻译,当隐藏事件触发时向下翻译。

在文档中:

请注意,如果将 android:windowSoftInputMode 设置为 adjustmentResize 或 adjustmentNothing,则 Android 上仅提供 KeyboardDidShow 和 KeyboardDidHide 事件 https://facebook.github.io/react-native/docs/keyboard

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

小智 0

将配置参数“ adjustmentNothing”更改为“ adjustmentPan”可以解决我的问题。只能使用“adjustPan”,不要使用“adjustResize”进行设置。