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:
Bruno Deanoz 2026-06-22 19:01:25 +02:00
parent f703196087
commit 313c21d47d
3 changed files with 18 additions and 13 deletions

View file

@ -41,20 +41,25 @@ import dev.kaizen.app.ui.theme.rememberDitherBrush
/** Mesh/blob background: large, heavily blurred color circles that drift slowly. */
@Composable
fun MeshBackground(content: @Composable BoxScope.() -> Unit) {
fun MeshBackground(animateBlobs: Boolean = true, content: @Composable BoxScope.() -> Unit) {
val dark = isSystemInDarkTheme()
val accent = LocalKaizenAccent.current
val base = MaterialTheme.colorScheme.background
// Blobs are subtler in light mode.
val factor = if (dark) 1f else 0.65f
val transition = rememberInfiniteTransition(label = "blobs")
val drift by transition.animateFloat(
initialValue = 0f,
targetValue = 1f,
animationSpec = infiniteRepeatable(tween(22000, easing = LinearEasing), RepeatMode.Reverse),
label = "drift",
)
// Dither overlay (drawn last, over everything) — kills 8-bit gradient banding.
val drift = if (animateBlobs) {
val transition = rememberInfiniteTransition(label = "blobs")
val d by transition.animateFloat(
initialValue = 0f,
targetValue = 1f,
animationSpec = infiniteRepeatable(tween(22000, easing = LinearEasing), RepeatMode.Reverse),
label = "drift",
)
d
} else {
0.5f
}
val ditherBrush = rememberDitherBrush()
Box(
Modifier

View file

@ -603,7 +603,7 @@ fun ChatScreen(
},
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) {
// 1. Scrollable Chat Content
// Stretches to the full screen, allowing bubbles to scroll cleanly behind the floating bottom dock.

View file

@ -115,7 +115,7 @@ fun rememberTiltState(): State<Offset> {
Lifecycle.Event.ON_START -> {
if (!registered) {
sensorManager.registerListener(
listener, sensor, SensorManager.SENSOR_DELAY_GAME
listener, sensor, SensorManager.SENSOR_DELAY_UI
)
registered = true
}
@ -131,7 +131,7 @@ fun rememberTiltState(): State<Offset> {
lifecycle.addObserver(lifecycleObserver)
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
}