Hi ! I've got a behaviour that I don't understand ...
# compose
l
Hi ! I've got a behaviour that I don't understand with Recomposition and Tap gesture. More in the thread.
This is a preview of the component I've built as a simple experiment. It comes with a reverse button.
If I click on the reverse button, digits are reorganized on different cells (4 comes in place of 1, 3 in place of 2, ...)
If I click on a cell, I should get the digit printed in the cell (with a
Toast
). But it only works correctly in normal orientation. In reversed orientation (just after having clicked on the reverse button, and without any device rotation) I still get "1" for the first cell
Here is the full code of the experiment, as well as its preview function.
It seems that the tap gesture keeps a reference to the original value of reversed parameter. But how can I come around this ?
A more accurate preview of the experiment
a
Use
pointerInput(reversed) { ... }
.
👍 1
🙏 1
l
Thank you very much : it worked 🙂 Looking at https://developer.android.com/reference/kotlin/androidx/compose/ui/input/pointer/package-summary#pointerinput_3, I see that the variabla arguments parameter is simply called
keys
and has type
Any
: does it mean that any variable -state or not- can be passed in if i want the gesture to be updated based on them ?
z
You could also use
rememberUpdatedState
with reversed if for some reason you didn’t want to restart your input coroutines
👍 1
a
Yes. Actually you don't need to specify a variable as a key if it is a
State
.
State
is a value holder which always holds the latest value, but your
reversed
is the value itself so when it is captured by the lambda of
pointerInput
it won't get updated unless you create a new lambda. This not specific to gestures. It's basically the same as the keys parameter in `remember`/`LaunchedEffect`/`DisposableEffect`.
👍 1
l
Thank you very much @Albert Chang @Zach Klippenstein (he/him) [MOD] for your clear explanations 🙂. I'll consider more carefully how I design those 🙂