Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uses DisposeOnViewTreeLifecycleDestroyed for ComposeView #1213

Merged
merged 2 commits into from
Jul 31, 2024

Conversation

rjrjr
Copy link
Contributor

@rjrjr rjrjr commented Jul 23, 2024

Fixes a problem where removing a ComposeView from the view hierarchy and then reintroducing it breaks things. For example this happens when DialogCollator calls dimiss() / show() on Dialog windows to re-order them. But it could also happen with things like RecyclerView, or anything that might do interesting classic view management. This kind of issue is why ViewTreeLifecycleOwner was invented, and why we've worked so hard to keep it working.

@rjrjr rjrjr force-pushed the ray/lifecycle-based-ComposeView-strategy branch from 0c676ae to 1f9a410 Compare July 23, 2024 22:39
@rjrjr rjrjr force-pushed the ray/lifecycle-based-ComposeView-strategy branch from 5fe942e to 1f9a410 Compare July 31, 2024 00:49
Fixes a problem where removing a `ComposeView` from the view hierarchy and then reintroducing it breaks things. For example this happens when `DialogCollator` calls `dimiss()` / `show()` on `Dialog` windows to re-order them. But it could also happen with things like `RecyclerView`, or anything that might do interesting classic view management. This kind of issue is why `ViewTreeLifecycleOwner` was invented, and why we've worked so hard to keep it working.
@rjrjr rjrjr force-pushed the ray/lifecycle-based-ComposeView-strategy branch from 1f9a410 to 698aa80 Compare July 31, 2024 00:51
@rjrjr rjrjr marked this pull request as ready for review July 31, 2024 00:51
@rjrjr rjrjr requested review from a team as code owners July 31, 2024 00:51
Signed-off-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
rjrjr added a commit that referenced this pull request Jul 31, 2024
When `DialogCollator` has to reorder, it did so by calling `Dialog.dismiss()` and `Dialog.show()`. #1213 fixed a problem that caused for `ComposeView`, but that fix is undone by Compose 1.6.8. Ngoc Vu dug in to see why and discovered:

> The `onClick` in `Modifier.clickable` is passed all the way down to `pointerInputHandler` in `SuspendingPointerInputModifierNodeImpl` (when the screen is responsive, you should see `pointerInputHandler()` being called in `SuspendingPointerInputModifierNodeImpl#onPointerEvent`).
>
> After shuffling the overlays, even though the `ClickableNode` is found and `SuspendingPointerInputModifierNodeImpl#onPointerEvent` is called, `pointerInputHandler()` is never called  because the `pointerInputJob` in `SuspendingPointerInputModifierNodeImpl` was launched from a canceled coroutineScope. Tracking down that coroutineScope shows that it was canceled when `DialogCollator` calls `Dialog.dismiss` -> `onViewDetachedFromWindow`  -> `Recomposer.cancel()`. So it makes sense why destroying/rebuilding instead of dismissing and reusing the dialog fixes this issue.

Still need to put together a non-workflow repro sample and submit a bug to the Compose team, but this unblocks our move to Compose 1.6.8 in the meantime.
@rjrjr rjrjr merged commit 8cb0a82 into main Jul 31, 2024
31 checks passed
@rjrjr rjrjr deleted the ray/lifecycle-based-ComposeView-strategy branch July 31, 2024 22:47
rjrjr added a commit that referenced this pull request Jul 31, 2024
When `DialogCollator` has to reorder, it did so by calling `Dialog.dismiss()` and `Dialog.show()`. #1213 fixed a problem that caused for `ComposeView`, but that fix is undone by Compose 1.6.8. @vumngoc dug in to see why and discovered:

> The `onClick` in `Modifier.clickable` is passed all the way down to `pointerInputHandler` in `SuspendingPointerInputModifierNodeImpl` (when the screen is responsive, you should see `pointerInputHandler()` being called in `SuspendingPointerInputModifierNodeImpl#onPointerEvent`).
>
> After shuffling the overlays, even though the `ClickableNode` is found and `SuspendingPointerInputModifierNodeImpl#onPointerEvent` is called, `pointerInputHandler()` is never called  because the `pointerInputJob` in `SuspendingPointerInputModifierNodeImpl` was launched from a canceled coroutineScope. Tracking down that coroutineScope shows that it was canceled when `DialogCollator` calls `Dialog.dismiss` -> `onViewDetachedFromWindow`  -> `Recomposer.cancel()`. So it makes sense why destroying/rebuilding instead of dismissing and reusing the dialog fixes this issue.

Still need to put together a non-workflow repro sample and submit a bug to the Compose team, but this unblocks our move to Compose 1.6.8 in the meantime.
rjrjr added a commit that referenced this pull request Jul 31, 2024
When `DialogCollator` has to reorder, it did so by calling `Dialog.dismiss()` and `Dialog.show()`. #1213 fixed a problem that caused for `ComposeView`, but that fix is undone by Compose 1.6.8. @vumngoc dug in to see why and discovered:

> The `onClick` in `Modifier.clickable` is passed all the way down to `pointerInputHandler` in `SuspendingPointerInputModifierNodeImpl` (when the screen is responsive, you should see `pointerInputHandler()` being called in `SuspendingPointerInputModifierNodeImpl#onPointerEvent`).
>
> After shuffling the overlays, even though the `ClickableNode` is found and `SuspendingPointerInputModifierNodeImpl#onPointerEvent` is called, `pointerInputHandler()` is never called  because the `pointerInputJob` in `SuspendingPointerInputModifierNodeImpl` was launched from a canceled coroutineScope. Tracking down that coroutineScope shows that it was canceled when `DialogCollator` calls `Dialog.dismiss` -> `onViewDetachedFromWindow`  -> `Recomposer.cancel()`. So it makes sense why destroying/rebuilding instead of dismissing and reusing the dialog fixes this issue.

Still need to put together a non-workflow repro sample and submit a bug to the Compose team, but this unblocks our move to Compose 1.6.8 in the meantime.
rjrjr added a commit that referenced this pull request Aug 1, 2024
This was the first attempt to fix dead `ComposeView` instances in shuffled `Dialog` windows, but it breaks other things. Still seems like the right thing to do, but maybe that ship has sailed. If the need comes up again, consider adding a `ViewEnvironment` property to allow customizing it (yuck).

Undoes #1213
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants