Skip to content

Commit

Permalink
Merge pull request #2289 from HedvigInsurance/ds/insurances
Browse files Browse the repository at this point in the history
GEN-2542 Ds/insurances
  • Loading branch information
StylianosGakis authored Nov 15, 2024
2 parents 26afd11 + 4634723 commit 2b2023f
Show file tree
Hide file tree
Showing 21 changed files with 532 additions and 668 deletions.
1 change: 1 addition & 0 deletions .idea/codeInsightSettings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ private val emptyStateColors: EmptyStateColors

@Preview
@Composable
fun EmptyStatePreview() {
private fun EmptyStatePreview() {
HedvigTheme {
Surface(color = Color.White) {
EmptyState(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@ import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.WindowInsets
import androidx.compose.foundation.layout.WindowInsetsSides
import androidx.compose.foundation.layout.WindowInsetsSides.Companion
import androidx.compose.foundation.layout.asPaddingValues
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.width
Expand All @@ -21,6 +24,7 @@ import androidx.compose.foundation.verticalScroll
import androidx.compose.runtime.Composable
import androidx.compose.runtime.Immutable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.Stable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
Expand Down Expand Up @@ -92,6 +96,64 @@ fun HedvigBottomSheet(
}
}

@Composable
fun <T> rememberHedvigBottomSheetState(): HedvigBottomSheetState<T> {
return remember { HedvigBottomSheetStateImpl() }
}

@Stable
interface HedvigBottomSheetState<T> {
val isVisible: Boolean
val data: T?

fun show(data: T)

fun dismiss()
}

fun HedvigBottomSheetState<Unit>.show() {
show(Unit)
}

private class HedvigBottomSheetStateImpl<T>() : HedvigBottomSheetState<T> {
override var isVisible: Boolean by mutableStateOf(false)
private set
override var data: T? by mutableStateOf(null)
private set

override fun dismiss() {
isVisible = false
}

override fun show(data: T) {
this.data = data
isVisible = true
}
}

@OptIn(ExperimentalSheetApi::class)
@Composable
fun <T> HedvigBottomSheet(
hedvigBottomSheetState: HedvigBottomSheetState<T>,
content: @Composable ColumnScope.(T) -> Unit,
) {
InternalHedvigBottomSheet(
isVisible = hedvigBottomSheetState.isVisible,
onVisibleChange = {
if (!it) {
hedvigBottomSheetState.dismiss()
}
},
onSystemBack = {
hedvigBottomSheetState.dismiss()
},
) {
if (hedvigBottomSheetState.data != null) {
content(hedvigBottomSheetState.data!!)
}
}
}

@OptIn(ExperimentalSheetApi::class)
@Composable
private fun InternalHedvigBottomSheet(
Expand All @@ -110,8 +172,8 @@ private fun InternalHedvigBottomSheet(
scrollState.animateScrollTo(scrollState.maxValue)
}
}
val defaultPadding = WindowInsets.safeDrawing.asPaddingValues()
val finalSheetPadding = sheetPadding ?: defaultPadding
val finalSheetPadding =
sheetPadding ?: WindowInsets.safeDrawing.only(WindowInsetsSides.Top + Companion.Horizontal).asPaddingValues()
ModalSheet(
visible = isVisible,
onVisibleChange = onVisibleChange,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ fun NavigationRail(
modifier: Modifier = Modifier,
) {
val borderColor = NavigationTokens.BorderColor.value
NavigationContainer(modifier) {
NavigationContainer(modifier.fillMaxHeight()) {
Column(
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = if (isExtraTall) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.hedvig.android.design.system.hedvig

import androidx.compose.animation.core.FastOutSlowInEasing
import androidx.compose.animation.core.FiniteAnimationSpec
import androidx.compose.animation.core.animateIntOffsetAsState
import androidx.compose.animation.core.tween
import androidx.compose.foundation.background
Expand Down Expand Up @@ -56,14 +57,15 @@ fun HedvigTabRowMaxSixTabs(
modifier: Modifier = Modifier,
tabSize: TabSize = TabDefaults.defaultSize,
tabStyle: TabStyle = TabDefaults.defaultStyle,
selectIndicatorAnimationSpec: FiniteAnimationSpec<IntOffset> = tween(
durationMillis = 600,
easing = FastOutSlowInEasing,
),
) {
var currentIndicatorOffset by rememberSaveable(stateSaver = IntOffset.Saver) { mutableStateOf(IntOffset(0, 0)) }
val indicatorOffset: IntOffset by animateIntOffsetAsState(
targetValue = currentIndicatorOffset,
animationSpec = tween(
durationMillis = 600,
easing = FastOutSlowInEasing,
),
animationSpec = selectIndicatorAnimationSpec,
label = "",
)
var oneLineHeight by remember { mutableIntStateOf(0) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import androidx.compose.foundation.layout.only
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.safeDrawing
import androidx.compose.foundation.layout.systemBars
import androidx.compose.foundation.layout.windowInsetsBottomHeight
import androidx.compose.foundation.layout.windowInsetsPadding
import androidx.compose.foundation.pager.HorizontalPager
import androidx.compose.foundation.pager.rememberPagerState
Expand Down Expand Up @@ -584,14 +585,13 @@ private fun CrossSellBottomSheet(
isVisible = true,
onVisibleChange = { onDismissed() },
content = {
Column {
Spacer(Modifier.height(32.dp))
CrossSellsSection(
showNotificationBadge = false,
crossSells = crossSells,
onCrossSellClick = onCrossSellClick,
)
}
CrossSellsSection(
showNotificationBadge = false,
crossSells = crossSells,
onCrossSellClick = onCrossSellClick,
)
Spacer(Modifier.height(16.dp))
Spacer(Modifier.windowInsetsBottomHeight(WindowInsets.safeDrawing))
},
)
}
Expand Down
4 changes: 0 additions & 4 deletions app/feature/feature-insurances/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ android {
dependencies {
api(libs.coil.coil)

implementation(libs.androidx.compose.material3)
implementation(libs.androidx.lifecycle.compose)
implementation(libs.apollo.normalizedCache)
implementation(libs.apollo.testingSupport)
Expand All @@ -31,10 +30,7 @@ dependencies {
implementation(projects.coreCommonAndroidPublic)
implementation(projects.coreCommonPublic)
implementation(projects.coreDemoMode)
implementation(projects.coreDesignSystem)
implementation(projects.coreIcons)
implementation(projects.coreResources)
implementation(projects.coreUi)
implementation(projects.crossSells)
implementation(projects.dataContractAndroid)
implementation(projects.dataContractPublic)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@ import androidx.compose.foundation.layout.windowInsetsBottomHeight
import androidx.compose.foundation.layout.windowInsetsPadding
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.material3.CardDefaults
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.DisposableEffect
import androidx.compose.runtime.getValue
Expand All @@ -46,17 +42,15 @@ import androidx.lifecycle.compose.dropUnlessResumed
import coil.ImageLoader
import com.hedvig.android.compose.ui.preview.BooleanCollectionPreviewParameterProvider
import com.hedvig.android.compose.ui.preview.PreviewContentWithProvidedParametersAnimatedOnClick
import com.hedvig.android.core.designsystem.component.card.HedvigCard
import com.hedvig.android.core.designsystem.component.error.HedvigErrorSection
import com.hedvig.android.core.designsystem.component.information.HedvigInformationSection
import com.hedvig.android.core.designsystem.material3.squircleMedium
import com.hedvig.android.core.ui.preview.rememberPreviewImageLoader
import com.hedvig.android.crosssells.CrossSellItemPlaceholder
import com.hedvig.android.crosssells.CrossSellsSection
import com.hedvig.android.data.contract.ContractGroup
import com.hedvig.android.data.contract.ContractType
import com.hedvig.android.data.contract.android.CrossSell
import com.hedvig.android.data.productvariant.ProductVariant
import com.hedvig.android.design.system.hedvig.EmptyState
import com.hedvig.android.design.system.hedvig.HedvigCard
import com.hedvig.android.design.system.hedvig.HedvigErrorSection
import com.hedvig.android.design.system.hedvig.HedvigNotificationCard
import com.hedvig.android.design.system.hedvig.HedvigPreview
import com.hedvig.android.design.system.hedvig.HedvigText
Expand All @@ -65,6 +59,8 @@ import com.hedvig.android.design.system.hedvig.InsuranceCard
import com.hedvig.android.design.system.hedvig.InsuranceCardPlaceholder
import com.hedvig.android.design.system.hedvig.NotificationDefaults.InfoCardStyle
import com.hedvig.android.design.system.hedvig.NotificationDefaults.NotificationPriority
import com.hedvig.android.design.system.hedvig.Surface
import com.hedvig.android.design.system.hedvig.rememberPreviewImageLoader
import com.hedvig.android.feature.insurances.data.InsuranceAgreement
import com.hedvig.android.feature.insurances.data.InsuranceContract
import com.hedvig.android.feature.insurances.insurance.presentation.InsuranceScreenEvent
Expand Down Expand Up @@ -152,7 +148,7 @@ private fun InsuranceScreen(
.fillMaxWidth()
.padding(horizontal = 16.dp),
) {
Text(
HedvigText(
text = stringResource(id = R.string.DASHBOARD_SCREEN_TITLE),
style = HedvigTheme.typography.headlineSmall,
)
Expand Down Expand Up @@ -212,19 +208,15 @@ private fun InsuranceScreenContent(
modifier = modifier.padding(top = 16.dp),
verticalArrangement = Arrangement.spacedBy(24.dp),
) {
val insuranceCardModifier = Modifier
.padding(horizontal = 16.dp)
.clip(MaterialTheme.shapes.squircleMedium)
if (uiState.isLoading) {
InsuranceCardPlaceholder(
imageLoader = imageLoader,
modifier = insuranceCardModifier,
modifier = Modifier.padding(horizontal = 16.dp),
)
CrossSellItemPlaceholder()
CrossSellItemPlaceholder(Modifier.padding(horizontal = 16.dp))
} else {
ContractsSection(
imageLoader = imageLoader,
modifier = insuranceCardModifier,
onInsuranceCardClick = onInsuranceCardClick,
contracts = uiState.contracts,
)
Expand All @@ -239,6 +231,7 @@ private fun InsuranceScreenContent(
showNotificationBadge = showNotificationBadge,
crossSells = uiState.crossSells,
onCrossSellClick = onCrossSellClick,
modifier = Modifier.padding(horizontal = 16.dp),
)
}
if (quantityOfCancelledInsurances > 0) {
Expand All @@ -263,20 +256,21 @@ private fun ContractsSection(
onInsuranceCardClick: (contractId: String) -> Unit,
modifier: Modifier = Modifier,
) {
if (contracts.isEmpty()) {
HedvigInformationSection(
title = stringResource(id = R.string.INSURANCES_NO_ACTIVE),
withDefaultVerticalSpacing = true,
)
} else {
Column(verticalArrangement = Arrangement.spacedBy(8.dp)) {
for (contract in contracts) {
InsuranceCard(
contract = contract,
imageLoader = imageLoader,
modifier = modifier,
onInsuranceCardClick = onInsuranceCardClick,
)
Box(modifier) {
if (contracts.isEmpty()) {
EmptyState(
text = stringResource(id = R.string.INSURANCES_NO_ACTIVE),
description = null,
)
} else {
Column(verticalArrangement = Arrangement.spacedBy(8.dp)) {
for (contract in contracts) {
InsuranceCard(
contract = contract,
imageLoader = imageLoader,
onInsuranceCardClick = onInsuranceCardClick,
)
}
}
}
}
Expand All @@ -295,7 +289,8 @@ private fun InsuranceCard(
topText = contract.currentInsuranceAgreement.productVariant.displayName,
bottomText = contract.exposureDisplayName,
imageLoader = imageLoader,
modifier = modifier
modifier = modifier.padding(horizontal = 16.dp)
.clip(HedvigTheme.shapes.cornerXLarge)
.clickable {
onInsuranceCardClick(contract.id)
},
Expand All @@ -308,17 +303,9 @@ private fun InsuranceCard(
private fun TerminatedContractsButton(text: String, onClick: () -> Unit, modifier: Modifier = Modifier) {
HedvigCard(
onClick = onClick,
colors = CardDefaults.outlinedCardColors(),
modifier = modifier,
modifier = modifier.fillMaxWidth(),
) {
Row(
verticalAlignment = Alignment.CenterVertically,
modifier = Modifier
.padding(16.dp)
.fillMaxWidth(),
) {
Text(text)
}
HedvigText(text, Modifier.padding(16.dp))
}
}

Expand All @@ -345,8 +332,8 @@ private fun MovingFlowSuggestionSection(onNavigateToMovingFlow: () -> Unit, modi
private fun PreviewInsuranceScreen(
@PreviewParameter(BooleanCollectionPreviewParameterProvider::class) withContracts: Boolean,
) {
com.hedvig.android.core.designsystem.theme.HedvigTheme {
Surface {
HedvigTheme {
Surface(color = HedvigTheme.colorScheme.backgroundPrimary) {
InsuranceScreen(
InsuranceUiState(
contracts = if (withContracts) {
Expand Down Expand Up @@ -386,7 +373,7 @@ private fun PreviewInsuranceScreen(
private fun PreviewInsuranceDestinationAnimation() {
val values = InsuranceUiStateProvider().values.toList()
HedvigTheme {
Surface {
Surface(color = HedvigTheme.colorScheme.backgroundPrimary) {
PreviewContentWithProvidedParametersAnimatedOnClick(
parametersList = values,
content = { insuranceUiState ->
Expand Down
Loading

0 comments on commit 2b2023f

Please sign in to comment.