Skip to content
This repository has been archived by the owner on Feb 15, 2019. It is now read-only.

Reading route params from NavigationBar #121

Open
msageryd opened this issue Sep 27, 2016 · 4 comments
Open

Reading route params from NavigationBar #121

msageryd opened this issue Sep 27, 2016 · 4 comments

Comments

@msageryd
Copy link

The doc says to do this:

class AboutScreen extends React.Component {
   static route = {
     navigationBar: {
       title(params) {
         return `Greeting for ${params.name}`;
       },
     }
   } 

But I need to do this to get it working:

class AboutScreen extends React.Component {
   static route = {
     navigationBar: {
       title(route) {
         return `Greeting for ${route.params.name}`;
       },
     }
   }

Am I right in doing this? I.e. should the docs be updated, or will I get in trouble in the next version?

@satya164
Copy link
Contributor

How are you updating the route params? Docs seem fine. You can also check it in action here https://github.com/exponentjs/ex-navigation/blob/master/example/components/EventEmitterExample.js#L59

@msageryd
Copy link
Author

Thanks.
That example is in line with how I do it. I still think the docs need to be updated.

Again.. from the docs:

class AboutScreen extends React.Component {
   static route = {
     navigationBar: {
       title(params) {
         return `Greeting for ${params.name}`;
       },
     }
   } 

This won't work, because there is no "name" field directly on the params object. The params object is actually a route which in turn has a params object which might have a name field.

@satya164
Copy link
Contributor

@MichaelSWE Hmm... In the example I linked the selectionCount property is directly on the function argument like how it's in the docs

@msageryd
Copy link
Author

msageryd commented Sep 27, 2016

@satya164 Yeah, I see that now. Misread it..

But it doesn't look like this to me. I push the route like this:

onClickProject() {
  this.props.navigator.push(
    Router.getRoute('project', {projectGuid: this.props.project.get('guid')})
  );
}

And I have to read the params like this:

class ProjectView extends Component {
  static route = {
    navigationBar: {
      title: 'Project',
      renderRight: (route) => {
        return (
          <View style={{flex:1}}>
            <CommitEditProjectButton/>
            <StartEditProjectButton projectGuid={route.params.projectGuid}/>
          </View>
        )
      }
    }
  }

If I do console.log(route) from inside of renderRight() I get this:

{
  "key": "97e56a00-323c-4f5b-833a-ae4ac1bea6ea",
  "routeName": "projekt",
  "params": {
    "projectGuid": "bfed1495-502a-40cc-b320-55f76a0443c4"
  },
  "config": {
    "styles": {
      "navigationBarAnimations": {}
    },
    "eventEmitter": {
      "_subscriber": {
        "_subscriptionsForType": {},
        "_currentSubscription": null
      },
      "_currentSubscription": null
    },
    "navigationBar": {
      "title": "Projekt"
    }
  }
}

I'm using ex-navigation 1.5.29

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants