在我真正的 Android 设备上,聚焦 TextInput
将屏幕插入堆栈导航后,键盘会闪烁一次(出现然后立即消失)。这不会在重新聚焦时发生,但如果我向后导航并使用其中包含 TextInputs 的任何屏幕重新推送导航,则会再次发生。
这不会发生:
navigation.navigate('...')
下面的这些代码与我的设备上运行的完全相同,只是简单的代码,没有花哨的东西。
应用.js
import * as React from 'react';
import { NavigationContainer } from '@react-navigation/native';
import { createStackNavigator } from '@react-navigation/stack';
import CategoryScreen from './screens/Category';
const MyStack = createStackNavigator();
export default function App() {
return (
<NavigationContainer>
<MyStack.Navigator>
<MyStack.Screen name="Category" component={CategoryScreen} />
</MyStack.Navigator>
</NavigationContainer>
);
}
Category.js import React from 'react';
import { View, TextInput, Button } from 'react-native';
export default function Category({ navigation }) {
function goToAnotherCategory() {
navigation.push('Category');
}
return (
<View>
<Button onPress={goToAnotherCategory} title="Go to Another Category" />
<TextInput style={{ margin: 10, borderWidth: 1, backgroundColor: 'white' }} />
</View>
)
}
我正在使用这些版本:"dependencies": {
...
"@react-navigation/native": "^5.5.1",
"@react-navigation/stack": "^5.5.1",
"react": "16.11.0",
"react-native": "0.62.2"
...
}
最佳答案
解决方案1:
最新版本的 react-navigation
也发生在我们身上。 .
作为一种解决方法,我们禁用了整个堆栈的键盘处理设置 keyboardHandlingEnabled
支持 false
.更多信息:https://reactnavigation.org/docs/stack-navigator/#keyboardhandlingenabled
所以现在它工作得很好。 :)
解决方案2:
在终端上运行这些命令
watchman watch-del-all
rm -rf node_modules && yarn
解决方案3:这也是由于版本兼容性。如果您使用 expo,请通过 expo CLI 安装这两个软件包
expo install @react-navigation/native
expo install @react-navigation/stack
关于javascript - React Native : After Navigate Push, First Focus TextInput 键盘闪烁,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62693464/