From 1f8b5255486c7ba7f1b05088218eb140e6e5647f Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Mon, 17 Jun 2024 16:36:02 +0200 Subject: [PATCH] Fix back navigation issue, when opening directly the notification troubleshoot screen. --- .../preferences/impl/PreferencesFlowNode.kt | 7 +++++- .../architecture/appyx/BackStackExt.kt | 25 +++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 libraries/architecture/src/main/kotlin/io/element/android/libraries/architecture/appyx/BackStackExt.kt diff --git a/features/preferences/impl/src/main/kotlin/io/element/android/features/preferences/impl/PreferencesFlowNode.kt b/features/preferences/impl/src/main/kotlin/io/element/android/features/preferences/impl/PreferencesFlowNode.kt index 8fef6053a4..6d3661aace 100644 --- a/features/preferences/impl/src/main/kotlin/io/element/android/features/preferences/impl/PreferencesFlowNode.kt +++ b/features/preferences/impl/src/main/kotlin/io/element/android/features/preferences/impl/PreferencesFlowNode.kt @@ -44,6 +44,7 @@ import io.element.android.features.preferences.impl.root.PreferencesRootNode import io.element.android.features.preferences.impl.user.editprofile.EditUserProfileNode import io.element.android.libraries.architecture.BackstackView import io.element.android.libraries.architecture.BaseFlowNode +import io.element.android.libraries.architecture.appyx.canPop import io.element.android.libraries.architecture.createNode import io.element.android.libraries.di.SessionScope import io.element.android.libraries.matrix.api.core.RoomId @@ -190,7 +191,11 @@ class PreferencesFlowNode @AssistedInject constructor( notificationTroubleShootEntryPoint.nodeBuilder(this, buildContext) .callback(object : NotificationTroubleShootEntryPoint.Callback { override fun onDone() { - backstack.pop() + if (backstack.canPop()) { + backstack.pop() + } else { + navigateUp() + } } }) .build() diff --git a/libraries/architecture/src/main/kotlin/io/element/android/libraries/architecture/appyx/BackStackExt.kt b/libraries/architecture/src/main/kotlin/io/element/android/libraries/architecture/appyx/BackStackExt.kt new file mode 100644 index 0000000000..27d106eb66 --- /dev/null +++ b/libraries/architecture/src/main/kotlin/io/element/android/libraries/architecture/appyx/BackStackExt.kt @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2024 New Vector Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.element.android.libraries.architecture.appyx + +import com.bumble.appyx.navmodel.backstack.BackStack + +fun BackStack.canPop(): Boolean { + val elements = elements.value + return elements.any { it.targetState == BackStack.State.ACTIVE } && + elements.any { it.targetState == BackStack.State.STASHED } +}