Skip to content

Commit

Permalink
Adjust insets easing
Browse files Browse the repository at this point in the history
  • Loading branch information
alexvanyo committed Sep 28, 2023
1 parent 120dff3 commit 47d9a62
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

package com.alexvanyo.composelife.ui.app.action

import androidx.compose.animation.core.EaseInOut
import androidx.compose.animation.core.Easing
import androidx.compose.animation.core.Spring
import androidx.compose.animation.core.animateDpAsState
import androidx.compose.animation.core.animateFloatAsState
Expand Down Expand Up @@ -44,6 +46,7 @@ import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.layout.layoutId
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.unit.dp
Expand All @@ -58,6 +61,7 @@ import com.alexvanyo.composelife.ui.app.action.settings.InlineSettingsScreen
import com.alexvanyo.composelife.ui.app.action.settings.InlineSettingsScreenInjectEntryPoint
import com.alexvanyo.composelife.ui.app.action.settings.InlineSettingsScreenLocalEntryPoint
import com.alexvanyo.composelife.ui.util.AnimatedContent
import com.alexvanyo.composelife.ui.util.Easing
import com.alexvanyo.composelife.ui.util.Layout
import com.alexvanyo.composelife.ui.util.PredictiveNavigationHost
import com.alexvanyo.composelife.ui.util.WindowInsets
Expand Down Expand Up @@ -141,7 +145,7 @@ fun CellUniverseActionCard(
val targetWindowInsets = lerp(
WindowInsets.safeDrawing.add(WindowInsets(all = 8.dp)),
WindowInsets.Zero,
targetWindowInsetsProgressToFullscreen,
Easing(EaseInOut, 0.5f to Easing { 1f }).transform(targetWindowInsetsProgressToFullscreen),
)

val cornerSize by animateDpAsState(
Expand Down Expand Up @@ -192,6 +196,7 @@ fun CellUniverseActionCard(
Surface(
shape = RoundedCornerShape(cornerSize),
tonalElevation = 1.dp,
color = Color.Transparent,
modifier = Modifier.windowInsetsPadding(
WindowInsets.safeDrawing.add(WindowInsets(all = 8.dp)),
),
Expand Down Expand Up @@ -336,6 +341,7 @@ fun CellUniverseActionCard(
is ActionCardNavigation.FullscreenSettings -> {
Surface(
shape = RoundedCornerShape(cornerSize),
color = Color.Transparent,
tonalElevation = 1.dp,
) {
FullscreenSettingsScreen(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,10 @@ fun Easing(
val easingMap = TreeMap<Float, Easing>()
easingMap[0f] = easing
easingMap.putAll(easings)
require(easingMap.size == easings.size + 1)
return Easing {
val (piecewiseStart, piecewiseEasing) = easingMap.floorEntry(it)!!
val piecewiseEnd = easingMap.ceilingKey(it) ?: 1f
val piecewiseEnd = easingMap.higherKey(it) ?: 1f
piecewiseEasing.transform((it - piecewiseStart) / (piecewiseEnd - piecewiseStart))
}
}

0 comments on commit 47d9a62

Please sign in to comment.