perf: reduce sensor rate and pause blob animation during chat
Sensor: SENSOR_DELAY_GAME → SENSOR_DELAY_UI (~15Hz instead of ~60Hz), parallax effect unchanged. Blob drift animation only runs on empty state, frozen at midpoint during chat (blobs still visible, no GPU animation cost).
This commit is contained in:
parent
f703196087
commit
313c21d47d
3 changed files with 18 additions and 13 deletions
|
|
@ -41,20 +41,25 @@ import dev.kaizen.app.ui.theme.rememberDitherBrush
|
||||||
|
|
||||||
/** Mesh/blob background: large, heavily blurred color circles that drift slowly. */
|
/** Mesh/blob background: large, heavily blurred color circles that drift slowly. */
|
||||||
@Composable
|
@Composable
|
||||||
fun MeshBackground(content: @Composable BoxScope.() -> Unit) {
|
fun MeshBackground(animateBlobs: Boolean = true, content: @Composable BoxScope.() -> Unit) {
|
||||||
val dark = isSystemInDarkTheme()
|
val dark = isSystemInDarkTheme()
|
||||||
val accent = LocalKaizenAccent.current
|
val accent = LocalKaizenAccent.current
|
||||||
val base = MaterialTheme.colorScheme.background
|
val base = MaterialTheme.colorScheme.background
|
||||||
// Blobs are subtler in light mode.
|
|
||||||
val factor = if (dark) 1f else 0.65f
|
val factor = if (dark) 1f else 0.65f
|
||||||
|
|
||||||
|
val drift = if (animateBlobs) {
|
||||||
val transition = rememberInfiniteTransition(label = "blobs")
|
val transition = rememberInfiniteTransition(label = "blobs")
|
||||||
val drift by transition.animateFloat(
|
val d by transition.animateFloat(
|
||||||
initialValue = 0f,
|
initialValue = 0f,
|
||||||
targetValue = 1f,
|
targetValue = 1f,
|
||||||
animationSpec = infiniteRepeatable(tween(22000, easing = LinearEasing), RepeatMode.Reverse),
|
animationSpec = infiniteRepeatable(tween(22000, easing = LinearEasing), RepeatMode.Reverse),
|
||||||
label = "drift",
|
label = "drift",
|
||||||
)
|
)
|
||||||
// Dither overlay (drawn last, over everything) — kills 8-bit gradient banding.
|
d
|
||||||
|
} else {
|
||||||
|
0.5f
|
||||||
|
}
|
||||||
|
|
||||||
val ditherBrush = rememberDitherBrush()
|
val ditherBrush = rememberDitherBrush()
|
||||||
Box(
|
Box(
|
||||||
Modifier
|
Modifier
|
||||||
|
|
|
||||||
|
|
@ -603,7 +603,7 @@ fun ChatScreen(
|
||||||
},
|
},
|
||||||
gesturesEnabled = true // Allows swiping from the screen's left edge to open the drawer
|
gesturesEnabled = true // Allows swiping from the screen's left edge to open the drawer
|
||||||
) {
|
) {
|
||||||
MeshBackground {
|
MeshBackground(animateBlobs = messages.isEmpty()) {
|
||||||
Box(Modifier.fillMaxSize(), contentAlignment = Alignment.Center) {
|
Box(Modifier.fillMaxSize(), contentAlignment = Alignment.Center) {
|
||||||
// 1. Scrollable Chat Content
|
// 1. Scrollable Chat Content
|
||||||
// Stretches to the full screen, allowing bubbles to scroll cleanly behind the floating bottom dock.
|
// Stretches to the full screen, allowing bubbles to scroll cleanly behind the floating bottom dock.
|
||||||
|
|
|
||||||
|
|
@ -115,7 +115,7 @@ fun rememberTiltState(): State<Offset> {
|
||||||
Lifecycle.Event.ON_START -> {
|
Lifecycle.Event.ON_START -> {
|
||||||
if (!registered) {
|
if (!registered) {
|
||||||
sensorManager.registerListener(
|
sensorManager.registerListener(
|
||||||
listener, sensor, SensorManager.SENSOR_DELAY_GAME
|
listener, sensor, SensorManager.SENSOR_DELAY_UI
|
||||||
)
|
)
|
||||||
registered = true
|
registered = true
|
||||||
}
|
}
|
||||||
|
|
@ -131,7 +131,7 @@ fun rememberTiltState(): State<Offset> {
|
||||||
|
|
||||||
lifecycle.addObserver(lifecycleObserver)
|
lifecycle.addObserver(lifecycleObserver)
|
||||||
if (lifecycle.currentState.isAtLeast(Lifecycle.State.STARTED)) {
|
if (lifecycle.currentState.isAtLeast(Lifecycle.State.STARTED)) {
|
||||||
sensorManager.registerListener(listener, sensor, SensorManager.SENSOR_DELAY_GAME)
|
sensorManager.registerListener(listener, sensor, SensorManager.SENSOR_DELAY_UI)
|
||||||
registered = true
|
registered = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue