mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-18 12:28:40 +00:00
fix(ui): restore continuous ambient motion (#1592)
This commit is contained in:
1 parent
3fd6b1f00d
commit
fbb334263c
5 files changed
+29
-81
No files matched your search
@@ -1301,23 +1301,6 @@ class FrontEndActivity : ComponentActivity() {
|
||||
}
|
||||
}
|
||||
|
||||
override fun onUserInteraction() {
|
||||
super.onUserInteraction()
|
||||
com.droiddeck.launcher.ui.Ambient.poke()
|
||||
}
|
||||
|
||||
override fun dispatchTouchEvent(event: android.view.MotionEvent): Boolean {
|
||||
if (event.actionMasked == android.view.MotionEvent.ACTION_UP || event.actionMasked == android.view.MotionEvent.ACTION_CANCEL) {
|
||||
com.droiddeck.launcher.ui.Ambient.poke()
|
||||
}
|
||||
return super.dispatchTouchEvent(event)
|
||||
}
|
||||
|
||||
override fun dispatchGenericMotionEvent(event: android.view.MotionEvent): Boolean {
|
||||
com.droiddeck.launcher.ui.Ambient.poke()
|
||||
return super.dispatchGenericMotionEvent(event)
|
||||
}
|
||||
|
||||
override fun dispatchKeyEvent(event: KeyEvent): Boolean {
|
||||
if (event.keyCode == KeyEvent.KEYCODE_BUTTON_A) com.droiddeck.launcher.ui.HeldKeys.confirm = event.action == KeyEvent.ACTION_DOWN
|
||||
if (showComponents && (event.keyCode == KeyEvent.KEYCODE_BUTTON_L1 || event.keyCode == KeyEvent.KEYCODE_BUTTON_R1)) {
|
||||
@@ -1344,7 +1327,6 @@ class FrontEndActivity : ComponentActivity() {
|
||||
com.droiddeck.launcher.stores.StoresState.libraryListener = { refreshAddedGames(); refresh() }
|
||||
com.droiddeck.launcher.stores.battlenet.BattleNetClient.opener = { args -> openBattleNet(args) }
|
||||
com.droiddeck.launcher.ui.Motion.refresh(this)
|
||||
com.droiddeck.launcher.ui.Ambient.poke()
|
||||
com.droiddeck.launcher.ui.QuitFlood.take()?.let { c ->
|
||||
returning = ReturningFlood(c, com.droiddeck.launcher.ui.LaunchOrigin.takeReturn())
|
||||
}
|
||||
|
||||
@@ -265,12 +265,6 @@ internal object Motion {
|
||||
if (scale == 0f) snap() else spring(damping, stiffness)
|
||||
}
|
||||
|
||||
internal object Ambient {
|
||||
var poked by mutableStateOf(0L)
|
||||
private set
|
||||
fun poke() { poked = android.os.SystemClock.uptimeMillis() }
|
||||
}
|
||||
|
||||
private val Shape10 = RoundedCornerShape(10.dp)
|
||||
|
||||
internal val Shape12 = RoundedCornerShape(12.dp)
|
||||
|
||||
@@ -641,7 +641,11 @@ internal fun LiftHero(
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun handleBob(): Float {
|
||||
internal fun Handle(height: Dp, above: Boolean = false) {
|
||||
val colors = MaterialTheme.colorScheme
|
||||
val pal = LocalPalette.current
|
||||
val shape = if (above) RoundedCornerShape(topStart = 12.dp, topEnd = 12.dp) else RoundedCornerShape(bottomStart = 12.dp, bottomEnd = 12.dp)
|
||||
val still = Motion.scale == 0f
|
||||
val bob = androidx.compose.animation.core.rememberInfiniteTransition(label = "handle")
|
||||
val lift by bob.animateFloat(
|
||||
0f, 0f,
|
||||
@@ -656,16 +660,6 @@ private fun handleBob(): Float {
|
||||
),
|
||||
label = "handleBob",
|
||||
)
|
||||
return lift
|
||||
}
|
||||
|
||||
@Composable
|
||||
internal fun Handle(height: Dp, above: Boolean = false) {
|
||||
val colors = MaterialTheme.colorScheme
|
||||
val pal = LocalPalette.current
|
||||
val shape = if (above) RoundedCornerShape(topStart = 12.dp, topEnd = 12.dp) else RoundedCornerShape(bottomStart = 12.dp, bottomEnd = 12.dp)
|
||||
val still = Motion.scale == 0f || !ambientAwake()
|
||||
val lift = if (still) 0f else handleBob()
|
||||
Row(
|
||||
verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(4.dp),
|
||||
modifier = Modifier.height(height).clip(shape).background(colors.surface)
|
||||
|
||||
@@ -222,7 +222,7 @@ fun LoadingOverlay(
|
||||
.background(colors.background)
|
||||
.blockTouches(),
|
||||
) {
|
||||
CapsuleWall(games, driftMs = 65_000, modifier = Modifier.alpha(0.3f), pauseWhenIdle = false)
|
||||
CapsuleWall(games, driftMs = 65_000, modifier = Modifier.alpha(0.3f))
|
||||
Box(
|
||||
Modifier.fillMaxSize().drawBehind {
|
||||
drawRect(
|
||||
|
||||
@@ -5,6 +5,12 @@ import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import com.droiddeck.launcher.R
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.animation.core.FastOutSlowInEasing
|
||||
import androidx.compose.animation.core.RepeatMode
|
||||
import androidx.compose.runtime.State
|
||||
import androidx.compose.animation.core.animateFloat
|
||||
import androidx.compose.animation.core.infiniteRepeatable
|
||||
import androidx.compose.animation.core.rememberInfiniteTransition
|
||||
import androidx.compose.animation.core.tween
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Box
|
||||
@@ -70,38 +76,6 @@ private const val WALL_MIN_GAMES = 4
|
||||
private const val WALL_DISTINCT = 40
|
||||
|
||||
private const val DRIFT_STEP_NS = 15_000_000L
|
||||
private const val AMBIENT_IDLE_NS = 20_000_000_000L
|
||||
|
||||
@Composable
|
||||
internal fun ambientAwake(): Boolean {
|
||||
val poked = Ambient.poked
|
||||
var awake by remember { mutableStateOf(true) }
|
||||
LaunchedEffect(poked) {
|
||||
awake = true
|
||||
kotlinx.coroutines.delay(AMBIENT_IDLE_NS / 1_000_000)
|
||||
awake = false
|
||||
}
|
||||
return awake
|
||||
}
|
||||
|
||||
@Composable
|
||||
internal fun AmbientFrames(pauseWhenIdle: Boolean = true, step: (Long) -> Unit) {
|
||||
val onStep = androidx.compose.runtime.rememberUpdatedState(step)
|
||||
val poked = if (pauseWhenIdle) Ambient.poked else 0L
|
||||
if (Motion.scale != 0f) LaunchedEffect(poked, pauseWhenIdle) {
|
||||
var shown = 0L
|
||||
var end = Long.MAX_VALUE
|
||||
while (shown < end) withFrameNanos { now ->
|
||||
if (shown == 0L) {
|
||||
shown = now
|
||||
if (pauseWhenIdle) end = now + AMBIENT_IDLE_NS
|
||||
} else if (now - shown >= DRIFT_STEP_NS) {
|
||||
onStep.value(now - shown)
|
||||
shown = now
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
internal fun SteamHome(s: FrontEndState, a: FrontEndActions, modifier: Modifier) {
|
||||
@@ -205,7 +179,6 @@ internal fun CapsuleWall(
|
||||
modifier: Modifier = Modifier,
|
||||
owned: List<Pair<Int, java.io.File>> = emptyList(),
|
||||
featured: List<com.droiddeck.launcher.frontend.SteamFeatured.Game> = emptyList(),
|
||||
pauseWhenIdle: Boolean = true,
|
||||
) {
|
||||
val pal = LocalPalette.current
|
||||
val blank = remember(pal) { WallCapsule(Brush.linearGradient(listOf(pal.surface, pal.background)), edge = pal.line) }
|
||||
@@ -215,7 +188,7 @@ internal fun CapsuleWall(
|
||||
val store = if (owned.isEmpty()) featured.filter { shown.add(it.appId) }.map { it.name to it.art } else emptyList()
|
||||
(library + store).take((WALL_DISTINCT - games.size).coerceAtLeast(0))
|
||||
}
|
||||
TiltedWall(games.size + padding.size, driftMs, modifier, pauseWhenIdle = pauseWhenIdle) { i ->
|
||||
TiltedWall(games.size + padding.size, driftMs, modifier) { i ->
|
||||
when {
|
||||
i < games.size -> WallCapsule(artBrush(hueOf(games[i].name)), games[i].art)
|
||||
i - games.size < padding.size -> padding[i - games.size].let { (seed, art) -> WallCapsule(artBrush(hueOf(seed)), art) }
|
||||
@@ -235,13 +208,20 @@ internal fun TiltedWall(
|
||||
capH: androidx.compose.ui.unit.Dp = 168.dp,
|
||||
gap: androidx.compose.ui.unit.Dp = 14.dp,
|
||||
corner: androidx.compose.ui.unit.Dp = 10.dp,
|
||||
pauseWhenIdle: Boolean = true,
|
||||
capsule: (index: Int) -> WallCapsule,
|
||||
) {
|
||||
val still = Motion.scale == 0f
|
||||
val drift = remember { mutableFloatStateOf(0f) }
|
||||
AmbientFrames(pauseWhenIdle) { dt ->
|
||||
drift.floatValue = ((drift.floatValue + dt / (driftMs * 1_000_000.0 * Motion.scale)) % 1.0).toFloat()
|
||||
val period = androidx.compose.runtime.rememberUpdatedState(driftMs)
|
||||
if (!still) LaunchedEffect(Unit) {
|
||||
var shown = 0L
|
||||
while (true) withFrameNanos { now ->
|
||||
if (shown == 0L) shown = now
|
||||
else if (now - shown >= DRIFT_STEP_NS) {
|
||||
drift.floatValue = ((drift.floatValue + (now - shown) / (period.value * 1_000_000.0 * Motion.scale)) % 1.0).toFloat()
|
||||
shown = now
|
||||
}
|
||||
}
|
||||
}
|
||||
val density = LocalDensity.current
|
||||
BoxWithConstraints(modifier.fillMaxSize()) {
|
||||
@@ -327,9 +307,10 @@ private fun DrawScope.drawCapsule(look: WallCapsule, art: Painter?, radius: Floa
|
||||
private fun CapsuleFan(games: List<Library.SteamGame>) {
|
||||
val pal = LocalPalette.current
|
||||
val density = LocalDensity.current
|
||||
val clock = remember { androidx.compose.runtime.mutableLongStateOf(0L) }
|
||||
AmbientFrames { clock.longValue += it }
|
||||
val floatMs = listOf(9_000, 11_000, 13_000)
|
||||
val transition = rememberInfiniteTransition(label = "fan")
|
||||
val floats = listOf(9_000, 11_000, 13_000).map { ms ->
|
||||
transition.animateFloat(0f, 1f, infiniteRepeatable(tween(ms, easing = FastOutSlowInEasing), RepeatMode.Reverse), label = "float")
|
||||
}
|
||||
val still = Motion.scale == 0f
|
||||
val slots = listOf(
|
||||
FanSlot(0.54f, 0.14f, 0.62f, -9f),
|
||||
@@ -350,7 +331,7 @@ private fun CapsuleFan(games: List<Library.SteamGame>) {
|
||||
for (i in games.indices.reversed()) {
|
||||
val slot = slots[i]
|
||||
val h = maxHeight * slot.height
|
||||
val ms = floatMs[i]
|
||||
val v: State<Float> = floats[i]
|
||||
val look = WallCapsule(artBrush(hueOf(games[i].name)), games[i].art)
|
||||
val art = look.art?.let { rememberCapsuleArt(it, with(density) { Size((h * 2f / 3f).toPx(), h.toPx()) }, radius) }
|
||||
Spacer(
|
||||
@@ -358,10 +339,7 @@ private fun CapsuleFan(games: List<Library.SteamGame>) {
|
||||
.offset(x = maxWidth * slot.x, y = maxHeight * slot.y)
|
||||
.size(h * 2f / 3f, h)
|
||||
.graphicsLayer {
|
||||
val t = if (still) 0f else {
|
||||
val phase = (clock.longValue / (ms * 1_000_000.0 * Motion.scale)) % 2.0
|
||||
FastOutSlowInEasing.transform((if (phase < 1.0) phase else 2.0 - phase).toFloat())
|
||||
}
|
||||
val t = if (still) 0f else v.value
|
||||
rotationZ = slot.lean + 2f * t
|
||||
translationY = -12.dp.toPx() * t
|
||||
shadowElevation = 24.dp.toPx()
|
||||
|
||||
Reference in new issue
Block a user