Skip to content

Commit

Permalink
Merge pull request #33 from NordicPlayground/fix/double_event
Browse files Browse the repository at this point in the history
Fix navigation issue when 2 events are emitted quickly.
  • Loading branch information
sylwester-zielinski authored Jan 25, 2023
2 parents 6d26bc3 + 45f446e commit f78d502
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.mapNotNull
import kotlinx.parcelize.RawValue
import no.nordicsemi.android.common.navigation.internal.NavigationManager
import no.nordicsemi.android.common.navigation.internal.START_DESTINATION

interface Navigator {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,18 +61,31 @@ import javax.inject.Inject
@ActivityRetainedScoped
internal class NavigationManager @Inject constructor(
@ApplicationContext private val context: Context,
): Navigator {
) : Navigator {
/** The navigation events class. */
sealed class Event {
data class NavigateTo(val route: String, val args: Bundle?, val navOptions: NavOptions? = null) : Event()
data class NavigateUp(val result: Any?) : Event()
data class NavigateTo(
val route: String,
val args: Bundle?,
val navOptions: NavOptions? = null,
val counter: Int = Event.counter++
) : Event()

data class NavigateUp(val result: Any?, val counter: Int = Event.counter++) : Event()

companion object {
private var counter = 0
}
}

/** Savable results that can be stored in [SavedStateHandle]. */
sealed class Result: Parcelable {
@Parcelize object Initial : Result()
@Parcelize object Cancelled : Result()
@Parcelize data class Success<R>(val value: @RawValue R) : Result()
sealed class Result : Parcelable {
@Parcelize
object Initial : Result()
@Parcelize
object Cancelled : Result()
@Parcelize
data class Success<R>(val value: @RawValue R) : Result()
}

private val map = mutableMapOf<DestinationId<*, *>, MutableStateFlow<Boolean>>()
Expand Down Expand Up @@ -150,7 +163,7 @@ internal class NavigationManager @Inject constructor(

override fun open(link: Uri) {
try {
with (Intent(Intent.ACTION_VIEW, link)) {
with(Intent(Intent.ACTION_VIEW, link)) {
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
context.startActivity(this)
}
Expand Down

0 comments on commit f78d502

Please sign in to comment.