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

BridgeComponent onReceive invoked twice

Open matthewblott opened this issue 7 months ago • 0 comments

As the title says. The first time the component is initialised the onReceive method is invoked once as expected. Subsequent visits to any page where the component is used will see the onReceive method invoked twice. The issue became apparent because I was having menu items added twice and I thought it was something else. I tested this with the main Turbo demo Android application and found the same behaviour.

I am currently using this workaround:

open class LinkTo (
  name: String,
  private val delegate: BridgeDelegate<NavDestination>,
) : BridgeComponent<NavDestination>(name, delegate) {

  private var isNew = false

  override fun onReceive(message: Message) {
    if(!isNew) {
      when (message.event) {
        "connect" -> handleConnectEvent(message)
        else -> Log.w("TurboDemo", "Unknown event for message: $message")
      }
      isNew = true
    }
  }

matthewblott avatar Jul 02 '24 10:07 matthewblott