rocketraman
01/31/2022, 6:41 PMval rather than using a var and delegates. But I'm trying to understand the Redditor's examples. Why doesn't the Draggable example work (assuming it doesn't, I haven't tried it)? Their explanation:
When Jetpack invokes the detectDragGestures callback, it's the same lambda instance. That means we never get the new values of offsetX and offsetY.But shouldn't
DraggableZone and Draggable recompose when the offset changes, thus getting new values of offsetX and offsetY in detectDragGestures?yschimke
01/31/2022, 6:50 PMrocketraman
01/31/2022, 6:51 PMAlbert Chang
01/31/2022, 7:19 PMThe pointer input handling block will be cancelled and re-started when pointerInput is recomposed with a different key1.
Halil Ozercan
01/31/2022, 8:37 PMrememberUpdatedState for lambdas which solves stale value problem. If you are passing a lambda to child composables, especially for state manipulation, be sure to use that.Zach Klippenstein (he/him) [MOD]
02/01/2022, 2:57 AMpointerInput is launched into a coroutine that lives as long as the modifier is applied with the same keys. The first time that modifier is created, the lambda is allocated and captures any properties read inside it as fields in the underlying lambda object. Every time that modifier is recomposed, the original lambda is still being used for the coroutine, and all the values it captured.
In the case of the explicit State or the delegated one, the lambda captured the State object itself. The value inside the state can change over time, but because the lambda captured the state object itself, every time it asks it for the value it gets the latest one stored inside the state. And on subsequent compositions, the lambda doesn't need to be recreated to capture the state object again because it's the same state object.
However, in the destructuring case, the lambda captures the initial actual value, not the state object holding it. So when new values are destructured in subsequent compositions, the lambda running in the coroutine is still the original lambda with the original values.rocketraman
02/01/2022, 8:23 PMrememberUpdatedState becomes clear as well!Zach Klippenstein (he/him) [MOD]
02/01/2022, 10:51 PMrocketraman
02/02/2022, 1:41 PM@SurvivesRecompose would allow for developer observability, and for tooling like IDEs and linters to give appropriate warnings.Zach Klippenstein (he/him) [MOD]
02/02/2022, 6:42 PMrocketraman
02/03/2022, 5:18 AM