Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 5bba45d5 authored by Kelly's avatar Kelly
Browse files

Enable highlight animations. The highlight color will pop up 3 times and

stop.

Test: manually test on device
Bug: 253536111
Change-Id: I5c467ebc424ef348f5de1fb18cadc27dfe050f2a
parent 16bec9b2
Loading
Loading
Loading
Loading
+25 −4
Original line number Diff line number Diff line
@@ -16,21 +16,42 @@

package com.android.settingslib.spa.widget.util

import androidx.compose.animation.animateColorAsState
import androidx.compose.animation.core.RepeatMode
import androidx.compose.animation.core.repeatable
import androidx.compose.animation.core.tween
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.material3.MaterialTheme
import androidx.compose.runtime.Composable
import androidx.compose.runtime.SideEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import com.android.settingslib.spa.framework.common.LocalEntryDataProvider
import com.android.settingslib.spa.framework.theme.SettingsTheme

@Composable
internal fun EntryHighlight(UiLayoutFn: @Composable () -> Unit) {
    val entryData = LocalEntryDataProvider.current
    val isHighlighted = rememberSaveable { entryData.isHighlighted }
    val backgroundColor =
        if (isHighlighted) MaterialTheme.colorScheme.surfaceVariant else Color.Transparent
    var isHighlighted by rememberSaveable { mutableStateOf(false) }
    SideEffect {
        isHighlighted = entryData.isHighlighted
    }

    val backgroundColor by animateColorAsState(
        targetValue = when {
            isHighlighted -> MaterialTheme.colorScheme.surfaceVariant
            else -> SettingsTheme.colorScheme.background
        },
        animationSpec = repeatable(
            iterations = 3,
            animation = tween(durationMillis = 500),
            repeatMode = RepeatMode.Restart
        )
    )
    Box(modifier = Modifier.background(color = backgroundColor)) {
        UiLayoutFn()
    }