kirillzyusko / react-native-bundle-splitter

HOC for lazy components loading

Home Page:https://kirillzyusko.github.io/react-native-bundle-splitter/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Dynamic setting of navigationOptions.

vidsag opened this issue · comments

Hi,
I am trying to set the navigationOptions for the screen.
The current implementation is,
static navigationOptions = ({ navigation }) => { const params = navigation.state.params || {}; let title = params.title ? params.title : ""; return { title: title, headerLeft: ( <HeaderIcon onPress={params.goBack} iconName="arrow-back" theme="light" /> ), ...NavigationHelper.getHeaderStyles("light", true) }; };

This is the current implementation when using the library

register({ require: () => require('./screens/TopicScreen'), static: { navigationOptions: { title: "TopicName", headerLeft: ( <HeaderIcon // onPress={goBack} iconName="arrow-back" theme="light" /> ), ...NavigationHelper.getHeaderStyles("light", true) } } }),

My question is how can I get the TopicName here for the title as it is set using setParams in the screen.

Hey, @vidsag

Everything, that is located in navigation options can be not only plain objects - it also may be a function.

So, it should work:

register({ 
  require: () => require('./screens/TopicScreen'), 
  static: { 
    navigationOptions: ({ navigation }) => {
      // your implementation from first code snippet
    }
  },
}

Please, let me know, whether this works or not :)

This works. Thanks!