Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ private sealed interface TopLevelDestination {
val destination: Destination

object Home : TopLevelDestination {
override val destination: Destination = HomeDestination.Home
override val destination: Destination = HomeDestination.Home()
}

object Insurances : TopLevelDestination {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ internal val TopLevelGraph.destination: Destination

internal val TopLevelGraph.startDestination: Destination
get() = when (this) {
TopLevelGraph.Home -> HomeDestination.Home
TopLevelGraph.Home -> HomeDestination.Home()
TopLevelGraph.Insurances -> InsurancesDestination.Insurances
TopLevelGraph.Forever -> ForeverDestination.Forever
TopLevelGraph.Payments -> PaymentsDestination.Payments
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ sealed interface HomeDestination {
data object Graph : HomeDestination, Destination

@Serializable
data object Home : HomeDestination, Destination
data class Home(
// When true, the home screen automatically opens the start-claim consent sheet on arrival. Defaults to false for
// regular home navigation; set to true when arriving via the `/submit-claim` deep link (see homeGraph).
val startClaimFlow: Boolean = false,
) : HomeDestination, Destination

@Serializable
data class FirstVet(val sections: List<FirstVetSection>) : HomeDestination, Destination {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package com.hedvig.android.feature.home.home.navigation

import android.content.Intent
import androidx.core.os.BundleCompat
import androidx.lifecycle.compose.dropUnlessResumed
import androidx.navigation.NavBackStackEntry
import androidx.navigation.NavController
import androidx.navigation.NavGraphBuilder
import coil3.ImageLoader
Expand Down Expand Up @@ -45,8 +48,10 @@ fun NavGraphBuilder.homeGraph(
exitTransition = { MotionDefaults.fadeThroughExit },
) {
val viewModel: HomeViewModel = koinViewModel()
val startClaimFlow = startClaimFlow || it.wasLaunchedFromClaimDeepLink(hedvigDeepLinkContainer)
HomeDestination(
viewModel = viewModel,
startClaimFlow = startClaimFlow,
onNavigateToInbox = dropUnlessResumed { onNavigateToInbox() },
onNavigateToNewConversation = dropUnlessResumed { onNavigateToNewConversation() },
navigateToClaimChat = dropUnlessResumed { navigateToClaimChat() },
Expand Down Expand Up @@ -84,3 +89,14 @@ fun NavGraphBuilder.homeGraph(
nestedGraphs()
}
}

/**
* Whether this back stack entry was opened by the claim flow deep link (`/submit-claim`). The deep link does not carry
* any route argument, so we inspect the launching intent's URI and match it against the known claim flow patterns.
*/
private fun NavBackStackEntry.wasLaunchedFromClaimDeepLink(hedvigDeepLinkContainer: HedvigDeepLinkContainer): Boolean {
val arguments = arguments ?: return false
val deepLinkIntent = BundleCompat.getParcelable(arguments, NavController.KEY_DEEP_LINK_INTENT, Intent::class.java)
val deepLinkUri = deepLinkIntent?.data?.toString() ?: return false
return hedvigDeepLinkContainer.claimFlow.any { claimFlowUri -> deepLinkUri.startsWith(claimFlowUri) }
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.produceState
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberUpdatedState
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.runtime.snapshotFlow
import androidx.compose.ui.Alignment
Expand Down Expand Up @@ -153,6 +154,7 @@ import org.jetbrains.compose.resources.stringResource
@Composable
internal fun HomeDestination(
viewModel: HomeViewModel,
startClaimFlow: Boolean,
onNavigateToInbox: () -> Unit,
onNavigateToNewConversation: () -> Unit,
navigateToClaimChat: () -> Unit,
Expand All @@ -174,6 +176,7 @@ internal fun HomeDestination(
val notificationPermissionState = rememberNotificationPermissionState()
HomeScreen(
uiState = uiState,
startClaimFlow = startClaimFlow,
notificationPermissionState = notificationPermissionState,
reload = { viewModel.emit(HomeEvent.RefreshData) },
onNavigateToInbox = onNavigateToInbox,
Expand Down Expand Up @@ -203,6 +206,7 @@ internal fun HomeDestination(
@Composable
private fun HomeScreen(
uiState: HomeUiState,
startClaimFlow: Boolean,
notificationPermissionState: NotificationPermissionState,
reload: () -> Unit,
onNavigateToInbox: () -> Unit,
Expand Down Expand Up @@ -247,6 +251,17 @@ private fun HomeScreen(
navigateToClaimChatInDevMode = navigateToClaimChatInDevMode,
isStagingEnvironment = (uiState as? Success)?.isProduction?.not() ?: false,
)
// Auto-open the start-claim consent sheet when arriving via the `/submit-claim` deep link, mirroring a tap on the
// "Start claim" button. Guarded so it only happens once per entry, surviving recompositions and configuration changes.
if (startClaimFlow) {
var hasOpenedStartClaimSheet by rememberSaveable { mutableStateOf(false) }
LaunchedEffect(Unit) {
if (!hasOpenedStartClaimSheet) {
hasOpenedStartClaimSheet = true
startClaimBottomSheetState.show()
}
}
}
Box(Modifier.fillMaxSize()) {
val toolbarHeight = 64.dp
val transition = updateTransition(targetState = uiState, label = "home ui state")
Expand Down Expand Up @@ -802,6 +817,7 @@ private fun PreviewHomeScreen(
),
isProduction = true,
),
startClaimFlow = false,
notificationPermissionState = rememberPreviewNotificationPermissionState(),
reload = {},
onNavigateToInbox = {},
Expand Down Expand Up @@ -835,6 +851,7 @@ private fun PreviewHomeScreenWithError() {
Surface(color = HedvigTheme.colorScheme.backgroundPrimary) {
HomeScreen(
uiState = HomeUiState.Error(null),
startClaimFlow = false,
notificationPermissionState = rememberPreviewNotificationPermissionState(),
reload = {},
onNavigateToInbox = {},
Expand Down Expand Up @@ -889,6 +906,7 @@ private fun PreviewHomeScreenAllHomeTextTypes(
addonBannerInfo = null,
isProduction = true,
),
startClaimFlow = false,
notificationPermissionState = rememberPreviewNotificationPermissionState(),
reload = {},
onNavigateToInbox = {},
Expand Down
Loading