具有版本的反应本机应用程序:
react@16.9.0
react-native@0.61.2
react-navigation@^4.0.10
react-navigation-stack@^1.10.3
react-navigation-tabs@^2.5.6
我正在尝试使用createBottomTabs创建一个应用程序,当我尝试输入TextInput时,当键盘显示时,有带有图标的bottomtabs,该图标将自动隐藏,在空格顶部留空白键盘
我的代码示例:
<SafeAreaView style={
flex: 1,
alignItems: 'center'
}>
<View>
<TextInput />
</View>
</SafeAreaView>
已经尝试使用KeyboardAvoidingView更改SafeAreaView,但是空格/空白仍然存在。
const MainTabs = createBottomTabNavigator({
Screen1: {
screen: Screen1Stack,
navigationOptions: {
tabBarIcon: Icon
}
},
Screen2: {
screen: Screen2Screen,
navigationOptions: {
tabBarIcon: Icon
}
},
Screen3: {
screen: Screen3Screen,
navigationOptions: {
tabBarIcon: Icon
}
},
Screen4: {
screen: Screen4Screen,
navigationOptions: {
tabBarIcon: Icon
}
},
},
{
tabBarOptions: {
...
showLabel: false
}
}
)
答案 0 :(得分:5)
我在react navigation tabs github(标题为“ Android#16上的底部标签栏和键盘”)上的评论中得到了答案,如果有人遇到与我相同的问题,我将在这里分享,答案为@ export-mike,由@hegelstad详细介绍
import React from 'react';
import { Platform, Keyboard } from 'react-native';
import { BottomTabBar } from 'react-navigation-tabs'; // need version 2.0 react-navigation of course... it comes preinstalled as a dependency of react-navigation.
export default class TabBarComponent extends React.Component {
state = {
visible: true
}
componentDidMount() {
if (Platform.OS === 'android') {
this.keyboardEventListeners = [
Keyboard.addListener('keyboardDidShow', this.visible(false)),
Keyboard.addListener('keyboardDidHide', this.visible(true))
];
}
}
componentWillUnmount() {
this.keyboardEventListeners && this.keyboardEventListeners.forEach((eventListener) => eventListener.remove());
}
visible = visible => () => this.setState({visible});
render() {
if (!this.state.visible) {
return null;
} else {
return (
<BottomTabBar {...this.props} />
);
}
}
}
用法:
const Tabs = createBottomTabNavigator({
TabA: {
screen: TabA,
path: 'tab-a',
navigationOptions: ({ navigation }) => ({
tabBarLabel: 'Tab A',
})
},
TabB: {
screen: TabB,
path: 'tab-b',
navigationOptions: ({ navigation }) => ({
tabBarLabel: 'Tab B',
})
}
},
(Platform.OS === 'android')
? {
tabBarComponent: props => <TabBarComponent {...props} />,
tabBarPosition: 'bottom'
}
: {
// don't change tabBarComponent here - it works on iOS after all.
}
);