Skip to content

Commit

Permalink
Updated NavigationEventHandler and NavigationEventNavigator to not ha…
Browse files Browse the repository at this point in the history
…ve an upper bounds on NavigationIntent
  • Loading branch information
chRyNaN committed Feb 28, 2022
1 parent b0938ea commit 6c27e3c
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ interface ComposeNavigationIntentStackNavigatorByKey<Context, Intent : Navigatio

override fun ComposeNavigationIntentScope<Context, Intent>.onGoUp() = onGoBack()

override fun ComposeNavigationIntentScope<Context, Intent>.onGoTo(intent: Intent) = goTo(key = intent)
override fun ComposeNavigationIntentScope<Context, Intent>.onGoTo(value: Intent) = goTo(key = value)

override fun navigate(event: NavigationEvent<Intent>) {
scope.onNavigate(value = event)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ fun <Intent : NavigationIntent> navigator(

override fun AndroidNavigationScope.onGoUp() = onGoUp()

override fun AndroidNavigationScope.onGoTo(intent: Intent) = onGoTo(intent)
override fun AndroidNavigationScope.onGoTo(value: Intent) = onGoTo(value)

override fun AndroidNavigationScope.canGoBack(): Boolean = canGoBack()
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,21 @@ package com.chrynan.navigation
* A [NavigationHandler] that provides distinct functions for each of the possible
* [NavigationEvent]s.
*/
interface NavigationEventHandler<Intent : NavigationIntent, Scope : NavigationScope> :
NavigationHandler<NavigationEvent<Intent>, Scope>,
StackNavigationHandler<NavigationEvent<Intent>, Scope> {
interface NavigationEventHandler<NavigationValue, Scope : NavigationScope> :
NavigationHandler<NavigationEvent<NavigationValue>, Scope>,
StackNavigationHandler<NavigationEvent<NavigationValue>, Scope> {

fun Scope.onGoBack()

fun Scope.onGoUp()

fun Scope.onGoTo(intent: Intent)
fun Scope.onGoTo(value: NavigationValue)

override fun Scope.onNavigate(value: NavigationEvent<Intent>) =
override fun Scope.onNavigate(value: NavigationEvent<NavigationValue>) =
when (value) {
is NavigationEvent.Back -> onGoBack()
is NavigationEvent.Up -> onGoUp()
is NavigationEvent.To -> onGoTo(intent = value.value)
is NavigationEvent.To -> onGoTo(value = value.value)
}

override fun Scope.canGoBack(): Boolean = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ package com.chrynan.navigation
* A [Navigator] that navigates using [NavigationEvent]s. This is typically the base [Navigator] but not every UI
* framework can use it, such as Jetpack Compose, so it is separate from the [Navigator] interface.
*/
interface NavigationEventNavigator<Intent : NavigationIntent> : Navigator,
interface NavigationEventNavigator<NavigationValue> : Navigator,
StackNavigator {

/**
* Navigates to the provided [event].
*/
fun navigate(event: NavigationEvent<Intent>)
fun navigate(event: NavigationEvent<NavigationValue>)

override fun goBack() =
if (canGoBack()) {
Expand All @@ -26,11 +26,11 @@ interface NavigationEventNavigator<Intent : NavigationIntent> : Navigator,
/**
* A convenience function for calling [NavigationEventNavigator.navigate] with [NavigationEvent.Up].
*/
fun <Intent : NavigationIntent> NavigationEventNavigator<Intent>.goUp() =
fun <NavigationValue> NavigationEventNavigator<NavigationValue>.goUp() =
navigate(event = NavigationEvent.Up())

/**
* A convenience function for calling [NavigationEventNavigator.navigate] with [NavigationEvent.To].
*/
fun <Intent : NavigationIntent> NavigationEventNavigator<Intent>.goTo(intent: Intent) =
fun <NavigationValue> NavigationEventNavigator<NavigationValue>.goTo(intent: NavigationValue) =
navigate(event = NavigationEvent.To(value = intent))

0 comments on commit 6c27e3c

Please sign in to comment.