Skip to content

Commit

Permalink
Merge pull request #2225 from HedvigInsurance/fix/cbm-related-fixes
Browse files Browse the repository at this point in the history
Fix/cbm related fixes
  • Loading branch information
StylianosGakis authored Sep 16, 2024
2 parents bea5a46 + 5c10475 commit 8c02415
Show file tree
Hide file tree
Showing 16 changed files with 286 additions and 219 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,13 @@ import com.hedvig.android.feature.terminateinsurance.navigation.TerminateInsuran
import com.hedvig.android.feature.terminateinsurance.navigation.terminateInsuranceGraph
import com.hedvig.android.feature.travelcertificate.navigation.travelCertificateGraph
import com.hedvig.android.language.LanguageService
import com.hedvig.android.logger.logcat
import com.hedvig.android.market.Market
import com.hedvig.android.navigation.activity.ExternalNavigator
import com.hedvig.android.navigation.compose.Destination
import com.hedvig.android.navigation.compose.typedPopUpTo
import com.hedvig.android.navigation.core.AppDestination
import com.hedvig.android.navigation.core.AppDestination.ClaimDetails
import com.hedvig.android.navigation.core.HedvigDeepLinkContainer
import com.hedvig.android.navigation.core.Navigator

Expand Down Expand Up @@ -265,6 +267,10 @@ internal fun HedvigNavHost(
hedvigBuildConstants = hedvigBuildConstants,
imageLoader = imageLoader,
openUrl = openUrl,
onNavigateToClaimDetails = { claimId ->
logcat { "Navigating to claim details from chat" }
hedvigAppState.navController.navigate(ClaimDetails(claimId))
},
navigator = navigator,
)
connectPaymentGraph(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,36 +1,19 @@
package com.hedvig.android.design.system.hedvig

import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.ColumnScope
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.RowScope
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.WindowInsets
import androidx.compose.foundation.layout.WindowInsetsSides
import androidx.compose.foundation.layout.displayCutout
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.only
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.safeDrawing
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.systemBars
import androidx.compose.foundation.layout.union
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.layout.windowInsetsPadding
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp
import com.hedvig.android.design.system.hedvig.TopAppBarDefaults.windowInsets
import com.hedvig.android.design.system.hedvig.icon.ArrowLeft
import com.hedvig.android.design.system.hedvig.icon.Close
import com.hedvig.android.design.system.hedvig.icon.HedvigIcons
import com.hedvig.android.design.system.hedvig.tokens.ScaffoldTokens

@Composable
Expand All @@ -53,8 +36,8 @@ fun Scaffold(
) {
TopAppBar(
title = topAppBarText ?: "",
onClick = navigateUp,
actionType = topAppBarActionType,
onActionClick = navigateUp,
topAppBarActions = topAppBarActions,
)
Column(
Expand All @@ -74,112 +57,6 @@ fun Scaffold(
}
}

@Composable
fun TopAppBarLayoutForActions(modifier: Modifier = Modifier, actions: @Composable RowScope.() -> Unit = {}) {
Row(
horizontalArrangement = Arrangement.End,
verticalAlignment = Alignment.CenterVertically,
modifier = modifier
.windowInsetsPadding(windowInsets)
.height(ScaffoldTokens.TopAppBarHeight)
.fillMaxWidth()
.padding(horizontal = ScaffoldTokens.TopAppBarHorizontalPadding),
) {
actions()
}
}

@Composable
fun TopAppBarWithBack(
title: String,
onClick: () -> Unit,
modifier: Modifier = Modifier,
windowInsets: WindowInsets = TopAppBarDefaults.windowInsets,
) {
TopAppBar(
title = title,
onClick = onClick,
actionType = TopAppBarActionType.BACK,
modifier = modifier,
windowInsets = windowInsets,
)
}

enum class TopAppBarActionType {
BACK,
CLOSE,
}

internal object TopAppBarDefaults {
val windowInsets: WindowInsets
@Composable
get() = WindowInsets.systemBars
.union(WindowInsets.displayCutout)
.only(WindowInsetsSides.Horizontal + WindowInsetsSides.Top)
}

@Composable
fun TopAppBar(
title: String,
onClick: () -> Unit,
actionType: TopAppBarActionType,
modifier: Modifier = Modifier,
topAppBarActions: @Composable (RowScope.() -> Unit)? = null,
windowInsets: WindowInsets = TopAppBarDefaults.windowInsets,
) {
Row(
verticalAlignment = Alignment.CenterVertically,
modifier =
modifier
.windowInsetsPadding(windowInsets)
.height(ScaffoldTokens.TopAppBarHeight)
.fillMaxWidth()
.padding(horizontal = ScaffoldTokens.TopAppBarHorizontalPadding),
) {
HorizontalItemsWithMaximumSpaceTaken(
startSlot = {
Row(
horizontalArrangement = Arrangement.Start,
verticalAlignment = Alignment.CenterVertically,
) {
IconButton(
onClick = { onClick() },
modifier = Modifier.size(24.dp),
content = {
Icon(
imageVector = when (actionType) {
TopAppBarActionType.BACK -> HedvigIcons.ArrowLeft
TopAppBarActionType.CLOSE -> HedvigIcons.Close
},
contentDescription = null,
)
},
)
Spacer(Modifier.width(8.dp))
HedvigText(
text = title,
maxLines = 1,
overflow = TextOverflow.Ellipsis,
modifier = Modifier.padding(top = 10.dp, bottom = 10.dp),
style = ScaffoldTokens.TopAppBarTextStyle.value,
)
}
},
endSlot = {
if (topAppBarActions != null) {
Row(
horizontalArrangement = Arrangement.End,
verticalAlignment = Alignment.CenterVertically,
) {
topAppBarActions()
}
}
},
spaceBetween = 8.dp,
)
}
}

private data class ScaffoldColors(
val background: Color,
)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,190 @@
package com.hedvig.android.design.system.hedvig

import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.RowScope
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.WindowInsets
import androidx.compose.foundation.layout.WindowInsetsSides
import androidx.compose.foundation.layout.displayCutout
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.only
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.systemBars
import androidx.compose.foundation.layout.union
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.layout.windowInsetsPadding
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp
import com.hedvig.android.design.system.hedvig.TopAppBarDefaults.windowInsets
import com.hedvig.android.design.system.hedvig.icon.ArrowLeft
import com.hedvig.android.design.system.hedvig.icon.Close
import com.hedvig.android.design.system.hedvig.icon.HedvigIcons
import com.hedvig.android.design.system.hedvig.tokens.TopAppBarTokens

@Composable
fun TopAppBar(
actionType: TopAppBarActionType,
onActionClick: () -> Unit,
modifier: Modifier = Modifier,
windowInsets: WindowInsets = TopAppBarDefaults.windowInsets,
content: @Composable () -> Unit,
) {
Surface(
color = TopAppBarTokens.ContainerColor.value,
contentColor = TopAppBarTokens.ContentColor.value,
modifier = modifier.fillMaxWidth(),
) {
Row(
verticalAlignment = Alignment.CenterVertically,
modifier = modifier
.windowInsetsPadding(windowInsets)
.height(TopAppBarTokens.ContainerHeight)
.padding(horizontal = TopAppBarTokens.ContentHorizontalPadding),
) {
IconButton(
onClick = onActionClick,
content = {
Icon(
imageVector = when (actionType) {
TopAppBarActionType.BACK -> HedvigIcons.ArrowLeft
TopAppBarActionType.CLOSE -> HedvigIcons.Close
},
contentDescription = null,
modifier = Modifier.size(24.dp),
)
},
)
Spacer(Modifier.width(8.dp))
CompositionLocalProvider(LocalTextStyle provides TopAppBarTokens.TextStyle.value) {
Box(
Modifier
.weight(1f)
.fillMaxHeight(),
propagateMinConstraints = true,
) {
content()
}
}
}
}
}

@Composable
fun TopAppBar(
title: String,
actionType: TopAppBarActionType,
onActionClick: () -> Unit,
modifier: Modifier = Modifier,
topAppBarActions: @Composable (RowScope.() -> Unit)? = null,
windowInsets: WindowInsets = TopAppBarDefaults.windowInsets,
) {
Surface(
color = TopAppBarTokens.ContainerColor.value,
contentColor = TopAppBarTokens.ContentColor.value,
modifier = modifier
.fillMaxWidth()
.height(TopAppBarTokens.ContainerHeight),
) {
Row(
verticalAlignment = Alignment.CenterVertically,
modifier = Modifier
.windowInsetsPadding(windowInsets)
.padding(horizontal = TopAppBarTokens.ContentHorizontalPadding),
) {
HorizontalItemsWithMaximumSpaceTaken(
startSlot = {
Row(
horizontalArrangement = Arrangement.Start,
verticalAlignment = Alignment.CenterVertically,
) {
IconButton(
onClick = onActionClick,
modifier = Modifier.size(24.dp),
content = {
Icon(
imageVector = when (actionType) {
TopAppBarActionType.BACK -> HedvigIcons.ArrowLeft
TopAppBarActionType.CLOSE -> HedvigIcons.Close
},
contentDescription = null,
)
},
)
Spacer(Modifier.width(8.dp))
HedvigText(
text = title,
maxLines = 1,
overflow = TextOverflow.Ellipsis,
modifier = Modifier.padding(top = 10.dp, bottom = 10.dp),
style = TopAppBarTokens.TextStyle.value,
)
}
},
endSlot = {
if (topAppBarActions != null) {
Row(
horizontalArrangement = Arrangement.End,
verticalAlignment = Alignment.CenterVertically,
) {
topAppBarActions()
}
}
},
spaceBetween = 8.dp,
)
}
}
}

@Composable
internal fun TopAppBarLayoutForActions(modifier: Modifier = Modifier, actions: @Composable RowScope.() -> Unit = {}) {
Row(
horizontalArrangement = Arrangement.End,
verticalAlignment = Alignment.CenterVertically,
modifier = modifier
.windowInsetsPadding(windowInsets)
.height(TopAppBarTokens.ContainerHeight)
.fillMaxWidth()
.padding(horizontal = TopAppBarTokens.ContentHorizontalPadding),
) {
actions()
}
}

@Composable
internal fun TopAppBarWithBack(
title: String,
onClick: () -> Unit,
modifier: Modifier = Modifier,
windowInsets: WindowInsets = TopAppBarDefaults.windowInsets,
) {
TopAppBar(
title = title,
actionType = TopAppBarActionType.BACK,
onActionClick = onClick,
modifier = modifier,
windowInsets = windowInsets,
)
}

enum class TopAppBarActionType {
BACK,
CLOSE,
}

internal object TopAppBarDefaults {
val windowInsets: WindowInsets
@Composable
get() = WindowInsets.systemBars
.union(WindowInsets.displayCutout)
.only(WindowInsetsSides.Horizontal + WindowInsetsSides.Top)
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
package com.hedvig.android.design.system.hedvig.tokens

import androidx.compose.ui.unit.dp

internal object ScaffoldTokens {
val BackgroundColor = ColorSchemeKeyTokens.BackgroundPrimary
val TopAppBarHeight = 64.dp
val TopAppBarHorizontalPadding = 16.dp
val TopAppBarTextStyle = TypographyKeyTokens.HeadlineSmall
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.hedvig.android.design.system.hedvig.tokens

import androidx.compose.ui.unit.dp

internal object TopAppBarTokens {
val ContainerColor = ColorSchemeKeyTokens.BackgroundPrimary
val ContentColor = ColorSchemeKeyTokens.TextPrimary
val ContainerHeight = 64.dp
val ContentHorizontalPadding = 16.dp
val TextStyle = TypographyKeyTokens.HeadlineSmall
}
Loading

0 comments on commit 8c02415

Please sign in to comment.