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

[BottomSheetDialog] initializeViewTreeOwners() wasn't triggered when set/addContentView so AbstractComposeView is not supported. #4208

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

bytebeats
Copy link

Close #4207.

Because of getDelegate(): AppCompatDelegate, the calling chain of ButtomSheetDialog#add/setContentView -> AppCompatDialog#add/setContentView -> ComponentDialog#add/setContentView was broken. So initializeViewTreeOwners() wasn't triggered, then BottomSheetDialog#decorView has no LifecycleOwner. So when AbstractComposeView was inserted into the view hierarchy of BotomSheetDialog, the extension function below will return null.

fun View.findViewTreeLifecycleOwner(): LifecycleOwner? {
    return generateSequence(this) { currentView ->
        currentView.parent as? View
    }.mapNotNull { viewParent ->
        viewParent.getTag(R.id.view_tree_lifecycle_owner) as? LifecycleOwner
    }.firstOrNull()
}

So the code below is triggered:

val viewTreeLifecycle =
        checkNotNull(lifecycle ?: findViewTreeLifecycleOwner()?.lifecycle) {
            "ViewTreeLifecycleOwner not found from $this"
        }

And it's exactly what the log is mentioning.

Copy link

google-cla bot commented Jun 25, 2024

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@bytebeats bytebeats marked this pull request as draft June 25, 2024 10:53
@bytebeats bytebeats marked this pull request as ready for review June 26, 2024 01:52
@bytebeats
Copy link
Author

bytebeats commented Jun 26, 2024

Since the Commit and Version 1.7.0, we could just upgrade the androidx.acivity:activity to 1.7.0. But still in 1.7.0, initViewTreeOwners() is still not called inside addContentView, so we still need to modify addContentView(...).

I create a PR to fix the issue from addContentView in PR-686. If the issue is fixed in the next version of androidx.appcompat:appcompat, we could just remove the modification of BottomSheetDialog#addContentView.

But if we don't want to upgrade the androidx.appcomapt:appcomat, we could add codes from the commit

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.

[BottomSheetDialog] AbstractComposeView can't be inserted a layout file used to a BottomSheetDialog.
1 participant