-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #51 from dreipol/feature/abstract-navigation-state
[abstract-navigation-state] Abstract navigation state
- Loading branch information
Showing
5 changed files
with
31 additions
and
34 deletions.
There are no files selected for viewing
24 changes: 24 additions & 0 deletions
24
...ain/kotlin/ch/dreipol/dreimultiplatform/reduxkotlin/navigation/AbstractNavigationState.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package ch.dreipol.dreimultiplatform.reduxkotlin.navigation | ||
|
||
abstract class AbstractNavigationState<Screen> { | ||
abstract val homeScreen: Screen | ||
abstract val pushedScreens: List<Screen> | ||
val screens: List<Screen> | ||
get() = listOf(homeScreen) + pushedScreens | ||
|
||
val currentScreen: Screen | ||
get() = screens.last() | ||
} | ||
|
||
// used in Android for showing correct animation when | ||
// navigating back from deep link jump | ||
enum class NavigationDirection { | ||
PUSH, | ||
POP | ||
} | ||
|
||
data class DirectionalNavigationState<Screen>( | ||
override val homeScreen: Screen, | ||
override val pushedScreens: List<Screen> = emptyList(), | ||
val navigationDirection: NavigationDirection = NavigationDirection.POP, | ||
) : AbstractNavigationState<Screen>() |
13 changes: 2 additions & 11 deletions
13
...ommonMain/kotlin/ch/dreipol/dreimultiplatform/reduxkotlin/navigation/NavigationReducer.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,4 @@ | ||
package ch.dreipol.dreimultiplatform.reduxkotlin.navigation | ||
|
||
fun navigateBack(state: NavigationState): NavigationState { | ||
if (state.sheet != null) { | ||
return state.copy(sheet = null) | ||
} | ||
val screens = state.screens.toMutableList() | ||
if (screens.size == 1) { | ||
return state | ||
} | ||
screens.removeAt(screens.lastIndex) | ||
return state.copy(screens = screens, navigationDirection = NavigationDirection.POP) | ||
} | ||
fun <Screen> navigateBack(state: DirectionalNavigationState<Screen>): DirectionalNavigationState<Screen> = | ||
state.copy(pushedScreens = state.pushedScreens.dropLast(1), navigationDirection = NavigationDirection.POP) |
17 changes: 0 additions & 17 deletions
17
src/commonMain/kotlin/ch/dreipol/dreimultiplatform/reduxkotlin/navigation/NavigationState.kt
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 0 additions & 4 deletions
4
src/commonMain/kotlin/ch/dreipol/dreimultiplatform/reduxkotlin/navigation/Screen.kt
This file was deleted.
Oops, something went wrong.