react-navigation / rfcs

RFCs for changes to React Navigation
Other
88 stars 16 forks source link

Default params in navigator route config #36

Closed brentvatne closed 5 years ago

brentvatne commented 6 years ago

It may be useful to specify default params in some cases, eg: to reuse screens for multiple routes.

let TabNavigator = createBottomTabNavigator({
  Brent: {
    screen: FriendScreen,
    initialParams: { firstName: 'Brent', lastName: 'Vatne' },
  },
  Eric: {
    screen: FriendScreen,
    initialParams: { firstName: 'Eric', lastName: 'Vicenti' },
  },
});

An alternative for this would be to wrap FriendScreen so we have BrentFriendScreen which passes in some props. This is maybe also fine and makes me hesitant to want to include something like initialParams unless we have some motivating use cases where this is infeasible. So let's gather use cases here.

dantman commented 6 years ago

An alternative for this would be to wrap FriendScreen so we have BrentFriendScreen which passes in some props. This is maybe also fine and makes me hesitant to want to include something like initialParams unless we have some motivating use cases where this is infeasible. So let's gather use cases here.

I wouldn't say technically infeasible, but I don't think creating 6+ wrapper screen components for the same screen just because you can't pass in initialParams is a good model.

I used a hack to fake initialParams for this very use case in a released app. Though I got tired of DrawerNavigator's limitations and started a refactor to make a future version just use a single Stack: StackNavigator() route and handle drawer items and handle dispatching navigation myself with reset.

Every single drawer item visible in this screenshot is the same Inbox screen but with different params: screenshot_20180324-124905

brentvatne commented 6 years ago

@dantman - could you open a RFC for this? I'd love to get this in soon

n1ru4l commented 6 years ago

I will try to create a PR asap!

ericvicenti commented 6 years ago

Could we call this defaultParams instead? I think its more technically accurate, because the initial params of the route may be overridden by the navigation actions

brentvatne commented 5 years ago

here: https://github.com/react-navigation/react-navigation-core/pull/11

donni106 commented 5 years ago

I also want to realize a Drawer with different items navigating in one same stack. Using params didn't work for me. Adding params to the RouteConfigs of my createDrawerNavigator did nothing. The params of a route were still empty. (react-navigation 2.18.2) With setting up a CustomDrawerItems overwriting the onItemPress method, I am able to render the items and navigate correctly in one main stack. bildschirmfoto 2018-10-29 um 17 30 39 My problem is, that the active item in my drawer is not changing. It is always the first item, which is active ('Start' in my example). I wonder how to set a clicked item active?

brentvatne commented 5 years ago

@donni106 - because it's not released yet, it's only in the latest alpha version of 3.0. post a new issue with exactly what you want please