简体   繁体   English

反应本机导航参数抽屉导航器

[英]react-native navigation params drawerNavigator

I have a tabNavigator nested in a drawerNavigator parent. 我有一个tabNavigator嵌套在抽屉导航父中。 In the drawerNavigator is have a custom content screen which is a favourite list. 在抽屉导航器中有一个自定义内容屏幕,它是收藏夹列表。

What I'm trying to achieve is when the drawer is triggered open the favourite list in reloaded. 我想要达到的目的是,当触发抽屉时,打开重载中的收藏夹列表。

I'm passing navigator params from the drawerNavigator to the tabNavigator but when I try to pass from tabNavigator to drawerNavigator it's undefined. 我正在将导航器参数从抽屉导航器传递到tabNavigator,但是当我尝试从tabNavigator传递到抽屉导航器时,它是未定义的。

How can I pass a navigation param from LaunchScreen into the DrawerScreen? 如何将导航参数从LaunchScreen传递到DrawerScreen?

export const PrimaryNav = TabNavigator({
  Home: {
    screen: LaunchScreen,
    navigationOptions: {
      swipeEnabled: false,
      tabBarIcon: ({ tintColor }) => (
        <Image
          style={[styles.icon]}
          source={require('../Images/img.png')}
        />
      ),
    },
  },
  Map: {
    screen: FirstScreen,
    navigationOptions: {
      tabBarIcon: ({ tintColor }) => (
        <Image
          source={require('../Images/img1.png')}
          style={[styles.icon]}
        />
      ),
    },
  },
},
{
  headerMode: 'none',  
  tabBarPosition: 'top',
  animationEnabled: true,
  tabBarOptions: {
    showIcon: true,
    showLabel: false,
    activeTintColor: '#ffffff',
    indicatorStyle: {
      borderBottomColor: '#33b2f4',
      borderBottomWidth: 3,
    },
    style: {
    backgroundColor: '#000',
    paddingTop:20,
    }
  },
});

const MyDrawerNavigator =  DrawerNavigator({
  Home: {
    screen: PrimaryNav
  },
}, {
  contentComponent: DrawerScreen
});

export default MyDrawerNavigator

Ok so here's how I solved the issue: 好的,这是我解决问题的方法:

I hooked up mobx and implemented a simple store: 我连接了mobx并实现了一个简单的商店:

import {observable, action} from 'mobx'

class Store {
  @observable refresh = 'false';

  @action changeRefresh(value) {
    this.refresh = value;
  }

}

export default new Store;

Then I tested for the draw state (open/close) in my root container: 然后,我在根容器中测试了绘制状态(打开/关闭):

class RootContainer extends Component {

  handleNavigationState = (previous, next, action) => {    
    if (action.routeName === 'DrawerOpen') {
        this.props.store.changeRefresh('true')  
    } else if (action.routeName === 'DrawerClose') {
        this.props.store.changeRefresh('false')    
    }
  }

  render () {
    return (
      <View style={styles.applicationView}>
        <StatusBar barStyle='light-content' />
        <AppNavigation onNavigationStateChange={this.handleNavigationState} />
      </View>
    )
  }
}

Then checked the store prop in my drawer screen and reloaded my favourite list: 然后在我的抽屉屏幕中检查商店道具并重新加载我最喜欢的列表:

render () {
  this.props.store.refresh==='true' ? (this.loadFavs()) : (null)
  ...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM