Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BridgeComponent onReceive invoked twice #38

Open
matthewblott opened this issue Jul 2, 2024 · 0 comments
Open

BridgeComponent onReceive invoked twice #38

matthewblott opened this issue Jul 2, 2024 · 0 comments

Comments

@matthewblott
Copy link

matthewblott commented Jul 2, 2024

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
    }
  }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant