Skip to content

Commit

Permalink
refactor: Move configuration values to constants
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinBoulongne committed Nov 28, 2024
1 parent 3133f12 commit f2eb596
Showing 1 changed file with 8 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,21 +48,20 @@ import com.infomaniak.swisstransfer.ui.theme.Margin
import com.infomaniak.swisstransfer.ui.theme.SwissTransferTheme
import com.infomaniak.swisstransfer.ui.utils.PreviewLightAndDark

private const val DISMISS_THRESHOLD = 0.5f
private const val MIN_ICON_SCALE = 1.0f
private const val MAX_ICON_SCALE = 1.5f
private const val SWIPED_ELEVATION = 4

@Composable
fun SwipeToDismissComponent(
contentShape: Shape,
onSwiped: () -> Unit = {},
content: @Composable () -> Unit,
) {

// Configuration
val dismissThreshold = 0.5f
val minIconScale = 1.0f
val maxIconScale = 1.5f
val swipedElevation = 4.dp

val state = rememberSwipeToDismissBoxState(
positionalThreshold = { totalDistance -> totalDistance * dismissThreshold },
positionalThreshold = { totalDistance -> totalDistance * DISMISS_THRESHOLD },
)

if (state.currentValue == EndToStart) onSwiped()
Expand All @@ -76,11 +75,11 @@ fun SwipeToDismissComponent(
label = "Background color animation",
)
val iconScale by animateFloatAsState(
targetValue = if (state.targetValue == EndToStart) maxIconScale else minIconScale,
targetValue = if (state.targetValue == EndToStart) MAX_ICON_SCALE else MIN_ICON_SCALE,
label = "Icon scale animation",
)
val contentElevation by animateDpAsState(
targetValue = if (state.dismissDirection == EndToStart) swipedElevation else 0.dp,
targetValue = if (state.dismissDirection == EndToStart) SWIPED_ELEVATION.dp else 0.dp,
label = "Content elevation animation",
)

Expand Down

0 comments on commit f2eb596

Please sign in to comment.