Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GEN-2547: travel certificate #2315

Merged
merged 10 commits into from
Nov 21, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ import coil.ImageLoader
import com.benasher44.uuid.Uuid
import com.hedvig.android.app.ui.HedvigAppState
import com.hedvig.android.core.buildconstants.HedvigBuildConstants
import com.hedvig.android.core.designsystem.material3.motion.MotionDefaults
import com.hedvig.android.data.claimflow.ClaimFlowStep
import com.hedvig.android.data.claimflow.toClaimFlowDestination
import com.hedvig.android.design.system.hedvig.motion.MotionDefaults
import com.hedvig.android.feature.change.tier.navigation.ChooseTierGraphDestination
import com.hedvig.android.feature.change.tier.navigation.InsuranceCustomizationParameters
import com.hedvig.android.feature.change.tier.navigation.StartTierFlowChooseInsuranceDestination
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,8 @@ package com.hedvig.android.core.designsystem.material3.motion

import androidx.compose.animation.EnterTransition
import androidx.compose.animation.ExitTransition
import androidx.compose.ui.unit.Density
import androidx.compose.ui.unit.dp

object MotionDefaults {
fun sharedXAxisEnter(density: Density): EnterTransition {
val offsetPixels = with(density) { SharedAxisDefaults.SharedAxisOffset.dp.roundToPx() }
return SharedAxisDefaults.sharedXAxisEnterTransition(offsetPixels)
}

fun sharedXAxisExit(density: Density): ExitTransition {
val offsetPixels = with(density) { SharedAxisDefaults.SharedAxisOffset.dp.roundToPx() }
return SharedAxisDefaults.sharedXAxisExitTransition(-offsetPixels)
}

fun sharedXAxisPopEnter(density: Density): EnterTransition {
val offsetPixels = with(density) { SharedAxisDefaults.SharedAxisOffset.dp.roundToPx() }
return SharedAxisDefaults.sharedXAxisEnterTransition(-offsetPixels)
}

fun sharedXAxisPopExit(density: Density): ExitTransition {
val offsetPixels = with(density) { SharedAxisDefaults.SharedAxisOffset.dp.roundToPx() }
return SharedAxisDefaults.sharedXAxisExitTransition(offsetPixels)
}

val fadeThroughEnter: EnterTransition = FadeThroughDefaults.fadeThroughEnterTransition

val fadeThroughExit: ExitTransition = FadeThroughDefaults.fadeThroughExitTransition
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ package com.hedvig.android.core.designsystem.material3.motion

import androidx.compose.animation.core.CubicBezierEasing

const val DurationExtraLong1 = 700.0

// https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:compose/material3/material3/src/commonMain/kotlin/androidx/compose/material3/tokens/MotionTokens.kt
@Suppress("unused")
object MotionTokens {
const val DurationExtraLong1 = 700.0
const val DurationExtraLong2 = 800.0
const val DurationExtraLong3 = 900.0
const val DurationExtraLong4 = 1000.0
Expand Down

This file was deleted.

9 changes: 9 additions & 0 deletions app/design-system/design-system-api/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
plugins {
id("hedvig.gradle.plugin")
id("hedvig.kotlin.library")
}

dependencies {
implementation(platform(libs.androidx.compose.bom))
implementation(libs.androidx.compose.runtime)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package com.hedvig.android.design.system.hedvig.api

import androidx.compose.runtime.Immutable
import androidx.compose.runtime.Stable

@Stable
interface HedvigDatePickerState {
var selectedDateMillis: Long?
var displayedMonthMillis: Long
var displayMode: HedvigDisplayMode
val yearRange: IntRange
val selectableDates: HedvigSelectableDates
}

@Stable
interface HedvigSelectableDates {
fun isSelectableDate(utcTimeMillis: Long) = true

fun isSelectableYear(year: Int) = true
}

@Immutable
@JvmInline
value class HedvigDisplayMode internal constructor(internal val value: Int) {
companion object {
/** Date picker mode */
val Picker = HedvigDisplayMode(0)

/** Date text input mode */
val Input = HedvigDisplayMode(1)
}

override fun toString() = when (this) {
Picker -> "Picker"
Input -> "Input"
else -> "Unknown"
}
}

object HedvigDatePickerDefaults {
val displayMode = HedvigDisplayMode.Picker
val YearRange: IntRange = IntRange(1900, 2100)
val AllDates: HedvigSelectableDates = object : HedvigSelectableDates {}
}
1 change: 1 addition & 0 deletions app/design-system/design-system-hedvig/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ hedvig {
dependencies {
api(libs.androidx.compose.foundation)
api(libs.coil.coil)
api(projects.designSystemApi)

implementation(libs.androidx.activity.compose)
implementation(libs.androidx.compose.foundationLayout)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ fun EmptyState(
}
}

@Suppress("UnusedReceiverParameter")
@Composable
private fun ColumnScope.EmptyStateIcon(iconStyle: EmptyStateIconStyle) {
val sizeModifier = Modifier.size(EmptyStateTokens.IconSize)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,58 @@ import androidx.compose.ui.res.stringResource
import com.hedvig.android.design.system.hedvig.ButtonDefaults.ButtonSize.Medium
import com.hedvig.android.design.system.hedvig.HedvigTextButton
import com.hedvig.android.design.system.hedvig.HedvigTheme
import com.hedvig.android.design.system.hedvig.api.HedvigDatePickerDefaults
import com.hedvig.android.design.system.hedvig.api.HedvigDatePickerState
import com.hedvig.android.design.system.hedvig.api.HedvigDisplayMode
import com.hedvig.android.design.system.hedvig.api.HedvigSelectableDates
import com.hedvig.android.design.system.hedvig.fromToken
import com.hedvig.android.design.system.hedvig.tokens.ColorSchemeKeyTokens
import com.hedvig.android.design.system.hedvig.tokens.ColorSchemeKeyTokens.TextNegative
import com.hedvig.android.design.system.hedvig.tokens.ColorSchemeKeyTokens.TextPrimary
import com.hedvig.android.design.system.hedvig.tokens.ColorSchemeKeyTokens.TextTertiary
import com.hedvig.android.design.system.internals.HedvigDatePicker
import com.hedvig.android.design.system.internals.HedvigDatePickerColors
import com.hedvig.android.design.system.internals.HedvigDatePickerInternal
import hedvig.resources.R
import java.util.Locale

data class HedvigDatePickerState(
var selectedDateMillis: Long?,
var displayedMonthMillis: Long?,
@Composable
fun rememberHedvigDatePickerState(
initialSelectedDateMillis: Long,
initialDisplayedMonthMillis: Long,
yearRange: IntRange,
initialDisplayMode: HedvigDisplayMode,
selectableDates: HedvigSelectableDates,
): HedvigDatePickerState {
return com.hedvig.android.design.system.internals.rememberHedvigDatePickerState(
initialSelectedDateMillis,
initialDisplayedMonthMillis,
yearRange,
initialDisplayMode,
selectableDates,
)
}

fun HedvigDatePickerState(
locale: Locale,
initialSelectedDateMillis: Long?,
initialDisplayedMonthMillis: Long?,
yearRange: IntRange = HedvigDatePickerDefaults.YearRange,
initialDisplayMode: HedvigDisplayMode = HedvigDatePickerDefaults.displayMode,
selectableDates: HedvigSelectableDates = HedvigDatePickerDefaults.AllDates,
): HedvigDatePickerState {
return com.hedvig.android.design.system.internals.HedvigDatePickerState(
locale,
initialSelectedDateMillis,
initialDisplayedMonthMillis,
yearRange,
initialDisplayMode,
selectableDates,
)
}

data class HedvigDatePickerImmutableState(
val selectedDateMillis: Long?,
val displayedMonthMillis: Long?,
val yearRange: IntRange,
val minDateInMillis: Long,
val maxDateInMillis: Long,
Expand All @@ -33,12 +72,39 @@ fun HedvigDatePicker(
datePickerState: HedvigDatePickerState,
onDismissRequest: () -> Unit,
onConfirmRequest: () -> Unit,
) {
HedvigDatePicker(
state = datePickerState,
onDismissRequest = onDismissRequest,
hedvigDatePickerColors = hedvigDatePickerColors,
modifier = Modifier.background(
hedvigDatePickerColors.containerColor,
),
confirmButton = {
HedvigTextButton(
text = stringResource(R.string.general_done_button),
onClick = onConfirmRequest,
buttonSize = Medium,
)
},
)
}

/**
* A version of [HedvigDatePicker] which does not offer internal mutability in the [datePickerState] parameter. Instead
* it takes in an immutable data class and it must be re-created again every time something changes
*/
@Composable
fun HedvigDatePicker(
datePickerState: HedvigDatePickerImmutableState,
onDismissRequest: () -> Unit,
onConfirmRequest: () -> Unit,
onSelectedDateChanged: (Long?) -> Unit,
isVisible: Boolean,
) {
if (isVisible) {
with(datePickerState) {
HedvigDatePickerInternal(
HedvigDatePicker(
selectedDateMillis = selectedDateMillis,
displayedMonthMillis = displayedMonthMillis,
yearRange = yearRange,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.hedvig.android.design.system.hedvig
package com.hedvig.android.design.system.hedvig.motion

import androidx.compose.animation.EnterTransition
import androidx.compose.animation.ExitTransition
Expand All @@ -7,36 +7,30 @@ import androidx.compose.animation.fadeIn
import androidx.compose.animation.fadeOut
import com.hedvig.android.design.system.hedvig.tokens.MotionTokens

object MotionDefaults {
val fadeThroughEnter: EnterTransition = FadeThroughDefaults.fadeThroughEnterTransition

val fadeThroughExit: ExitTransition = FadeThroughDefaults.fadeThroughExitTransition
}

private const val ProgressThreshold = 0.35f

private val Int.ForOutgoing: Int
get() = (this * ProgressThreshold).toInt()

private val Int.ForIncoming: Int
get() = this - this.ForOutgoing

object FadeThroughDefaults {
internal object FadeThroughDefaults {
private const val FadeThroughDuration = MotionTokens.DurationMedium1.toInt()

internal val fadeThroughEnterTransition: EnterTransition = fadeIn(
val fadeThroughEnterTransition: EnterTransition = fadeIn(
animationSpec = tween(
durationMillis = FadeThroughDuration.ForIncoming,
delayMillis = FadeThroughDuration.ForOutgoing,
easing = MotionTokens.EasingStandardCubicBezier,
),
)

internal val fadeThroughExitTransition: ExitTransition = fadeOut(
val fadeThroughExitTransition: ExitTransition = fadeOut(
animationSpec = tween(
durationMillis = FadeThroughDuration.ForOutgoing,
delayMillis = 0,
easing = MotionTokens.EasingStandardAccelerateCubicBezier,
),
)
}

private const val ProgressThreshold = 0.35f

private val Int.ForOutgoing: Int
get() = (this * ProgressThreshold).toInt()

private val Int.ForIncoming: Int
get() = this - this.ForOutgoing
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.hedvig.android.design.system.hedvig.motion

import androidx.compose.animation.EnterTransition
import androidx.compose.animation.ExitTransition
import androidx.compose.ui.unit.Density
import androidx.compose.ui.unit.dp

object MotionDefaults {
fun sharedXAxisEnter(density: Density): EnterTransition {
val offsetPixels = with(density) { SharedAxisDefaults.SharedAxisOffset.dp.roundToPx() }
return SharedAxisDefaults.sharedXAxisEnterTransition(offsetPixels)
}

fun sharedXAxisExit(density: Density): ExitTransition {
val offsetPixels = with(density) { SharedAxisDefaults.SharedAxisOffset.dp.roundToPx() }
return SharedAxisDefaults.sharedXAxisExitTransition(-offsetPixels)
}

fun sharedXAxisPopEnter(density: Density): EnterTransition {
val offsetPixels = with(density) { SharedAxisDefaults.SharedAxisOffset.dp.roundToPx() }
return SharedAxisDefaults.sharedXAxisEnterTransition(-offsetPixels)
}

fun sharedXAxisPopExit(density: Density): ExitTransition {
val offsetPixels = with(density) { SharedAxisDefaults.SharedAxisOffset.dp.roundToPx() }
return SharedAxisDefaults.sharedXAxisExitTransition(offsetPixels)
}

val fadeThroughEnter: EnterTransition = FadeThroughDefaults.fadeThroughEnterTransition

val fadeThroughExit: ExitTransition = FadeThroughDefaults.fadeThroughExitTransition
}
Loading
Loading