firebase-android-sdk icon indicating copy to clipboard operation
firebase-android-sdk copied to clipboard

FIAM does not dismiss on back gesture when android:enableOnBackInvokedCallback is set to true

Open kk-777-1127 opened this issue 11 months ago • 6 comments

  • Android Studio version: Android Studio Meerkat | 2024.3.1 Canary
  • Firebase Component: InAppMessaging
  • Component version: Bom33.7.0

Expected behavior: • The FIAM message should be dismissed when the back gesture is performed.

Observed behavior: • The FIAM message is not dismissed when the back gesture is performed.

Steps to reproduce:

1.	Enable android:enableOnBackInvokedCallback in your app’s AndroidManifest.xml.
2.	Display a Firebase In-App Messaging (FIAM) message.
3.	Attempt to dismiss the FIAM message using the back gesture.

Relevant Code:

It seems the issue may be related to the BackButtonHandler implementation in the Firebase In-App Messaging SDK. Specifically, dispatchKeyEvent in BackButtonHandler might not be invoked when android:enableOnBackInvokedCallback is set to true, as the back gesture bypasses the traditional KeyEvent.KEYCODE_BACK handling. https://github.com/firebase/firebase-android-sdk/blob/377edccb947d97000fde92999743f3981e89f6c5/firebase-inappmessaging-display/src/main/java/com/google/firebase/inappmessaging/display/internal/layout/util/BackButtonHandler.java#L23

kk-777-1127 avatar Jan 24 '25 06:01 kk-777-1127

I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.

google-oss-bot avatar Jan 24 '25 06:01 google-oss-bot

Hi @kk-777-1127, thank you for reaching out. I was able to reproduce the issue. I'll raise this to our engineers and see what we can do here. I'll get back to you once I hear back from them. Thanks!

lehcar09 avatar Jan 24 '25 19:01 lehcar09

The FiamFrameLayout component does not have direct knowledge of the associated Activity. This makes it challenging to implement features that rely on Activity, such as supporting predictive back gestures using OnBackInvokedDispatcher (introduced in Android 13).

kk-777-1127 avatar Jan 25 '25 02:01 kk-777-1127

From what I gather, setting android:enableOnBackInvokedCallback=true turns on predictive back animations, and instructs the system to use the OnBackInvokedCallback platform API.

The OnBackInvokedCallback platform API, replaces the KeyEvent.KEYCODE_BACK API and all platform classes that use OnBackPressed, which are planned for deprecation and which will require migration in the next major Android release following 13. For details, see documentation.

This looks to me like a feature request to use the OnBackInvokedCallback platform API. That said, I'll go ahead and mark this as a feature request. While we are unable to promise any timeline for this, we'll definitely keep this under our radar.

P.S. For folks who find this useful, adding an emoji thumbs up on the original post can help us prioritize adding this to the roadmap.

lehcar09 avatar Jan 27 '25 17:01 lehcar09

I got around it by setting enableOnBackInvokedCallback=false for Application in AndroidManifext.xml and enableOnBackInvokedCallback=true for Activity. Other Bad effects of this are unknown.

To begin with, can OnBackInvokedCallback be used when added with WindowManager#addView?

matsudamper avatar Feb 10 '25 13:02 matsudamper

There were no issues with Android 15 and Baklava, so this may also be a bug in Android 14 only.

matsudamper avatar Feb 11 '25 16:02 matsudamper