[英]React Native keyboard events not working with android:windowSoftInputMode=“adjustNothing”
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 . 当显示键盘时,我试图仅调整视图的一个组件,因此我在Android清单文件中设置了“ adjustNothing” ,并使用“ keyboardDidHide”事件监听器和TextInput onFocus处理了组件的移动。 I tried this but I'm not getting anything from the listener when keyboard hides...
我试过了,但是键盘隐藏时我没有从听众那里得到任何东西...
Here is my AnidroidManifest File: 这是我的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>
And this is what i want to do when keyboard hides: 这是键盘隐藏时我要执行的操作:
keyboardDidHide() {
this.animateS(false);
}
so it animates back in place. 因此它会恢复原状。
I tried with adjustResize and adjustPan but they move the whole view up and i don't want that. 我尝试使用adjustResize和adjustPan,但是它们将整个视图向上移动,我不希望这样。 the animation is a simple translate up when keyboard is shown and down when did hide event triggers.
动画是显示键盘时向上和向下隐藏事件触发器时的简单转换。
In the docs: 在文档中:
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
请注意,如果您将android:windowSoftInputMode设置为AdjustResize或AdjustNothing,则只有在Android https://facebook.github.io/react-native/docs/keyboard上可以使用keyboardDidShow和keyboardDidHide事件
Is this a bug with react native or am i doing something wrong, any ideas? 这是本机反应的错误,还是我做错了任何想法?
This is an error in the React Native Documentation. 这是React Native文档中的错误。
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 ...
正如andreicoman11在对github问题的答复中所指出的那样:
... 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 failed to document that at https://facebook.github.io/react-native/docs/keyboard React Native无法在https://facebook.github.io/react-native/docs/keyboard上证明这一点
Change the config param "adjustNothing" to "adjustPan" can solve my problem. 将配置参数“ adjustNothing”更改为“ adjustPan”可以解决我的问题。 Only "adjustPan", do not set with "adjustResize".
仅“ adjustPan”,不设置“ adjustResize”。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.