Closed Pezcraft closed 2 months ago
They're both have the same input. So the can't. You will need to implement this yourself.
What are you wanting to happen?
I want to reset a CountDownTimer whenever the user interacts with the app which includes scrolling.
You will need to look at the implementations of those and use some of the lower level APIs. if you make a sample screen, I can more easily suggest a change.
@OptIn(ExperimentalHorologistApi::class, ExperimentalWearFoundationApi::class)
@Composable
fun SampleScreen(
modifier: Modifier = Modifier,
) {
val columnState = rememberColumnState()
val focusRequester = rememberActiveFocusRequester()
var showBlackScreenNow by remember { mutableStateOf(false) }
val screenTimeout: CountDownTimer = object : CountDownTimer(5000, 1000) {
override fun onTick(millisUntilFinished: Long) {}
override fun onFinish() {
showBlackScreenNow = true
}
}
Scaffold(modifier = modifier) {
ScalingLazyColumn(
modifier = Modifier
.fillMaxSize()
.rotaryWithScroll(columnState, focusRequester)
.onRotaryScrollEvent {
if (showBlackScreenNow) {
showBlackScreenNow = false
}
screenTimeout.cancel()
screenTimeout.start()
true
},
state = columnState.state
) {
item { Text(text = "...") }
}
if (showBlackScreenNow) {
Column(
modifier = Modifier
.fillMaxWidth()
.fillMaxHeight()
.wrapContentSize(Alignment.Center)
.clickable {
if (showBlackScreenNow) {
showBlackScreenNow = false
}
screenTimeout.cancel()
screenTimeout.start()
},
) {
Box(
modifier = Modifier
.fillMaxWidth()
.fillMaxHeight()
.clip(RectangleShape)
.background(Color.Black, RectangleShape)
)
}
}
}
}
Thanks, I'll take a look. But it might be a couple of days.
Forgot about this, sorry. Will take a look.
These APIs are now part of Wear Compose. You should see whether the Rotary support does what you need https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:wear/compose/compose-foundation/src/main/java/androidx/wear/compose/foundation/rotary/RotaryScrollable.kt;l=118?q=RotaryScrollable&sq=
I expect this is by design, the existing rotary code normally consumes the events.
/**
* Adding this [modifier][Modifier] to the [modifier][Modifier] parameter of a component will allow
* it to intercept [RotaryScrollEvent]s if it (or one of its children) is focused.
*
* @param onRotaryScrollEvent This callback is invoked when the user interacts with the rotary side
* button or the bezel on a wear device. While implementing this callback, return true to stop
* propagation of this event. If you return false, the event will be sent to this
* [onRotaryScrollEvent]'s parent.
* @return true if the event is consumed, false otherwise.
*/
fun Modifier.onRotaryScrollEvent(onRotaryScrollEvent: (RotaryScrollEvent) -> Boolean): Modifier =
this then
Big apologies for the delay and responding and then just closing.
onRotaryInputAccumulatedWithFocus
does nothing whenrotaryWithScroll
is used too. So what's the best option to react to scrolling events?