Loading packages/SystemUI/compose/features/src/com/android/systemui/bouncer/ui/composable/PinBouncer.kt +29 −40 Original line number Diff line number Diff line Loading @@ -24,30 +24,31 @@ import androidx.compose.animation.core.AnimationVector1D import androidx.compose.animation.core.animateDpAsState import androidx.compose.animation.core.animateFloatAsState import androidx.compose.animation.core.tween import androidx.compose.foundation.LocalIndication import androidx.compose.foundation.combinedClickable import androidx.compose.foundation.focusable import androidx.compose.foundation.gestures.detectTapGestures import androidx.compose.foundation.interaction.MutableInteractionSource import androidx.compose.foundation.interaction.collectIsPressedAsState import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.aspectRatio import androidx.compose.foundation.layout.sizeIn import androidx.compose.foundation.shape.CircleShape import androidx.compose.material3.MaterialTheme import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.runtime.DisposableEffect import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember import androidx.compose.runtime.rememberCoroutineScope import androidx.compose.runtime.setValue import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.draw.clip import androidx.compose.ui.draw.drawBehind import androidx.compose.ui.focus.FocusRequester import androidx.compose.ui.focus.focusRequester import androidx.compose.ui.geometry.CornerRadius import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.graphicsLayer import androidx.compose.ui.input.pointer.pointerInput import androidx.compose.ui.platform.LocalView import androidx.compose.ui.unit.Dp import androidx.compose.ui.unit.dp Loading @@ -63,9 +64,7 @@ import com.android.systemui.common.ui.compose.Icon import com.android.systemui.res.R import kotlin.time.Duration.Companion.milliseconds import kotlin.time.DurationUnit import kotlinx.coroutines.async import kotlinx.coroutines.coroutineScope import kotlinx.coroutines.delay import kotlinx.coroutines.launch /** Renders the PIN button pad. */ Loading Loading @@ -234,7 +233,9 @@ private fun PinPadButton( onLongPressed: (() -> Unit)? = null, content: @Composable (contentColor: () -> Color) -> Unit, ) { var isPressed: Boolean by remember { mutableStateOf(false) } val interactionSource = remember { MutableInteractionSource() } val isPressed by interactionSource.collectIsPressedAsState() val indication = LocalIndication.current.takeUnless { isPressed } val view = LocalView.current LaunchedEffect(isPressed) { Loading Loading @@ -281,8 +282,6 @@ private fun PinPadButton( animationSpec = colorAnimationSpec ) val scope = rememberCoroutineScope() Box( contentAlignment = Alignment.Center, modifier = Loading @@ -297,24 +296,14 @@ private fun PinPadButton( cornerRadius = CornerRadius(cornerRadius.toPx()), ) } .clip(CircleShape) .thenIf(isEnabled) { Modifier.pointerInput(Unit) { detectTapGestures( onPress = { scope.launch { isPressed = true val minDuration = async { delay(pinButtonPressedDuration + pinButtonHoldTime) } tryAwaitRelease() minDuration.await() isPressed = false } }, onTap = { onClicked() }, onLongPress = onLongPressed?.let { { onLongPressed() } }, Modifier.combinedClickable( interactionSource = interactionSource, indication = indication, onClick = onClicked, onLongClick = onLongPressed ) } }, ) { content(contentColor::value) Loading Loading
packages/SystemUI/compose/features/src/com/android/systemui/bouncer/ui/composable/PinBouncer.kt +29 −40 Original line number Diff line number Diff line Loading @@ -24,30 +24,31 @@ import androidx.compose.animation.core.AnimationVector1D import androidx.compose.animation.core.animateDpAsState import androidx.compose.animation.core.animateFloatAsState import androidx.compose.animation.core.tween import androidx.compose.foundation.LocalIndication import androidx.compose.foundation.combinedClickable import androidx.compose.foundation.focusable import androidx.compose.foundation.gestures.detectTapGestures import androidx.compose.foundation.interaction.MutableInteractionSource import androidx.compose.foundation.interaction.collectIsPressedAsState import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.aspectRatio import androidx.compose.foundation.layout.sizeIn import androidx.compose.foundation.shape.CircleShape import androidx.compose.material3.MaterialTheme import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.runtime.DisposableEffect import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember import androidx.compose.runtime.rememberCoroutineScope import androidx.compose.runtime.setValue import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.draw.clip import androidx.compose.ui.draw.drawBehind import androidx.compose.ui.focus.FocusRequester import androidx.compose.ui.focus.focusRequester import androidx.compose.ui.geometry.CornerRadius import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.graphicsLayer import androidx.compose.ui.input.pointer.pointerInput import androidx.compose.ui.platform.LocalView import androidx.compose.ui.unit.Dp import androidx.compose.ui.unit.dp Loading @@ -63,9 +64,7 @@ import com.android.systemui.common.ui.compose.Icon import com.android.systemui.res.R import kotlin.time.Duration.Companion.milliseconds import kotlin.time.DurationUnit import kotlinx.coroutines.async import kotlinx.coroutines.coroutineScope import kotlinx.coroutines.delay import kotlinx.coroutines.launch /** Renders the PIN button pad. */ Loading Loading @@ -234,7 +233,9 @@ private fun PinPadButton( onLongPressed: (() -> Unit)? = null, content: @Composable (contentColor: () -> Color) -> Unit, ) { var isPressed: Boolean by remember { mutableStateOf(false) } val interactionSource = remember { MutableInteractionSource() } val isPressed by interactionSource.collectIsPressedAsState() val indication = LocalIndication.current.takeUnless { isPressed } val view = LocalView.current LaunchedEffect(isPressed) { Loading Loading @@ -281,8 +282,6 @@ private fun PinPadButton( animationSpec = colorAnimationSpec ) val scope = rememberCoroutineScope() Box( contentAlignment = Alignment.Center, modifier = Loading @@ -297,24 +296,14 @@ private fun PinPadButton( cornerRadius = CornerRadius(cornerRadius.toPx()), ) } .clip(CircleShape) .thenIf(isEnabled) { Modifier.pointerInput(Unit) { detectTapGestures( onPress = { scope.launch { isPressed = true val minDuration = async { delay(pinButtonPressedDuration + pinButtonHoldTime) } tryAwaitRelease() minDuration.await() isPressed = false } }, onTap = { onClicked() }, onLongPress = onLongPressed?.let { { onLongPressed() } }, Modifier.combinedClickable( interactionSource = interactionSource, indication = indication, onClick = onClicked, onLongClick = onLongPressed ) } }, ) { content(contentColor::value) Loading