-
-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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
React Native #743
Comments
There will be a |
Possibly of interest: http://applinks.org/ |
I'd prefer to have a synchronous way to store URLs, just because all our transitions are sync by default. @rpflorence Ideally we would be able to render the top-level component and not have to embed the router in some other component, no? |
I'm just making wild guesses, but every app has |
The components would have to be different too. You don't have a DOM |
Strictly I wouldn't say |
Perhaps, though, links are the navigation paradigm on the web (not just for text). As part of "Learn Once, Write Everywhere," there's a strong case to be made for maintaining a declarative way to create transitions (even if they don't default to blue text). For instance, I think this should work with react-native: <Link to = "home">
<Image source = { ix("logo.svg") } />
</Link> |
Yes, I suppose you're right. |
The naive solution would be something like this:
and then choose a I came really close to submitting a feature request to have DOM shims for the RN primitives ( |
Perhaps branch via |
@appsforartists You're right, the goal of React Native is not to enable "write once" mentality, thus I think your example would be an anti-pattern. You should maintain different code bases for different platforms. But I do agree with you that Links should be available much like they are on the web. Views should be linkable. Otherwise I'd expect that it would be possible to route using regular JS from a click handler. (Not sure if this is already possible with React router - I'm assuming it is.) |
I know there hasn't been any major progress here yet, but I think it would be nice, if the router would be "smart" about where to transition to. If we have a navigation stack which already contains edit: Since there actually is already a |
we're working on this, don't think we need the issue anymore. |
Any update on this? React Router on RN would be HUGE. |
+1 |
ping @ryanflorence - curious to hear how this is coming along and if there is anything that we can do to help! I see the most recent commit on the react-native branch was about 21 days ago: bf6f9a7 - if you could put up a checklist for remaining tasks perhaps a few of us could try to tackle them |
I too would like to know. I see there's a branch here: https://github.com/rackt/react-router/tree/react-native Do you guys have an estimate for the completion of this? Would you like help? |
Anybody...? It looks like the |
+1 |
1 similar comment
+1 |
Where can I find a sample of react-router + react-native? |
👍 |
3 similar comments
+1 |
+1 |
👍 |
@ryanflorence Any update on this? Just about to start a big project in RN and would love to use React Router. |
Yah just a report on what I've been up to - I have a working prototype of this in an app that's currently in beta at the moment. It's rough around the edges, but I think there's definitely going to be a way to make it work in a stable manner. Some of the harder parts around the integration is not actually developing a solution, but really figuring out the API around the right solution. Routing on the web does not map directly to routing on native. @ide talks about it a bit here: https://medium.com/the-exponent-log/routing-and-navigation-in-react-native-6b27bee39603. The main issue is that a url of |
Do you think being explicit there is too tedious, though? |
I never like to have to specify something multiple times, but the route definition doesn't include all the information that might be required as a general solution. I think the library needs the ability to explicitly state the implied routes as you have indicated (even though it feels a bit tedious). In some circumstances it is possible that they could be derived and maybe there is some benefit in a utility library to calculate them for these use cases. I'm in the process of building a solution for my app taking into account design suggestions from this conversation. I now have the ability to configure nested navigators as per a react-router hierarchy and with history. I can push new routes and everything renders correctly and also got the back navigation working with it also hooked up to the hardware button in android. I'm working with Redux so my solutions depends on that architecture so it isn't a good decoupled general solution. I have also allowed for the navigation bar to be specified on a NavigatorRoute as a custom component. I'm not directly keeping the Navigator stacks and history in sync, but only update the Navigator stack via the Router which receives the current route via props. Interestingly the shape of the Navigator stacks don't match my history. e.g. if I visit Tab1->Tab2->Tab1 the navigator will only have two scene Tab1 & Tab2 and switch between them, however the history will include an entry for all three(3) so the android back has the right behaviour. By switching between the mounted components their states are maintained e.g. textinput. My next task is to get implied routes working. At this stage I'm not sure how or where I'm going to store the implied routes for a given route. Possibly since I'm using Redux I will define them within action creators and accept params to interpolate each of the routes. |
I have decided to define the implied routes up front so on use I don't have to specify them. I have added a name property to all my routes (separate to path since I don't want params in their name) and then refer to them in an object as follows
A @ name (e.g. scene2) is an indicator to the implied generator to use another implied definition for the continued chain avoiding the need for duplication, however it can also be specified in full (e.g. scene3) Now when doing a pushDeep I can refer to only the destination URL.Since I use redux I will generate the implied routes and interpolated them within a middle layer. The Router is then explicitly informed of the implied routes through a props update. In history I will hold the interpolated implied routes, otherwise I would have to hold the params. Therefore having react native router expecting implied routes to be explicitly defined isn't really an issue. |
Makes sense - ideally we can imply some of this from the route structure, but it's not going to be a core thing. |
I implemented this kind of api as an example in react-native. Basically building a wrapper of the current Navigator api. Looks like this <Router platform="ios">
<IndexRoute name="login" component={Login} />
<Route name="home" component={Home} />
</Router> |
@skrigs is there any chance you can open up your redux routing solution, I am kinda in the same boat as you and interested to see how you did it. Generally speaking, with RN 0.18, RR 1.1 pretty much out of the door, is there a more concrete roadmap to have a routing solution based on the navigator for React Native ? |
hey all, I'm excited for RR to work with RN too, but until then here is a library my team wrote to help with routing - https://github.com/pressly/scene-router |
Btw the new navigator with animated being used under the hood that @skevy has mentioned is now available: https://github.com/ericvicenti/navigation-rfc |
I'm not closing this issue just yet, but talking to @skevy, my current thinking is that this is a no-go.
Pending any compelling points to the contrary, I'm going to close this as a |
Also, the reducer-based paradigm gives much, much better integration with Redux than is possible with the current style of API. Again, this isn't really possible on the web side because the ultimate source of truth is the browser rather than the |
Given the above, I'm going to close this issue for the time being. |
I know this thread is old, but I wanted to add another note for the benefit of people looking for a solution that makes React Router possible on React Native. I've been making some exciting progress with react-router-native—a lib that marries React Router to NavigationExperimental. For those of you who are interested, here's the pitch:
Please note that the address bar seen above is for development only and can be disabled by removing the addressBar prop from the Feedback is greatly appreciated. 🍺 |
How do you model the case like on the Instagram and Facebook apps where you can hit the same scene from multiple tabs in the tab bar? |
@taion This is actually surprisingly easy to do: const profileRoute = (
<Route path="profile" component={Profile} overlayComponent={ProfileNavBar} />;
);
<Router history={nativeHistory}>
<TabsRoute path="master" component={Master}>
<StackRoute path="/tab1" component={Tab1}>
<Route path="/home" component={Home} overlayComponent={HomeNavBar} />;
{profileRoute}
</StackRoute>
<StackRoute path="/tab2" component={Tab2}>
<Route path="/notifications" component={Notifications} overlayComponent={NotificationsNavBar} />;
{profileRoute}
</StackRoute>
</TabsRoute>
</Router> This is possible because we only use React Router to render the navigational components and delegate rendering of user components to Hope this makes sense. 🍺 |
Right – that's where we ended up, but it didn't feel quite right. You can replicate a bag of routes/scenes across multiple tabs in this manner, but it feels like a worse way of handling configuration, and doesn't make a lot of sense to me from the perspective of the actual URLs. Essentially, my dislike for an API that requires nesting the same |
https://react-router-website-xvufzcovng.now.sh/MemoryRouter mentions that Does it mean we can use react router in react native apps from version 4? |
@nikhildaga Would also like to know what the status is. I get |
The other components seem to work which is good, but I can't get a link to work |
You can create a custom React Router works with React Native, but you won't get nice NavigationController-esque transitions without a lot of effort. Edit: I haven't tried it with v4, only v3. |
React-Router v4 will help with this issue https://medium.com/@jschloer/react-router-v4-with-react-native-5f2005ab2a72#.56mt46jj9 way to go @jschloer |
Just tracking react native thoughts here. My assumptions are probably all wrong since 1) I don't know much about native dev and 2) I've spent 5 minutes with react native but:
Location
and eventually anAndroid
location, it'll probably be stored in memory and persisted to some sort oflocalStorage
equivalent. When the app boots we look at the URI requesting the launch first, and then thelocalStorage
(whatever it really is) second.Again, I have no idea what I'm talking about yet. ¯(º_o)/¯
The text was updated successfully, but these errors were encountered: