-
-
Notifications
You must be signed in to change notification settings - Fork 499
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
[Discussion] Be able to restore views (fragments) natively when Android kills the process #96
Comments
Android fragments have built-in view hierarchy persistence by default. It is turned off in screens however. I believe this is outside of the scope of this project. The problem here is that there is no value in having your view hierarchy restored if the underlying react app does not restore to the same state. This way you'd have a UI out of sync with the application state. The way it should work is that app state persistence should be handled on the react side, such that when the app gets restored react app first recreates the state and only after that native view hierarchy should be recreated to match that state (this may not always be possible and in fact this is the same for native apps, I had many issues with that automatic mechanism in the past when working on Android native apps because normally only a fraction of the app state is kept in the view hierarchy) |
But this could be done, right? What if:
Don't you think it can work? |
React works terribly with rehydration even in React DOM. Highly doubt it's possible to make it work reliably here. |
I am opening this as a place for discussion instead of using Twitter. All this comes from my try & error + my experience using a RN app daily on my Android phone. Summary is here https://twitter.com/ferrannp/status/1126056440924389376.
There has been some discussion here too: #17
So there are two scenarios:
To simulate number 2 you can:
adb shell am kill app.package.name
After using a React Native app daily on my phone, I find 2) happening quite a lot (Pixel 2) when I open other apps and then I come back to mine.
I think as
react-native-screens
use fragments, it could help with this. Right now is not working, and that is why #17 happened. That's why we use the workaround:I believe we could persist fragments and let the system restore them. What are the problems with that? Maybe the state of JS won't be the same (for example, if you use Redux). However, I think this can be an alternative and document that if you persist native state, you are responsible to persist JS state (
AsyncStorage
or whatever you prefer).What do you think?
cc @brentvatne @osdnk @kmagiera @satya164
The text was updated successfully, but these errors were encountered: