appcues / appcues-react-native-module

The Appcues React Native Module
MIT License
10 stars 0 forks source link

Tooltip remains visible after pressing Android back button #159

Open jp1987 opened 3 months ago

jp1987 commented 3 months ago

See video, I would expect the tooltip to dismiss on back press. How can we solve this?

https://github.com/appcues/appcues-react-native-module/assets/1288101/43acc34e-a13a-44e9-b83a-1c25f0a70895

jp1987 commented 3 months ago

Any update here?

andretortolano commented 3 months ago

@jp1987 sorry the delay we are still investigating a possible solution for this.

andretortolano commented 3 months ago

adding some context to this issue.

The problem is that the native back button or the navigation back is getting ignored on Android for ViewPresenters that shouldHandleBack is true (Modals, Tooltips).

The reason is because we rely on an Android onBackPressedDispatcher to get called by the Activity when the onBackPressed() method is called, the default behavior is overridden for ReactActivity that instead calls for its own delegate (forward the back behavior to any RN navigation system that is being used)

one possible solution is to override your apps MainActivity to include this lines in order to prioritize any onBackPressedDispatcher registered (hasEnabledCallbacks):

override fun onBackPressed() {
  if (onBackPressedDispatcher.hasEnabledCallbacks()) {
    onBackPressedDispatcher.onBackPressed()
  } else {
    super.onBackPressed()
  }
}

Please let me know if this works for your app. in case you want to take this privately you can also reach me at andre@appcues.com