Skip to content

Commit

Permalink
Make NavEvent subtypes public (#660)
Browse files Browse the repository at this point in the history
This allows for more dynamic/precise control of child nav events from a
parent screen.

Resolves #653

CC @chrisbanes
  • Loading branch information
ZacSweers authored May 31, 2023
1 parent 293dac0 commit 59006ef
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,16 @@ public fun CircuitContent(
remember(onNavEvent) {
object : Navigator {
override fun goTo(screen: Screen) {
onNavEvent(GoToNavEvent(screen))
onNavEvent(NavEvent.GoTo(screen))
}

override fun resetRoot(newRoot: Screen): List<Screen> {
onNavEvent(ResetRootNavEvent(newRoot))
onNavEvent(NavEvent.ResetRoot(newRoot))
return emptyList()
}

override fun pop(): Screen? {
onNavEvent(PopNavEvent)
onNavEvent(NavEvent.Pop)
return null
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,20 @@ import com.slack.circuit.runtime.presenter.Presenter
*/
public fun Navigator.onNavEvent(event: NavEvent) {
when (event) {
is GoToNavEvent -> goTo(event.screen)
is ResetRootNavEvent -> resetRoot(event.newRoot)
PopNavEvent -> pop()
NavEvent.Pop -> pop()
is NavEvent.GoTo -> goTo(event.screen)
is NavEvent.ResetRoot -> resetRoot(event.newRoot)
}
}

/** A sealed navigation interface intended to be used when making a navigation call back. */
public sealed interface NavEvent : CircuitUiEvent
/** A sealed navigation interface intended to be used when making a navigation callback. */
public sealed interface NavEvent : CircuitUiEvent {
/** Corresponds to [Navigator.pop]. */
public object Pop : NavEvent

internal object PopNavEvent : NavEvent
/** Corresponds to [Navigator.goTo]. */
public data class GoTo(internal val screen: Screen) : NavEvent

internal data class GoToNavEvent(internal val screen: Screen) : NavEvent

internal data class ResetRootNavEvent(internal val newRoot: Screen) : NavEvent
/** Corresponds to [Navigator.resetRoot]. */
public data class ResetRoot(internal val newRoot: Screen) : NavEvent
}

0 comments on commit 59006ef

Please sign in to comment.