Is there anyone from the Compose Mutliplatform tea...
# compose-ios
i
Is there anyone from the Compose Mutliplatform team that might be able to shed light on why ComposeHostingViewController does not implement LifecycleOwner/ViewModelStoreOwner, and hides the IOSLifecycleOwner property? I'm working on some things that deal with interop between Compose and iOS applications, and it would make my life significantly easier if I was able access the IOSLifecycleOwner property, or if the ComposeHostingViewController implemented LifecycleOwner/ViewModelStoreOwner.
j
Can you make a custom
ViewController
subclass that extends
ComposeHostingViewController
and implements
LifecycleOwner?
a
What actually you want to achieve by accessing the LifecycleOwner/ViewModelStoreOwner ?
i
Can you make a custom ViewController subclass that extends ComposeHostingViewController and implements LifecycleOwner?
No; ComposeHostingViewController is an internal class and can't be subclassed. IOSLifecycleOwner is also internal, and so is ViewControllerLifecycleDelegate. It's possible to re-implement all of this myself, based on the library code, but that doesn't feel ideal.
What actually you want to achieve by accessing the LifecycleOwner/ViewModelStoreOwner ?
I want to be able to externally observe the ViewController's lifecycle, and access objects in the ViewModelStore. Contrived example: I have a UINavigationController; when some external event happens, I want to take a quick look through the UIControllers hosted by the UINavigationController, and if the top-most Controller is a ComposeHostingViewController, grab a ViewModel from that ComposeHostingViewController's ViewModelStore, and then call some function on the ViewModel. For example, if I intercept a deep link that's targeting a screen that's in the currently active ComposeHostingViewController, I might want to tell the ViewModel to reset a scroll state, so that a scrollable column on the screen scrolls back up to the top. At the moment to achieve what I want to achieve, I need to create my own wrapper for
ComposeUIViewController
, and grab the LocalLifecycleOwner/LocalViewModelStoreOwner inside composition, and keep a reference to these on the UIViewController with objc_getAssociatedObject. It's all possible to do, but it feels a little like jumping through hoops to achieve something that would otherwise be easily possible if the ComposeHostingViewController made
lifecycleOwner
public, or implemented the appropriate interfaces.