diff --git a/app/design-system/design-system-hedvig/src/main/kotlin/com/hedvig/android/design/system/hedvig/Toggle.kt b/app/design-system/design-system-hedvig/src/main/kotlin/com/hedvig/android/design/system/hedvig/Toggle.kt index 5225e98d1d..069220b0a8 100644 --- a/app/design-system/design-system-hedvig/src/main/kotlin/com/hedvig/android/design/system/hedvig/Toggle.kt +++ b/app/design-system/design-system-hedvig/src/main/kotlin/com/hedvig/android/design/system/hedvig/Toggle.kt @@ -64,6 +64,7 @@ import com.hedvig.android.design.system.hedvig.tokens.SmallSizeDefaultToggleToke import com.hedvig.android.design.system.hedvig.tokens.SmallSizeDetailedToggleTokens import com.hedvig.android.design.system.hedvig.tokens.ToggleColorTokens import com.hedvig.android.design.system.hedvig.tokens.ToggleIconSizeTokens +import com.hedvig.android.logger.logcat import kotlin.math.roundToInt import kotlinx.coroutines.delay import kotlinx.coroutines.flow.collectLatest @@ -258,19 +259,19 @@ private fun Toggle( Box { ToggleBackground( modifier = - modifier - .height(toggleIconSize.height) - .width(toggleIconSize.width) - .fillMaxSize() - .onSizeChanged { layoutSize -> - val dragEndPoint = layoutSize.width - contentSizePx - state.updateAnchors( - DraggableAnchors { - false at 0f - true at dragEndPoint - }, - ) - }, + modifier + .height(toggleIconSize.height) + .width(toggleIconSize.width) + .fillMaxSize() + .onSizeChanged { layoutSize -> + val dragEndPoint = layoutSize.width - contentSizePx + state.updateAnchors( + DraggableAnchors { + false at 0f + true at dragEndPoint + }, + ) + }, color = backgroundColor.value, interactionSource = interactionSource, contentSize = contentSize, @@ -307,7 +308,8 @@ private fun ToggleBackground( .offset { IntOffset( x = draggableState - .requireOffset() + .offset + .let { if (it.isNaN()) 0f else it } .roundToInt(), y = 0, )