Skip to content

BridgeComponent onReceive invoked twice #38

@matthewblott

Description

@matthewblott

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
    }
  }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions