Comments (14)
Thanks.
I have actually done as in the example. But I still have to import the router to each and every screen which needs it for navigation. I'd rather inject the router into every screen than having to require it everywhere.
It turned out that it already was injected. So, now I'm wondering if it would be a bad idea to use _props.navigation.router instead of having to import the router?
from ex-navigation.
Hiya folks,
@satya164 and I discussed this today and it seemed like there is no harm in supporting an API that lets you push / replace routes without importing the router as it is fairly trivial to implement. You can try this out in 1.5.29 (d51ce4d)
Either of these work now:
this.props.navigator.push(AppRouter.getRoute('another', { text: 'Some dynamic text!' }));
this.props.navigator.push('another', { text: 'Some dynamic text!' });
The only downside of using the approach without AppRouter.getRoute
right now is that I wasn't sure how to implement typechecking on the route param, so you'll lose out on that. If someone knows how to make it compatible with this approach too, that would be great :)
@MichaelSWE - does this solve your issue?
from ex-navigation.
I found the router in props.navigation._router. But since I haven't found any documentation stating that I should use it I hesitate. Is this a safe way of getting the router?
gotoProfilePage = () => {
this.props.navigator.push(
this.props.navigation._router.getRoute('profile')
);
}
from ex-navigation.
you can put all your routes in one file and require that file to get your routes.
gotoProfilePage = () => {
this.props.navigator.push(router.getRoute('profile'));
}
Refer this example:
https://github.com/exponentjs/rnplay/blob/master/navigation/Router.js
from ex-navigation.
I think app specific stuff like routing belongs to the context.
from ex-navigation.
I'm sorry, I don't quite follow you. What do you mean by app specific? Are there apps without navigation? All apps needs routing as far as I know. And the _route object is already "injected" via the props.navigation object.
Should I use the injected _route or should I import my Route everywhere?
from ex-navigation.
I won't claim it's best practise or anything, but I just import my router wherever it's needed. I can see why it might feel wrong - but really, it's fine. Hopefully there'll be bigger problems to solve! 😄
from ex-navigation.
Great!
Exactly what I thought earlier today. Seems odd to be forced to make two calls when props.navigator knows everything needed to consolidate to one call, but I didn't dare suggesting it because of the silence from @brent in this matter :)
Why the need for type checking? It seems that spelling the route wrongly would be a much likelier error. To solve this, one would need to setup constants for all route strings. This would clear any potential type error as well.
Would it be a bad idea to let the users be able to register their route constants with the navigator as well. This way we wouldn't even need to import our constants module.
I.e.
this.props.navigator.push(this.props.navigator.routeconsts.ANOTHER, { text: 'Some dynamic text!' });
from ex-navigation.
Why the need for type checking? It seems that spelling the route wrongly would be a much likelier error. To solve this, one would need to setup constants for all route strings. This would clear any potential type error as well.
Sorry that's what I meant by it -- it can't validate that you spell the route name correctly with this style.
Would it be a bad idea to let the users be able to register their route constants with the navigator as well. This way we wouldn't even need to import our constants module.
Hmmm I don't see what the win is from doing this
from ex-navigation.
Aha, ok. I didn't realize that you checked the strings. What will happen if I misspell a route with the new approach?
The win would be one less import (my constants). But I haven't actually put my routes in constants yet, so it's not a problem for now.
from ex-navigation.
Aha, ok. I didn't realize that you checked the strings. What will happen if I misspell a route with the new approach?
You won't be warned by flow, you'd just get a runtime error when you try to push it.
The win would be one less import (my constants). But I haven't actually put my routes in constants yet, so it's not a problem for now.
I personally would not put them in constants, I don't think that helps to make it any more readable or maintainable. You could just use whatever constant name as a string and accomplish the same thing :) 'ANOTHER'
instead of Constants.ANOTHER
from ex-navigation.
Aha, again. I didn't know that Flow could do such cool checks.
I know too little about Flow, I guess. Why doesn't the check work with the new approach? The only difference is that ExNavigationStack.push makes the call to getRoute() instead of me doing it explicitly. How can this break the Flow checking?
from ex-navigation.
I see now. I suppose routeName: $Keys<RC>
does not work when different types are allowed as params. I'm sorry, cannot help with this. I would gladly accept a breaking change (getting rid of the getRoute-call). But I understand that many would be upset.
from ex-navigation.
@MichaelSWE - @skevy can look at making that work later if you want to create another issue. I think this one is solved though!
from ex-navigation.
Related Issues (20)
- turn caching off for some pages HOT 1
- error code 404 , it crashes upon scanning of QR.
- Compatibility with RN 0.47 HOT 2
- how to do change toolbar color with drawer
- Large gap on nav bar header on Android HOT 5
- Android back button navigation pop does not trigger onWillChangeTab
- importing NavigationProvider throws undefined is not an object (evaluating PropTypes.shape in NavigationPropTypes.js:30:26) HOT 10
- Styling the default back button on the left side of the navbar HOT 1
- @expo/ex-navigation > [email protected] has incorrect peer dependency "react@^0.13.0 || ^0.14.0 || ^15.0.0 || ^16.0.0".
- Version 4.0
- tiveart HOT 1
- TypeError: undefined is not an object (evaluating 'navigationState.navigators')
- expo does not support NavigatorIOS ?
- Use react-navigation instead of expo/ex-navigation
- How To Hide TabBar on Particular Screen Using Expo/ex-navigation
- Unmount TabItem in TabNavigation
- Support for the experimental syntax 'exportNamespaceFrom' isn't currently enabled HOT 3
- Issue with babel 7 HOT 1
- [question] Pop to root [solved]
- UnhandledPromiseRejectionWarning: UnableToResolveError: Unable to resolve module @exponent/ex-navigation from
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ex-navigation.