Skip to content

Commit 3316800

Browse files
committed
fix back handling on api <33
1 parent d183e30 commit 3316800

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

modalsheet/src/main/kotlin/dev/hrach/navigation/modalsheet/ModalSheetDialog.kt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import android.window.OnBackInvokedCallback
1313
import android.window.OnBackInvokedDispatcher
1414
import androidx.activity.BackEventCompat
1515
import androidx.activity.ComponentDialog
16+
import androidx.activity.addCallback
1617
import androidx.activity.setViewTreeOnBackPressedDispatcherOwner
1718
import androidx.annotation.DoNotInline
1819
import androidx.annotation.RequiresApi
@@ -309,6 +310,17 @@ internal class ModalSheetDialogWrapper(
309310
dialogLayout.setViewTreeOnBackPressedDispatcherOwner(this)
310311
// Initial setup
311312
updateParameters(securePolicy, layoutDirection, darkThemeEnabled)
313+
314+
// Due to how the onDismissRequest callback works
315+
// (it enforces a just-in-time decision on whether to update the state to hide the dialog)
316+
// we need to unconditionally add a callback here that is always enabled,
317+
// meaning we'll never get a system UI controlled predictive back animation
318+
// for these dialogs
319+
onBackPressedDispatcher.addCallback(this) {
320+
scope.launch {
321+
onPredictiveBack.value.invoke(flowOf())
322+
}
323+
}
312324
}
313325

314326
private fun setLayoutDirection(layoutDirection: LayoutDirection) {

0 commit comments

Comments
 (0)