最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Hide and Show createBottomTabNavigator tabbar with Animation in react-native - Stack Overflow

programmeradmin8浏览0评论

I am using createBottomTabNavigator for tab bar.

I can hide and show tabbar using tabBarVisible prop by setting it true or false.

Problem I have is ,I want it to hide with animation.

any links will be helpful.

I am using createBottomTabNavigator for tab bar.

I can hide and show tabbar using tabBarVisible prop by setting it true or false.

Problem I have is ,I want it to hide with animation.

any links will be helpful.

Share Improve this question edited Feb 21, 2019 at 5:09 Jaydeep Galani asked Feb 8, 2019 at 9:10 Jaydeep GalaniJaydeep Galani 4,9613 gold badges30 silver badges48 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 5 +50

You might wanna use new Animated.Value(0) And change the bottom value of the tab. https://github./react-navigation/react-navigation/issues/888 this has a solution.

You can create custom tabBarComponent, and then hide/show it with what animation you want. I catch the props of tabbar in ponentWillReceiveProps

I used react-native-animatable for animation.

  ponentWillReceiveProps(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>
    );
  }
发布评论

评论列表(0)

  1. 暂无评论