Zach Klippenstein (he/him) [MOD]
08/25/2021, 8:29 PMNavBackStackEntryProvider sets all the owner locals for the destination (ViewModelStore, Lifecycle, SavedStateRegistry, and SaveableStateRegistry), and that AndroidView manages its view’s hierarchy state, but if a view underneath an AndroidView inside a composable destination asks for the ViewTreeSavedStateRegistryOwner, for example (and same for the other 2 view tree owners), wouldn’t they skip past the compose nav destination’s owners and find the owner on the android view containing the composition with the nav host? I would expect AndroidView to set the view tree owners from the respective composition locals on its child view.Ian Lake
08/25/2021, 9:34 PMIan Lake
08/25/2021, 9:35 PMLocalViewModelStoreOwner don't exist at all anywhere in the androidx.compose code base - they're completely independent things that AndroidView wouldn't ever know aboutZach Klippenstein (he/him) [MOD]
08/25/2021, 10:12 PMViewTreeViewModelStoreOwner though? And same for LifecycleOwner and SavedStateRegistryOwner?Ian Lake
08/25/2021, 10:15 PMViewTreeViewModelStoreOwner should be set to - the composition local is totally unknown to androidx.composeZach Klippenstein (he/him) [MOD]
08/25/2021, 10:16 PMComposeView1> NavHost > nav destination > AndroidView > ComposeView2 When ComposeView2 reads the 3 view tree owners, it should get the ones defined for that nav destination, right? But because the view tree owners search will only look up the view hierarchy, it will find the same ones read by ComposeView1 (i.e. the ones on RootView). So it won’t get, for example, the right lifecycle events when the destination is navigated away from.
Ian Lake
08/25/2021, 10:17 PMComposeView will inherit the composition localsZach Klippenstein (he/him) [MOD]
08/25/2021, 10:18 PMprovideDefault isn’t it… (checks…)Ian Lake
08/25/2021, 10:19 PMZach Klippenstein (he/him) [MOD]
08/25/2021, 10:23 PMAndroidCompositionLocals looks like it explicitly sets LocalLifecycleOwner & LocalSavedStateRegistryOwner here – and it gets the values for those locals from the AndroidComposeView, which gets them from the view tree here, not the incoming parent composition.Ian Lake
08/25/2021, 10:26 PMZach Klippenstein (he/him) [MOD]
08/25/2021, 10:30 PMProvideAndroidCompositionLocals throws if the owner.viewTreeOwners is null, so it would seem like those are read before creating the child composition, and then the composition is created, and then those values are provided before composing the child’s content.Ian Lake
08/25/2021, 11:21 PMIan Lake
08/25/2021, 11:22 PMCompositionContext, which is really what it should be using as the source of truth I would think?Ian Lake
08/25/2021, 11:22 PMZach Klippenstein (he/him) [MOD]
08/26/2021, 8:09 PMZach Klippenstein (he/him) [MOD]
08/26/2021, 8:16 PMLocalSavedStateRegistry and LocalSaveableStateRegistry. I guess AndroidView could just use the former for the view tree owner and assume that anyone setting one of those locals would correctly set both of them.Ian Lake
08/26/2021, 8:20 PMLocalViewModelStoreOwner is not visible or available to AndroidViewZach Klippenstein (he/him) [MOD]
08/26/2021, 8:31 PMZach Klippenstein (he/him) [MOD]
08/26/2021, 9:02 PM