首页 > 解决方案 > ReactNavigation - 调用父导航器并更改其“cardStyle”和“navigationOption”的属性

问题描述

我有以下代码:

/**
 * The tab that's is going to stay in the Home Section
 * @type {[type]}
 */
const HomeTab = createMaterialTopTabNavigator({
  //Home: Home,
  PostFriends: PostFriends,
  // Another screens
}, {
  tabBarComponent: null,
  mode: 'hide',
  navigationOptions: {
    visible: false // Now I don't want to see this tab, but I'll need it in the future
  }
});

/**
 * The Stack that 
 * @type {[type]}
 */
const HomeStack = createStackNavigator({
  HomeTab: HomeTab,
  // Another screens
}, {
  headerMode: 'float',
  cardStyle: {
    top: -20 // This is the value that I want to change it to make the animation
  }
});

如您所见,在简历中,我有一个隐藏的 TabNavigator,它位于 StackNavigator 内,我想将最后一个标题设置为最常见应用程序的标题,当屏幕向下滚动时,标题会向上移动,直到消失。

现在,我在 PostFriend 的屏幕内,它有一个带有大量数据的 ScrollView,因此,当我在此屏幕上滚动时,我想访问 HomeStack,以更改“cardStyle”和“navigationOption”的属性以更改它的值并且可以制作动画。

这是我的屏幕代码:

export default class PostFriends extends React.Component {
    static navigationOptions = ({ navigation }) => {
        const { params } = navigation.state;
       // I tried a lot of black magic to 
       // connect with the HomeStack
    }; 
    /**
     * Constructor of the component
     * @param  {[type]} props [description]
     * @return {[type]}       [description]
     */
    constructor(props) {
        super(props);
        // Some attributes
    }

    render() {
        return (
              <ScrollView>
                  // A lot of data
              </ScrollView>
        );
    }
}

标签: javascriptreactjsreact-nativereact-navigation

解决方案


推荐阅读