Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 205d1e5

Browse files
committed
navigationStackIsEmpty method to enable predictive back
1 parent 9c0e7cc commit 205d1e5

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

shell/platform/android/io/flutter/embedding/android/FlutterActivity.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -666,14 +666,21 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
666666
public void registerOnBackInvokedCallback() {
667667
if (Build.VERSION.SDK_INT >= 33) {
668668
// TODO(justinmc): This is really the one and only thing that stops root
669-
// pback for me.
669+
// pback for me. There are probably other places you need to mess with
670+
// this for other embedding strategies!
670671
Log.e("justin", "registerOnBackInvokedCallback");
671672
getOnBackInvokedDispatcher()
672673
.registerOnBackInvokedCallback(
673674
OnBackInvokedDispatcher.PRIORITY_DEFAULT, onBackInvokedCallback);
674675
}
675676
}
676677

678+
@Override
679+
public void navigatorIsEmpty() {
680+
Log.e("justin", "navigatorIsEmpty in embedding FlutterActivity");
681+
unregisterOnBackInvokedCallback();
682+
}
683+
677684
/**
678685
* Unregisters the callback from OnBackInvokedDispatcher.
679686
*

shell/platform/android/io/flutter/embedding/android/FlutterFragment.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1661,6 +1661,13 @@ public boolean popSystemNavigator() {
16611661
return false;
16621662
}
16631663

1664+
@Override
1665+
public void navigatorIsEmpty() {
1666+
// TODO(justinmc): Implement. Implementing in FlutterActivity first.
1667+
// unregisterOnBackInvokedCallback();
1668+
Log.e("justin", "navigatorIsEmpty in embedding FlutterFragment");
1669+
}
1670+
16641671
@VisibleForTesting
16651672
@NonNull
16661673
boolean shouldDelayFirstAndroidViewDraw() {

shell/platform/android/io/flutter/plugin/platform/PlatformPlugin.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ public interface PlatformPluginDelegate {
5656
* androidx.activity.OnBackPressedDispatcher} will be executed.
5757
*/
5858
boolean popSystemNavigator();
59+
60+
void navigatorIsEmpty();
5961
}
6062

6163
@VisibleForTesting
@@ -111,6 +113,7 @@ public void setSystemUiOverlayStyle(
111113

112114
@Override
113115
public void navigatorIsEmpty() {
116+
Log.e("justin", "navigatorIsEmpty in PlatformHandler.PlatformMessageChannel.");
114117
PlatformPlugin.this.navigatorIsEmpty();
115118
}
116119

@@ -482,8 +485,7 @@ private void setSystemChromeSystemUIOverlayStyle(
482485

483486
private void navigatorIsEmpty() {
484487
Log.e("justin", "navigatorIsEmpty in PlatformPlugin");
485-
// TODO(justinmc): Can't quite call it like this, need FlutterActivity.
486-
// activity.unregisterOnBackInvokedCallback();
488+
platformPluginDelegate.navigatorIsEmpty();
487489
}
488490

489491
private void popSystemNavigator() {

0 commit comments

Comments
 (0)