Skip to content

Commit e9f1ec6

Browse files
committed
Rename RestoreHistoryOperation to ReplaceAllOperation and move it to its own file
1 parent 26e13a7 commit e9f1ec6

File tree

2 files changed

+30
-13
lines changed

2 files changed

+30
-13
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* Copyright (c) 2026 Element Creations Ltd.
3+
*
4+
* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial.
5+
* Please see LICENSE files in the repository root for full details.
6+
*/
7+
8+
package io.element.android.appnav
9+
10+
import com.bumble.appyx.core.navigation.NavElements
11+
import com.bumble.appyx.core.navigation.Operation
12+
import com.bumble.appyx.navmodel.backstack.BackStack
13+
import kotlinx.parcelize.Parcelize
14+
15+
/**
16+
* Replaces all the current elements with the provided [navElements], keeping their [BackStack.State] too.
17+
*/
18+
@Parcelize
19+
class ReplaceAllOperation<NavTarget : Any>(
20+
private val navElements: NavElements<NavTarget, BackStack.State>
21+
) : Operation<NavTarget, BackStack.State> {
22+
override fun isApplicable(elements: NavElements<NavTarget, BackStack.State>): Boolean {
23+
return true
24+
}
25+
26+
override fun invoke(existing: NavElements<NavTarget, BackStack.State>): NavElements<NavTarget, BackStack.State> {
27+
return navElements
28+
}
29+
}

appnav/src/main/kotlin/io/element/android/appnav/RootFlowNode.kt

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import androidx.lifecycle.lifecycleScope
1818
import com.bumble.appyx.core.modality.BuildContext
1919
import com.bumble.appyx.core.navigation.NavElements
2020
import com.bumble.appyx.core.navigation.NavKey
21-
import com.bumble.appyx.core.navigation.Operation
2221
import com.bumble.appyx.core.node.Node
2322
import com.bumble.appyx.core.plugin.Plugin
2423
import com.bumble.appyx.core.state.MutableSavedStateMap
@@ -167,7 +166,7 @@ class RootFlowNode(
167166
val savedElements = buildContext.savedStateMap?.get("NavModel") as? NavElements<NavTarget, BackStack.State>
168167
if (savedElements != null) {
169168
Timber.d("restoreSavedElements: Saved elements found, restoring them.")
170-
backstack.accept(RestoreHistoryOperation(savedElements))
169+
backstack.accept(ReplaceAllOperation(savedElements))
171170
}
172171
}
173172

@@ -254,17 +253,6 @@ class RootFlowNode(
254253
}
255254
}
256255

257-
@Parcelize
258-
class RestoreHistoryOperation<NavTarget : Any>(private val navElements: NavElements<NavTarget, BackStack.State>) : Operation<NavTarget, BackStack.State> {
259-
override fun isApplicable(elements: NavElements<NavTarget, BackStack.State>): Boolean {
260-
return true
261-
}
262-
263-
override fun invoke(existing: NavElements<NavTarget, BackStack.State>): NavElements<NavTarget, BackStack.State> {
264-
return navElements
265-
}
266-
}
267-
268256
sealed interface NavTarget : Parcelable {
269257
@Parcelize data object SplashScreen : NavTarget
270258

0 commit comments

Comments
 (0)