Skip to content

Commit

Permalink
Merge pull request #233 from niscy-eudiw/main
Browse files Browse the repository at this point in the history
Resolved navigation issue with OpenId4VCI flows
  • Loading branch information
stzouvaras authored Nov 26, 2024
2 parents a44d970 + 88787ee commit d66c4b1
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -350,8 +350,9 @@ class PinViewModel(

val navigationAfterCreate = ConfigNavigation(
navigationType = NavigationType.PushScreen(
IssuanceScreens.AddDocument,
mapOf("flowType" to IssuanceFlowUiConfig.NO_DOCUMENT.name)
screen = IssuanceScreens.AddDocument,
arguments = mapOf("flowType" to IssuanceFlowUiConfig.NO_DOCUMENT.name),
popUpToScreen = CommonScreens.QuickPin
),
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,8 @@ class QrScanViewModel(
IssuanceFlowUiConfig.NO_DOCUMENT -> {
ConfigNavigation(
navigationType = NavigationType.PushRoute(
route = DashboardScreens.Dashboard.screenRoute
route = DashboardScreens.Dashboard.screenRoute,
popUpToRoute = IssuanceScreens.AddDocument.screenRoute
)
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ import eu.europa.ec.uilogic.component.wrap.WrapSecondaryButton
import eu.europa.ec.uilogic.config.ConfigNavigation
import eu.europa.ec.uilogic.config.NavigationType
import eu.europa.ec.uilogic.extension.cacheDeepLink
import eu.europa.ec.uilogic.navigation.CommonScreens
import eu.europa.ec.uilogic.navigation.StartupScreens
import kotlinx.coroutines.channels.Channel
import kotlinx.coroutines.flow.Flow
Expand Down Expand Up @@ -84,8 +83,10 @@ fun SuccessScreen(
when (navigationEffect) {
is Effect.Navigation.SwitchScreen -> {
navController.navigate(navigationEffect.screenRoute) {
popUpTo(CommonScreens.Success.screenRoute) {
inclusive = true
navigationEffect.popUpRoute?.let { popUpToRoute ->
popUpTo(popUpToRoute) {
inclusive = true
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ sealed class Event : ViewEvent {
sealed class Effect : ViewSideEffect {
sealed class Navigation : Effect() {
data class SwitchScreen(
val screenRoute: String
val screenRoute: String,
val popUpRoute: String?
) : Navigation()

data class PopBackStackUpTo(
Expand Down Expand Up @@ -101,10 +102,11 @@ class SuccessViewModel(

is NavigationType.PushScreen -> {
Effect.Navigation.SwitchScreen(
generateComposableNavigationLink(
screenRoute = generateComposableNavigationLink(
screen = nav.screen,
arguments = generateComposableArguments(nav.arguments),
)
),
popUpRoute = nav.popUpToScreen?.screenRoute
)
}

Expand All @@ -115,7 +117,10 @@ class SuccessViewModel(

is NavigationType.Pop, NavigationType.Finish -> Effect.Navigation.Pop

is NavigationType.PushRoute -> Effect.Navigation.SwitchScreen(nav.route)
is NavigationType.PushRoute -> Effect.Navigation.SwitchScreen(
nav.route,
nav.popUpToRoute
)
}

setEffect {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import eu.europa.ec.uilogic.component.InfoTextWithNameAndValueData
import eu.europa.ec.uilogic.config.ConfigNavigation
import eu.europa.ec.uilogic.config.NavigationType
import eu.europa.ec.uilogic.navigation.DashboardScreens
import eu.europa.ec.uilogic.navigation.IssuanceScreens

@VisibleForTesting(otherwise = VisibleForTesting.NONE)
object TestsData {
Expand Down Expand Up @@ -496,7 +497,8 @@ object TestsData {
val mockedConfigNavigationTypePop = ConfigNavigation(navigationType = NavigationType.Pop)
val mockedConfigNavigationTypePush = ConfigNavigation(
navigationType = NavigationType.PushRoute(
route = DashboardScreens.Dashboard.screenRoute
route = DashboardScreens.Dashboard.screenRoute,
popUpToRoute = IssuanceScreens.AddDocument.screenRoute
)
)
val mockedConfigNavigationTypePopToScreen = ConfigNavigation(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import eu.europa.ec.uilogic.config.ConfigNavigation
import eu.europa.ec.uilogic.config.NavigationType
import eu.europa.ec.uilogic.navigation.CommonScreens
import eu.europa.ec.uilogic.navigation.DashboardScreens
import eu.europa.ec.uilogic.navigation.IssuanceScreens
import eu.europa.ec.uilogic.navigation.helper.generateComposableArguments
import eu.europa.ec.uilogic.navigation.helper.generateComposableNavigationLink
import eu.europa.ec.uilogic.serializer.UiSerializer
Expand Down Expand Up @@ -177,7 +178,10 @@ class AddDocumentInteractorImpl(
override fun buildGenericSuccessRouteForDeferred(flowType: IssuanceFlowUiConfig): String {
val navigation = when (flowType) {
IssuanceFlowUiConfig.NO_DOCUMENT -> ConfigNavigation(
navigationType = NavigationType.PushRoute(route = DashboardScreens.Dashboard.screenRoute),
navigationType = NavigationType.PushRoute(
route = DashboardScreens.Dashboard.screenRoute,
popUpToRoute = IssuanceScreens.AddDocument.screenRoute
),
)

IssuanceFlowUiConfig.EXTRA_DOCUMENT -> ConfigNavigation(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,8 @@ class AddDocumentViewModel(
offerURI = it.link.toString(),
onSuccessNavigation = ConfigNavigation(
navigationType = NavigationType.PushScreen(
screen = DashboardScreens.Dashboard
screen = DashboardScreens.Dashboard,
popUpToScreen = IssuanceScreens.AddDocument
)
),
onCancelNavigation = ConfigNavigation(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import eu.europa.ec.uilogic.navigation.Screen

data class ConfigNavigation(
val navigationType: NavigationType,
val flags: Int = 0,
val indicateFlowCompletion: FlowCompletion = FlowCompletion.NONE
)

Expand All @@ -29,10 +28,14 @@ sealed interface NavigationType {
data object Finish : NavigationType
data class PushScreen(
val screen: Screen,
val arguments: Map<String, String> = emptyMap()
val arguments: Map<String, String> = emptyMap(),
val popUpToScreen: Screen? = null
) : NavigationType

data class PushRoute(val route: String) : NavigationType
data class PushRoute(
val route: String,
val popUpToRoute: String? = null
) : NavigationType

data class PopTo(val screen: Screen) : NavigationType
data class Deeplink(val link: String, val routeToPop: String? = null) : NavigationType
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class RouterHostImpl(
}
navController.getBackStackEntry(screenRoute)
return true
} catch (e: Exception) {
} catch (_: Exception) {
return false
}
}
Expand Down

0 comments on commit d66c4b1

Please sign in to comment.