I'm learning the ropes with React Native and React Navigator at the moment and I've come across something in development where I feel like I want to implement the DRY (don't repeat yourself) technique.
Here's my component code:
export default class App extends React.Component {
render() {
const MainNavigator = TabNavigator({
welcome: { screen: WelcomeScreen },
auth: { screen: AuthScreen },
main: {
screen: TabNavigator({
map: { screen: MapScreen },
deck: { screen: DeckScreen },
review: {
screen: StackNavigator({
review: { screen: ReviewScreen },
settings: { screen: SettingsScreen }
})
}
}, {
tabBarPosition: 'bottom',
lazyLoad: true,
animationEnabled: false,
swipeEnabled: false
})
}
}, {
tabBarPosition: 'bottom',
lazyLoad: true,
animationEnabled: false,
swipeEnabled: false
});
return <MainNavigator />;
}
}
As you can see, I have the following chunk of repeatable code:
tabBarPosition: 'bottom',
lazyLoad: true,
animationEnabled: false,
swipeEnabled: false
I tried to refactor the same way that you would do styles in React components like this:
export default class App extends React.Component {
render() {
const MainNavigator = TabNavigator({
welcome: { screen: WelcomeScreen },
auth: { screen: AuthScreen },
main: {
screen: TabNavigator({
map: { screen: MapScreen },
deck: { screen: DeckScreen },
review: {
screen: StackNavigator({
review: { screen: ReviewScreen },
settings: { screen: SettingsScreen }
})
}
}, { defaultTabStyles })
}
}, { defaultTabStyles });
return <MainNavigator />;
}
}
const defaultTabStyles = {
tabBarPosition: 'bottom',
lazyLoad: true,
animationEnabled: false,
swipeEnabled: false
};
As you can see, this is a much cleaner way of doing things if it would work. But it doesn't work, so is there a way of refactoring this correctly or do I need to stick with my original implementation?