我正在使用createBottomTabNavigator
作为标签栏。
我可以通过将tabBarVisible
或true
设置为false
来隐藏和显示标签栏。
我遇到的问题是,我希望它随动画一起隐藏。
任何链接都会有帮助。
答案 0 :(得分:2)
您可能想使用新的Animated.Value(0) 并更改选项卡的底值。 https://github.com/react-navigation/react-navigation/issues/888这有一个解决方案。
答案 1 :(得分:0)
您可以创建自定义tabBarComponent
,然后使用所需的动画对其进行隐藏/显示。我在tabbar
componentWillReceiveProps
的道具
我用react-native-animatable
做动画。
componentWillReceiveProps(props) {
const oldState = this.props.navigation.state;
const oldRoute = oldState.routes[oldState.index].routes[0];
const oldParams = oldRoute.params;
const wasVisible = !oldParams || oldParams.visible;
const newState = props.navigation.state;
const newRoute = newState.routes[newState.index].routes[0];
const newParams = newRoute.params;
const isVisible = !newParams || newParams.visible;
if (wasVisible && !isVisible) {
this.view.slideOutDown(500);
this.setState({
hidden: true,
});
} else if (isVisible && !wasVisible) {
this.view.slideInUp(500).then(() => {
this.setState({
hidden: false,
});
});
}
}
render() {
return (
<Animatable.View
ref={ref => { this.view = ref; }}
style={[styles.container, {
position: this.state.hidden ? 'absolute' : 'relative',
}]}
useNativeDriver
>
<BottomTabBar
{...this.props}
/>
</Animatable.View>
);
}