Function

findViewTreeComposeViewContext

Returns the ComposeViewContext used in this View's part of the hierarchy, or null if one cannot be found or it doesn't match the values set for View.findViewTreeLifecycleOwner or View.findViewTreeSavedStateRegistryOwner.

findViewTreeComposeViewContext

Source set: Android
public fun View.findViewTreeComposeViewContext(): ComposeViewContext?

Returns the ComposeViewContext used in this View's part of the hierarchy, or null if one cannot be found or it doesn't match the values set for View.findViewTreeLifecycleOwner or View.findViewTreeSavedStateRegistryOwner. For example, if there is a ComposeView set in the hierarchy, findViewTreeComposeViewContext on a child of that View will normally return that ComposeViewContext. However, if the child is within a Fragment, its LifecycleOwner differs from the ComposeView, so findViewTreeComposeViewContext will return null.

This can be used with AbstractComposeView.createComposition to compose without the ComposeView being attached:

Jetpack Compose beyond MaterialFree components, screens and templates for apps that don’t look like Google’s. Copy them into your app, or let your coding agent add them.Browse for free

Content updated: