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
Do you store navigation stack in state? #393
Comments
You can totally do that. Managing the navigation of the app with ReSwift doesn't seem super complicated, but I don't know how people have solved the problem with pressing/swiping back, for instance, because that's something that's given for free and it's not tied to a programmatic action you explicitly perform. Same thing with dismissing alerts/popovers, etc. In those cases, it's not that you update the view because your state has changed, but rather the view changes by itself and you would need to, at least, catch those events and sync back your ReSwift state to keep it consistent. Regarding restoring the state of your app (not talking about ReSwift here), Apple already provides something for this, you can check this. This is fairly easy to integrate, but in order to keep in sync both the app and your ReSwift state, you will probably have to serialise and persist it yourself, so once the app has been restored, you can continue managing its navigation with ReSwift where you left it. This seems trickier but doable. |
Thank you @danielmartinprieto for your answer :). Good catch with back navigation. To be clear, I don't want to implement this. I'm just curious if it's common for people using Redux on iOS to keep navigation in state and use Actions to push/pop ViewController. Personally, I use Redux for navigation only partially. For example I have a hamburger menu with SideMenuViewController and when user selects an item, I dispatch SelectScreenAction and MainViewController replaces its ViewController based on new state. I know that there is also ReSwift-Router library to help with navigation. As you mentioned, it's doable for sure, but to me it looks like a lot of effort with questionable benefits, but probably to be 100% Redux, we shoud keep navigation in state, because after all it's a shared state of the application. |
Yeah, totally agree that it's much easier for a web app, where routing is done these days in a fairly declarative manner, which fits Redux/ReSwift better. |
I have a Initially I was tracking a lot more things, like a modal stack, so you could present a modal with an But I use it extensively for my custom UI stuff, like to present my custom bottom sheet, show a notification etc.. it's all done trough actions and reducers, and it's very convenient. I also track the device orientation, and subscribe to it whenever needed. And a bunch of other stuff. |
I store some UI states using ReSwift. - ( Tab index, Button label, etc ). But I am not prefer to store UI state in ReSwift. Especially instant UI (Dialog, Toast, Navigation) need more efforts and times to control their states. I let UI store their own states. I make efforts to be stored pure data and logics in ReSwift's state. |
Closing this because the question appears to have been answered 👍 If any of y'all wants to whip up a short article (e.g. Markdown Gist) that we could link to or include in the docs as an example, please feel very invited to do so 🙏 |
Hi,
I've got a few questions:
Redux was invented for web (js) where as far as I know navigation is either similar to starting up whole application (loading a different URL) or changing visibility in a single HTML source. In contrast to mobile apps where you need to restore whole complex navigation stack like tabs, nested navigation controllers, modal views etc.
I don't think that in many applications it would be beneficial to be able to restore whole navigation, but I wonder what is your way to deal with it?
Best regards,
Wojciech Kulik
The text was updated successfully, but these errors were encountered: