@@ -3,6 +3,7 @@ package com.multiplemodals
33import android.app.Activity
44import android.content.Context
55import android.content.DialogInterface
6+ import android.os.Build
67import android.view.KeyEvent
78import android.view.View
89import android.view.ViewGroup
@@ -120,7 +121,7 @@ class RNTModalView(context: Context): ViewGroup(context), LifecycleEventListener
120121 }
121122
122123 private fun attachBackHandler (dialog : ModalDialog ) {
123- // Prevent closing from native part as this is handled by JS
124+ // Prevent KEYCODE_BACK from closing the dialog and handle the event in JS.
124125 dialog.setOnKeyListener(object : DialogInterface .OnKeyListener {
125126 override fun onKey (dialog : DialogInterface , keyCode : Int , event : KeyEvent ): Boolean {
126127 if (event.action != KeyEvent .ACTION_UP ) {
@@ -144,6 +145,17 @@ class RNTModalView(context: Context): ViewGroup(context), LifecycleEventListener
144145 return false
145146 }
146147 })
148+
149+ // Register a back handler to prevent closing and handle the event in JS.
150+ if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .TIRAMISU ) {
151+ dialog.onBackInvokedDispatcher.registerOnBackInvokedCallback(
152+ android.window.OnBackInvokedDispatcher .PRIORITY_DEFAULT
153+ ) {
154+ UiThreadUtil .runOnUiThread {
155+ eventDispatcher.dispatchEvent(PressBackEvent (surfaceId, id))
156+ }
157+ }
158+ }
147159 }
148160
149161 // Child management
0 commit comments