android - 为什么 android 键盘会触发我的导航返回
问题描述
好的,这就是问题所在。当我按下 android 输入插入文本时,键盘出现,我的屏幕导航回来。这仅发生在 Android 上。每次输入都会发生这种情况,如果我在打开键盘的情况下启动屏幕并关闭它,则会出现同样的问题。我知道我没有使用最新版本的 react-native 或库。
这是我的环境和 package.json。
"react-native": "0.61.3"
"@react-native-community/datetimepicker": "^2.2.2",
"@react-native-community/masked-view": "^0.1.5",
"@react-navigation/bottom-tabs": "^5.0.0-alpha.34",
"@react-navigation/core": "^5.0.0-alpha.32",
"@react-navigation/drawer": "^5.0.0-alpha.36",
"@react-navigation/material-bottom-tabs": "^5.0.0-alpha.31",
"@react-navigation/material-top-tabs": "^5.0.0-alpha.30",
"@react-navigation/native": "^5.0.0-alpha.24",
"@react-navigation/stack": "^5.0.0-alpha.58",
环境
SO: Ubuntu 20.04 LTS (Also tried on OSX)
node: 14.1.0
API Android: 28
npm:6.14.4
该应用程序看起来像这样。(不完全是代码,我刚加入这个项目,代码真是让人头疼。)
//App.js
<Tab.Navigator
initialRouteName={'HOME'}
tabBarOptions={{
activeTintColor: 'white',
style: {backgroundColor: 'black'},
}}>
<Tab.Screen
name="Account"
component={props => <ProfileTab {...props} />}
>
</Tab.Screen>
</Tab.Navigator>
//ProfileTab.js
<Stack.Navigator
mode="modal"
headerMode="none"
initialRouteName="SessionFilter"
>
<Stack.Screen
component={props => (
<Login
close={() => {
if (!currentUser) navigation.navigate('SessionFilter');
navigation.goBack();
}}
sendToRegister={() => {
navigation.goBack();
navigation.navigate('Registry');
}}
/>
)}
name="Login"
/>
</Stack.Navigator>
//Login.js
return (
<SafeAreaView style={{ flex: 1, backgroundColor: "white" }}>
<ScrollView
contentContainerStyle={{
backgroundColor: "white",
paddingHorizontal: 15,
minWidth: 350,
alignItems: "center",
flex: 1,
minHeight: Dimensions.get("window").height + 30,
}}
>
<TextField>
</ScrollView>
</SafeAreaView>
);
};
//TextField.js
import React from 'react';
import { TextField } from 'react-native-material-textfield';
export const TextField = (props) => (
<TextField
{...props}
tintColor="black"
textColor="black"
fontSize={12}
autoCapitalize="none"
onChangeText={text => props.onChange({ target: { value: text } })}
titleTextStyle={{ fontSize: 10 }}
contentInset={{ label: 0 }}
secureTextEntry={props.type && props.type === "password"}
/>
);
我试图恢复所有糟糕的代码,但它是这样的。省略了我认为不重要的部分。
解决方案
推荐阅读
- mockito - 如何在 Spring Boot 应用程序中为 JDBC 模板编写 Mockito Junit 测试用例?
- android - 在 android TV Leanback 中从遥控器的后退按钮隐藏键盘
- python - 将嵌套字典重构为 CSV 文件中的三角矩阵
- python - Pandas 对多列进行分组并根据非分组列中的条件附加值
- javascript - 如何在 For 语句中运行 If 语句以仅显示数据集的特定行
- stanford-nlp - 如何指定斯坦福 CoreNLP 服务器将破折号/连字符视为空格
- domain-driven-design - DDD:如何按状态查询多聚合根
- tensorflow - TensorFlow 分类无效参数错误
- python-3.x - 如何在不带显示的服务器上创建和保存 tkinter.Canvas 图像
- powershell - PowerShell:需要在两行/行之间获取值