Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set default params? #441

Closed
jeffreymendez1993 opened this issue Feb 22, 2017 · 20 comments

Comments

@jeffreymendez1993
Copy link
Contributor

@jeffreymendez1993 jeffreymendez1993 commented Feb 22, 2017

Is there any way to set a default param on the component itself?

@grabbou

This comment has been minimized.

Copy link
Collaborator

@grabbou grabbou commented Feb 22, 2017

@grabbou grabbou closed this Feb 22, 2017
@jeffreymendez1993

This comment has been minimized.

Copy link
Contributor Author

@jeffreymendez1993 jeffreymendez1993 commented Feb 22, 2017

@grabbou I do not see this section.

@grabbou

This comment has been minimized.

Copy link
Collaborator

@grabbou grabbou commented Feb 22, 2017

Try Default navigation options 😊

@jeffreymendez1993

This comment has been minimized.

Copy link
Contributor Author

@jeffreymendez1993 jeffreymendez1993 commented Feb 22, 2017

@grabbou static navigationOptions = { state: { params: { something: false, somethingElse: false } } } did not work.

@grabbou grabbou reopened this Feb 22, 2017
@grabbou

This comment has been minimized.

Copy link
Collaborator

@grabbou grabbou commented Feb 22, 2017

@jeffreymendez1993

This comment has been minimized.

Copy link
Contributor Author

@jeffreymendez1993 jeffreymendez1993 commented Feb 22, 2017

@grabbou Sure. I want to achieve this but for navigation state params since I have a statement checking to see if the prop has been passed down and set to true and need to default it to false.
screen shot 2017-02-22 at 12 57 59 pm

@jeffreymendez1993

This comment has been minimized.

Copy link
Contributor Author

@jeffreymendez1993 jeffreymendez1993 commented Feb 22, 2017

screen shot 2017-02-22 at 1 00 18 pm

I would like to be able to set this default value of popToStart for instance.
@ddeanto

This comment has been minimized.

Copy link

@ddeanto ddeanto commented Feb 23, 2017

This may be related to #232

@grabbou

This comment has been minimized.

Copy link
Collaborator

@grabbou grabbou commented Feb 23, 2017

@jeffreymendez1993 why wouldn't const value = params.popToStart || 'defaultValue'; work?

@jeffreymendez1993

This comment has been minimized.

Copy link
Contributor Author

@jeffreymendez1993 jeffreymendez1993 commented Feb 24, 2017

@grabbou It would work, but wouldn't you want to be able to setDefault params just how you setDefault props to have a clear vision on what the default to certain things would be. If not I guess that would work for now.

@thurt

This comment has been minimized.

Copy link
Contributor

@thurt thurt commented Mar 1, 2017

as far as I'm aware, you currently cannot set default parameters for a scene/screen. but seems like there is a good argument for adding them

@jeffreymendez1993

This comment has been minimized.

Copy link
Contributor Author

@jeffreymendez1993 jeffreymendez1993 commented Mar 6, 2017

@thurt I think this should be added as for this makes code clean and easy to read.

@dantman

This comment has been minimized.

Copy link
Contributor

@dantman dantman commented Apr 18, 2017

This is especially important for things like the DrawerNavigator where routes are not opened by a navigator.navigate(..., params) call within the app, but instead are navigated to by the DrawerRouter without any params.

Without default params it's not possible (at least not without fudging things using the routeName) to have a bunch of drawer items with the same screen but different params, like:

DrawerNavigator({
  Inbox: {
    screen: MessageList,
    params: {
      filter: {
        archived: false
      }
    },
  },
  Archives: {
    screen: MessageList,
    params: {
      filter: {
        archived: true
      }
    },
  },
  AllMessages: {
    screen: MessageList,
  },
});
@jeffreymendez1993

This comment has been minimized.

Copy link
Contributor Author

@jeffreymendez1993 jeffreymendez1993 commented Apr 19, 2017

@dantman that would be perfect

@ntkzwane

This comment has been minimized.

Copy link

@ntkzwane ntkzwane commented Jul 12, 2017

I share the same sentiments with @dantman, except my scenario involves use of the TabNavigator. I see you made reference to #838, however this wouldn't be the cleanest solution in my opinion.

@0x5e

This comment has been minimized.

Copy link

@0x5e 0x5e commented Aug 25, 2017

Same problems with @dantman . Same screen with different params.

@dantman dantman mentioned this issue Sep 15, 2017
11 of 11 tasks complete
@jiyarong

This comment has been minimized.

Copy link

@jiyarong jiyarong commented Oct 8, 2017

Has the problem been solved?

@brentvatne

This comment has been minimized.

Copy link
Member

@brentvatne brentvatne commented Jan 24, 2018

hi there! I moved this feature request to canny, as it's our new home for feature requests: https://react-navigation.canny.io/feature-requests/p/set-default-params-in-a-screen-component

issues are now only for bugs

@brentvatne

This comment has been minimized.

Copy link
Member

@brentvatne brentvatne commented Mar 6, 2018

where you use the param, you can do this:

this.props.navigation.getParam('name', defaultValueHere)

if you think this api isn't good enough then please open a rfc to discuss further

@react-navigation react-navigation locked and limited conversation to collaborators Mar 6, 2018
@brentvatne

This comment has been minimized.

Copy link
Member

@brentvatne brentvatne commented Oct 23, 2018

the api that @dantman suggested above was implemented in react-navigation/core#11

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
10 participants
You can’t perform that action at this time.