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

Commit 27c8aa6b authored by Kelly Zhang's avatar Kelly Zhang Committed by Android (Google) Code Review
Browse files

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

parents 49b93b3d 5bba45d5
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()
    }