Updated on 2026-08-14

This commit is contained in:
Tangem 2022-11-07 19:30:35 +05:00
parent d3a1c61088
commit 4e4b90c2a6
5 changed files with 16 additions and 9 deletions

View file

@ -132,7 +132,7 @@ class MainActivity : AppCompatActivity(), SnackbarHandler, ActivityResultCallbac
}
override fun onDestroy() {
store.dispatch(NavigationAction.ActivityDestroyed)
store.dispatch(NavigationAction.ActivityDestroyed(WeakReference(this)))
super.onDestroy()
}

View file

@ -1,7 +1,7 @@
package com.tangem.tap.common.redux.navigation
import android.net.Uri
import androidx.fragment.app.FragmentActivity
import androidx.appcompat.app.AppCompatActivity
import org.rekotlin.Action
import java.lang.ref.WeakReference
@ -9,7 +9,7 @@ sealed class NavigationAction : Action {
data class NavigateTo(
val screen: AppScreen,
val fragmentShareTransition: FragmentShareTransition? = null,
val addToBackstack: Boolean = true
val addToBackstack: Boolean = true,
) : NavigationAction()
data class PopBackTo(val screen: AppScreen? = null) : NavigationAction()
@ -20,6 +20,6 @@ sealed class NavigationAction : Action {
data class Share(val data: String) : NavigationAction()
data class ActivityCreated(val activity: WeakReference<FragmentActivity>) : NavigationAction()
object ActivityDestroyed : NavigationAction()
data class ActivityCreated(val activity: WeakReference<AppCompatActivity>) : NavigationAction()
data class ActivityDestroyed(val activity: WeakReference<AppCompatActivity>) : NavigationAction()
}

View file

@ -25,7 +25,14 @@ private fun internalReduce(action: Action, state: AppState): NavigationState {
state.navigationState.copy(backStack = navState.backStack.subList(0, index))
}
is NavigationAction.ActivityCreated -> navState.copy(activity = navigationAction.activity)
is NavigationAction.ActivityDestroyed -> navState.copy(activity = null)
is NavigationAction.ActivityDestroyed -> {
when {
// Destroy the activity if it invoked for the same activity. Prevents overwriting to null if there is a
// new scan from the background [REDACTED_TASK_KEY]
navState.activity?.get() == navigationAction.activity.get() -> navState.copy(activity = null)
else -> navState
}
}
else -> navState
}
}

View file

@ -1,12 +1,12 @@
package com.tangem.tap.common.redux.navigation
import androidx.fragment.app.FragmentActivity
import androidx.appcompat.app.AppCompatActivity
import org.rekotlin.StateType
import java.lang.ref.WeakReference
data class NavigationState(
val backStack: List<AppScreen> = listOf(AppScreen.Home),
val activity: WeakReference<FragmentActivity>? = null
val activity: WeakReference<AppCompatActivity>? = null,
) : StateType
enum class AppScreen {