-
Notifications
You must be signed in to change notification settings - Fork 349
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
Issues getting Horizon working with React Native #255
Comments
This seems like a reasonable fix albeit confusing if you don't have some React Native context, but that's fine. Authentications, Tokens, & OAuth If the endpoint is available and accessible by react-native and we can properly shim @dferber90 is there a browser friendly check we can do to check if AsyncStorage is available and opt for that first if it is available? Maybe just: From => https://github.com/rethinkdb/horizon/blob/next/client/src/auth.js#L35-L50: function getStorage() {
if (window.AsyncStorage){ // Line added
return new AsyncStorage() // Line added
} else if (window.localStorage === undefined) { // Line modified
return new FakeStorage()
}
try {
window.localStorage.setItem('$$fake', 1)
window.localStorage.removeItem('$$fake')
return window.localStorage
} catch (error) {
if (window.sessionStorage === undefined) {
return new FakeStorage()
} else {
return window.sessionStorage
}
}
} As for the token put into the query string, what is the standard way of ready from query params in |
Put up a branch to solve outstanding issues in #279 |
I'm really new to react-native (1 week usage in my spare time) and haven't built anything with OAuth yet, so unfortunately I don't know. Take anything I say with a grain of salt 😉 |
So are these resolved, and should Horizon be working with React Native? I went through the various Horizon issues to get a sense of where it was, and this led me to believe that it still wasn't working. Then I watched the video at https://www.youtube.com/watch?v=xRK0SYSgVF0&feature=youtu.be and it does seem that it works. Am I missing something? Thanks. |
From what I can tell, the only remaining issue with React Native is that we don't interact with AsyncStorage instead of LocalStorage. The big impediment being that the interface is different (AsyncStorage is async). In addition, we'd need to figure out how best to do OAuth redirects in React Native, since there's not actually a browser or a window.location |
When the app is closed or moved to the background the Websocket connection should be terminated, and reopened when the app is activated again. On React Native's side AppState can be used for this. When the phone loses internet connectivity you'd have to handle that as well. NetInfo can be used for this. Specifically, you'd want to handle the case when it gains connection again to reconnect Horizon. Both of these are concerns of the React Native developer, not Horizon itself as long as API is there to support reconnecting - and it seems there is 👍 Since these steps are pretty much the same for every React Native app, maybe we could extract them into an npm package. |
That seems reasonable. I think we should get good reconnection working pretty soon it seems like. |
The horizon client seems to work with react-native 0.31.0 (android+ios) and the the latest |
That's good, I can probably move the babel config back out to a separate file. I forget exactly why I moved it in |
Ok, great! Oh, there is one more things that needs to be tweaked for it to work. Working on a fix. BRB. |
WRT the babel config, if you remove it then It is still possible to build the client without the babel conf, with EDIT: Or, |
Ok, got it working. Assuming you have one project for your horizon app (horizonApp) and one for you react native app (reactNativeApp), the steps as of horizon 2.0.0-beta-7 are as follows:
Seems like a lot of steps, but it all boils down to that the Horizon cli must be built with the babel preset enabled while the Horizon client must be built without the babel preset for it to work in React Native. |
Thanks @lirbank for the workaround. Unfortunately, I'm getting this error when I try
module.js:457 Error: Cannot find module 'shelljs/global' |
I just tried it again, and it looks like it worked. I believe the only thing that changed was I reinstalled horizon globally. |
@deontologician can we implement this change so react-native can work out of the box? |
Yes, we are going to, and I want to get a proper test setup for react On Thu, Aug 25, 2016, 23:04 Sat Mandir S. Khalsa notifications@github.com
|
Ok, a fix is up in #823 if anyone wants to try it out. Be aware that if you do, you need to build the package and install it, you can't just |
Yes, #823 seems to solve the babel-loose problem! |
@smkhalsa How do you pass these error? |
@anhtuank7c |
Hope one day it i'll be fixed and we won't have to make all of this tricky hack! :) |
I took horizon for a spin with a react-native project.
I have set up an example project you can use to experiment with it yourselves at dferber90/horizon-react-native.
Current issues
Currently there is at least one issue in here, because
window.location
is undefined in React Native.After
npm install
ing, it's possible to manually fix this by editinghorizon-react-native/HorizonExampleApp/node_modules/@horizon/client/lib/auth.js
and changing line 98After doing this, press
CMD+R
in the simulator. Now an alert should appear saying the Horizon client is connected... which means it works :)Authentication
I haven't fully understood how horizon does authentication yet, so I can describe the problems I discovered only vaguely.
Tokens
When using tokens, the token would have to be stored on the device using AsyncStorage instead of
localStorage
. Having low-level functions which allow developers to pass the current token to Horizon from any source and specify how to save any new tokens would be helpful here.OAuth
The current flow of using OAuth is probably not possible with React Native since the OAuth token can't be read form the callback URL, but maybe from the URI Scheme. I've never created OAuth integration for a native device before, so I can't really tell.
The text was updated successfully, but these errors were encountered: