Last active
October 4, 2023 13:56
-
-
Save hahouari/2cc8fb52a36d740b626cd33bec80f870 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Composable | |
fun MyScreen(modifier: Modifier = Modifier) { | |
// ... | |
// ... other variables | |
// ... | |
val configuration = LocalConfiguration.current | |
val scope = rememberCoroutineScope() | |
val interactionSource = remember { MutableInteractionSource() } | |
val indication = rememberRipple( | |
// if set false, the ripple effect will not be cropped to the button. | |
bounded = true, | |
// if you want to spread to stop right at the edges of your targeted composable, | |
// take the longest side divided by two, in this case the row width is the screen width. | |
radius = configuration.screenWidthDp.dp / 2, | |
) | |
// used later to change Dp unit to Pixels using .toPx() | |
val density = LocalDensity.current | |
LaunchedEffect(Unit) { | |
with(density) { | |
scope.launch { | |
// wait a little bit for user to focus on the screen | |
delay(800) | |
val centerX = configuration.screenWidthDp.dp / 2 | |
val centerY = 64.dp / 2 | |
// simulate a press for the targeted setting tile | |
val press = PressInteraction.Press(Offset(centerX.toPx(), centerY.toPx())) | |
interactionSource.emit(press) | |
// wait a little bit for the effect to animate | |
delay(400) | |
// release the effect | |
val release = PressInteraction.Release(press) | |
interactionSource.emit(release) | |
} | |
} | |
} | |
// ... | |
// ... The rest of the code in segment 2 | |
// ... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment