expo / ex-navigation

Route-centric navigation for React Native
997 stars 201 forks source link

Define Parent/Child Relationship? #31

Open joncursi opened 8 years ago

joncursi commented 8 years ago

Is it possible to define a route as a child of another, similar to react router? I.e. something like:

export const router = createRouter(() => ({
  componentA: () => ComponentA, // normal definition
  componentB: () => <Parent><ComponentB/></Parent>, // render ComponentB as a child of Parent
  componentC: () => <Parent><ComponentC/></Parent>, // render ComponentC as a child of Parent
}));
joncursi commented 8 years ago

When I attempt the above, I get:

screen shot 2016-08-16 at 2 02 06 am
joncursi commented 8 years ago

The use case for this is having a container component that sets the Navigation header for each of its children, rather than having to define the same exact navigation header for each individual child (technical debt?).

chirag04 commented 8 years ago

for the usecase you mentioned, you can use https://github.com/exponentjs/ex-navigation/blob/79d9a6e4d787a60d76b15936f3a252e453eb92df/src/ExNavigationConnect.js#L8

joncursi commented 8 years ago

@chirag04 is there an example somewhere on how to use hoistStatics? I'm having a hard time making sense of hoistStatics in the src. Thanks!

sibelius commented 7 years ago

@joncursi hoistStatics will just copy all staticproperties of your component that is non react specific

for instance:

class MyComponent extends Component {
    static route = {
        navigationBar: {
          title: 'MyComponent',
        },
    };
}

hoistStatics will copy static route to the connect component, so ExNavigation can use it

@joncursi could u post ur solution here? or close the issue then?

joncursi commented 7 years ago

I haven't come up with a solution for this yet because I'm not sure how the mentioned hoistStatics solves the question I asked in this thread. @chirag04 can you show me an example?