I’m trying this in android compose
@OptIn(ExperimentalComposeUiApi::class)
@Composable
fun Screen() {
Scaffold(
topBar = {},
bottomBar = {}
) { innerPadding ->
MainBody(
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.spacedBy(dimensionResource(id = R.dimen.rhythmEighth)),
modifier = Modifier
.fillMaxSize()
.padding(innerPadding)
.padding(horizontal = dimensionResource(id = R.dimen.pageMarginHorizontal))
) {
Text(
text = stringResource(id = R.string.email_title),
style = baseTextAppearanceTitle1
)
Column(
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.spacedBy(dimensionResource(id = R.dimen.rhythmSixteenth)),
) {
OutlinedTextField(
value = "",
onValueChange = {},
label = { Text(stringResource(id = R.string.email_placeholder)) },
keyboardActions = KeyboardActions(
onDone = { keyboardController?.hide() }
)
)
}
}
}
}
and this re-usable component that I created to detect gestures on several screens. Which shows an alert message after some time of inactivity
@Composable
internal fun MainBody(
modifier: Modifier = Modifier,
verticalArrangement: Arrangement.Vertical = Arrangement.Top,
horizontalAlignment: Alignment.Horizontal = Alignment.Start,
onCancelAction: (() -> Unit)? = null,
content: @Composable ColumnScope.() -> Unit,
) {
val popupStart = 25
val closeStart = 15
var popupCountdown by remember { mutableIntStateOf(popupStart) }
var closeSessionCountdown by remember { mutableIntStateOf(closeStart) }
LaunchedEffect(Unit) {
while (true) {
delay(1000)
if (popupCountdown > 0) {
popupCountdown--
} else {
closeSessionCountdown--
}
}
}
if (closeSessionCountdown == 0 && onCancelAction != null) {
onCancelAction()
}
Column(
horizontalAlignment = horizontalAlignment,
verticalArrangement = verticalArrangement,
modifier = modifier.pointerInput(Unit) {
awaitEachGesture {
awaitFirstDown(
pass = androidx.compose.ui.input.pointer.PointerEventPass.Initial
)
popupCountdown = popupStart
closeSessionCountdown = closeStart
}
}
) {
content()
Alert(
showDialog = popupCountdown == 0,
)
}
}
My issue is that when I start typing on the OutlinedTextField
the parent component doesn’t detect the action and triggers the inactivity pop. Could you suggest a way to do this?
Thanks