strada-ios icon indicating copy to clipboard operation
strada-ios copied to clipboard

Web and native lifecycle event mismatch when called on a background tab

Open adampal opened this issue 11 months ago • 2 comments

The web BridgeComponent connect event fires when the element appears on a page. However, if this happens on a background tab, the native BridgeComponent will ignore any messages sent because the destination is not yet active. This means the native component is not initialised.

When the user switches to the tab that has the component, the web connect event has already fired and won't happen again. There is no equivalent to viewWillLoad for the web component so I have no way of initialising the component when the user switches to the tab. You also can't use the native onViewDidLoad lifecycle event because the native component isn't initialised until it receives an event from the web so onViewDidLoad is never called.

I think I understand why we're ignoring events on an inactive destination. However maybe we could make an exception for connect events. The connect event is often used to initialise the component and set some base state ready for when the user starts interacting with it. In most cases this should be ok (preferable even?) to run on a background tab so by the time the user wants to interact with the component it has already set any state it needs.

I'd love to know if anyone else has hit this issue or if there's any recommended way of handling this situation.

If you think allowing connected events on a not-active destination is a good idea, I'm happy to draft up a PR with the change.

adampal avatar Mar 26 '24 03:03 adampal