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 04d907b commit 3cab353
Showing 1 changed file with 8 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,21 +44,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 == SwipeToDismissBoxValue.EndToStart) onSwiped()
Expand All @@ -72,11 +71,11 @@ fun SwipeToDismissComponent(
label = "Background color animation",
)
val iconScale by animateFloatAsState(
targetValue = if (state.targetValue == SwipeToDismissBoxValue.EndToStart) maxIconScale else minIconScale,
targetValue = if (state.targetValue == SwipeToDismissBoxValue.EndToStart) MAX_ICON_SCALE else MIN_ICON_SCALE,
label = "Icon scale animation",
)
val contentElevation by animateDpAsState(
targetValue = if (state.dismissDirection == SwipeToDismissBoxValue.EndToStart) swipedElevation else 0.dp,
targetValue = if (state.dismissDirection == SwipeToDismissBoxValue.EndToStart) SWIPED_ELEVATION.dp else 0.dp,
label = "Content elevation animation",
)

Expand Down

0 comments on commit 3cab353

Please sign in to comment.