Multiple Strada components of the same name

If I connect two Strada components with the same name I can only reply to one of them. I’m not sure if this is intended behavior or not.

My example is a ButtonComponent that adds native bar button items to an iOS app. When I add both a left and right button I can only activate the click on the one referenced first in the HTML.

5 Likes

I realize this is over a year old (and pre-rebranding) but I wonder if this is still an issue. I too would like to have a generic button component I can use to trigger multiple navigation buttons, but I think I’m experiencing the same issue. Multiple buttons appear, but the click event seems to fire on the last one in the HTML, in my case.

I should add that I know nothing about iOS so I’m taking code from the demos and guides and making tweaks to it, so it’s possible I just didn’t replace something that I needed to replace.

Edit: I think I figured out the issue based on the Bridge Component examples, but I don’t fully understand it.

In the example, in the UIAction click handler, it replies to the last “connect” message for the component. reply(to:...) has the behavior of looking up the last event by event name.

        let action = UIAction { [unowned self] _ in
            self.reply(to: "connect")
        }

But if the component has been mounted multiple times, then, it seems that the “last” message might be for a different web element. I had the mental model that each web element would be mounted to a different instance of the Swift BridgeComponent, but it seems like perhaps that’s not true. Actually yes, after I override the init method in the bridge component and add a print statement, I can see that it’s only initialized once per view, it seems.

In order to get the reply to the correct web element, we need to supply the correct original message id, so e.g. the example code could be changed to:

        let action = UIAction { [unowned self] _ in
            self.reply(with: message)
        }

The actual message data doesn’t really matter for the purposes of this bridge component communication. (The reply(to: ...) variant also uses the original message body anyway.) But I think we could edit the jsonData field if we wanted to send something else.