Skip to content

Commit

Permalink
feat: update navigate and replace
Browse files Browse the repository at this point in the history
  • Loading branch information
triandamai committed Jun 25, 2023
1 parent d3d8ff7 commit beb31e2
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 10 deletions.
13 changes: 5 additions & 8 deletions ui/src/main/java/app/trian/mvi/ui/PageWrapper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -53,25 +53,22 @@ inline fun <reified ViewModel : MviViewModel<*, *, *>> NavGraphBuilder.pageWrapp
)
.show()

is UIEvent.ShowSnackBar -> {

}

is UIEvent.ShowSnackBar -> {}
is UIEvent.NavigateAndReplace ->
controller.navigator.navigateAndReplace(event.route, *event.params)

is UIEvent.NavigateSingleTop -> controller.navigator.navigateSingleTop(
event.route,
*event.params
)

UIEvent.NavigateBackAndClose -> controller.navigator.navigateBackAndClose()
UIEvent.NavigateUp -> controller.navigator.navigateUp()
UIEvent.Nothing -> {}
is UIEvent.Navigate -> controller.navigator.navigate(
event.route,
*event.params
)
UIEvent.NavigateBackAndClose -> controller.navigator.navigateBackAndClose()
UIEvent.NavigateUp -> controller.navigator.navigateUp()
UIEvent.Nothing -> {}

}
}
})
Expand Down
1 change: 0 additions & 1 deletion ui/src/main/java/app/trian/mvi/ui/UIEvent.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package app.trian.mvi.ui

sealed interface UIEvent {
class ShowToast(val message: String) : UIEvent

class ShowSnackBar(val message: String) : UIEvent
class NavigateAndReplace(val route: String, vararg val params: String) : UIEvent
class NavigateSingleTop(val route: String, vararg val params: String) : UIEvent
Expand Down
3 changes: 2 additions & 1 deletion ui/src/main/java/app/trian/mvi/ui/internal/Navigator.kt
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ class Navigator(
launchSingleTop = true
}
}

/**
* Navigation into [routeName] as destination, and pop all backstack before last route
* if same route exist on back stack, will be replace with [routeName]
Expand All @@ -95,7 +96,7 @@ class Navigator(
}
}
this.navHostController.navigate(buildRoute) {
popUpTo(navHostController.graph.startDestinationId) {
popUpTo(navHostController.graph.id) {
inclusive = true
}
launchSingleTop = true
Expand Down

0 comments on commit beb31e2

Please sign in to comment.