Open SylvainHocq opened 6 years ago
Good question! We currently don't keep navigation in the state as it's tricky to keep in sync with what android saves with activities and fragments etc. It's definitely something we want to explore though.
I created a navigation middleware that navigate based on Navigation Actions:
class NavigationMiddleware : AppMiddleware {
override fun dispatch(next: Middleware.Next<Action, Action>, action: Action): Action {
if (action is NavigationAction) {
action.navigate()
return action
}
return next.next(action)
}
}
interface NavigationAction : PageViewAction {
fun navigate()
}
open class IntentNavigation(val from: Context,
private val intent: Intent,
override val pageName: String)
: NavigationAction {
override fun navigate() {
this.from.startActivity(intent)
}
}
open class ActivityNavigationAction(from: Context, val to: Class<out Activity>, pageName: String)
: IntentNavigation(from, Intent(from, to), pageName)
open class NewStackNavigationAction(from: Context, val to: Class<out Activity>, pageName: String)
: IntentNavigation(from, Intent(from, to).apply {
addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK)
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
}, pageName)
If you need a more complex navigation, just implement the NavigationAction interface.
Hello @guitcastro interesting implementation with middleware. Thanks for your response. @guitcastro can you please add implementation of your NavigationAction? I thinks it's just an Action without specific implement. This is it? I come back on this thread because , i thinks again on this architecture problem. The pain point with @guitcastro implementation is that navigation is not in the state. If we things that all application state must be in an object State. Then we have a lost.
@evant if your interest i have implemented a Router implementation of your redux implementation, inspired by an iOS implementation It's not very clean because depends of Rx because it was much faster for me to plug different UI action, but it's work very well. I have test it on a huge project without problem.
Hello, Thanks a lots, for this good library!
Do you have any ideas to manage navigation in a single activity application with redux?
Thanks.