【发布时间】:2019-02-08 09:10:45
【问题描述】:
我使用createBottomTabNavigator 作为标签栏。
我可以通过设置true 或false 来使用tabBarVisible 属性隐藏和显示标签栏。
我的问题是,我想用动画隐藏它。
任何链接都会有所帮助。
【问题讨论】:
标签: javascript android ios react-native
我使用createBottomTabNavigator 作为标签栏。
我可以通过设置true 或false 来使用tabBarVisible 属性隐藏和显示标签栏。
我的问题是,我想用动画隐藏它。
任何链接都会有所帮助。
【问题讨论】:
标签: javascript android ios react-native
您可能想使用 new Animated.Value(0) 并更改选项卡的底部值。 https://github.com/react-navigation/react-navigation/issues/888这个有解决办法。
【讨论】:
您可以创建自定义tabBarComponent,然后使用您想要的动画隐藏/显示它。我在componentWillReceiveProps中抓到tabbar的道具
我使用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>
);
}
【讨论】: