<@UHAJKUSTU> if I create a component this way: ```...
# decompose
e
@Arkadii Ivanov if I create a component this way:
Copy code
private val receivedMediaComponent by lazy {        receivedMediaComponent(childContext("receivedMediaComponent"))
    }
do I need any additional setup to make lifecycle of the component work correctly? It doesn’t receive onResume events when I call
bringToFront()
, but gets it if I close/open the app. Is that expected behaviour?
a
How do you use
bringToFront
together with the permanent component
receivedMediaComponent
?
e
The component is added to the child stack in a bottom navigation component. I just pass the instance when the child is constructed.
a
Do you receive at least one onResume?
e
Yes, I receive one OnResume when the screen is first opened (just created), but it doesn’t happen when I change bottom tabs back and forth.
a
I think this is expected, since the component context you are using is permanent. You would need to use the component context provided by navigation (the childFactory function).
e
Thank you!
👍 1
I had to implement a
LazyValue
wrapper class, which holds a component and is initialized during child creation like this:
Copy code
Configuration.Received -> Child.ReceivedChild(receivedMediaComponent.getOrInit {
                receivedMediaComponent(componentContext)
            })
And now it seems to work correctly. Thanks again!
a
Just take care to not leak the component context. E.g. if you remove the child component from the stack, it should be released and deallocated. And next time you should use the new component context again.
e
Yes, thanks for noticing. It’s really tricky. I assume that if I use
bringToFront
in this particular case the component is never removed from stack and should live the same period of time as its parent holding the reference. But in general it is very important point, I should be more careful.
👍 1