From 205d1e53397591594e400b79e16280d62b84f922 Mon Sep 17 00:00:00 2001 From: Justin McCandless Date: Wed, 1 Feb 2023 11:41:06 -0800 Subject: [PATCH] navigationStackIsEmpty method to enable predictive back --- .../io/flutter/embedding/android/FlutterActivity.java | 9 ++++++++- .../io/flutter/embedding/android/FlutterFragment.java | 7 +++++++ .../io/flutter/plugin/platform/PlatformPlugin.java | 6 ++++-- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/shell/platform/android/io/flutter/embedding/android/FlutterActivity.java b/shell/platform/android/io/flutter/embedding/android/FlutterActivity.java index a94c266dde14b..ebf92d77d2168 100644 --- a/shell/platform/android/io/flutter/embedding/android/FlutterActivity.java +++ b/shell/platform/android/io/flutter/embedding/android/FlutterActivity.java @@ -666,7 +666,8 @@ protected void onCreate(@Nullable Bundle savedInstanceState) { public void registerOnBackInvokedCallback() { if (Build.VERSION.SDK_INT >= 33) { // TODO(justinmc): This is really the one and only thing that stops root - // pback for me. + // pback for me. There are probably other places you need to mess with + // this for other embedding strategies! Log.e("justin", "registerOnBackInvokedCallback"); getOnBackInvokedDispatcher() .registerOnBackInvokedCallback( @@ -674,6 +675,12 @@ public void registerOnBackInvokedCallback() { } } + @Override + public void navigatorIsEmpty() { + Log.e("justin", "navigatorIsEmpty in embedding FlutterActivity"); + unregisterOnBackInvokedCallback(); + } + /** * Unregisters the callback from OnBackInvokedDispatcher. * diff --git a/shell/platform/android/io/flutter/embedding/android/FlutterFragment.java b/shell/platform/android/io/flutter/embedding/android/FlutterFragment.java index 483b5ec0f52fe..ad581197802a9 100644 --- a/shell/platform/android/io/flutter/embedding/android/FlutterFragment.java +++ b/shell/platform/android/io/flutter/embedding/android/FlutterFragment.java @@ -1661,6 +1661,13 @@ public boolean popSystemNavigator() { return false; } + @Override + public void navigatorIsEmpty() { + // TODO(justinmc): Implement. Implementing in FlutterActivity first. + // unregisterOnBackInvokedCallback(); + Log.e("justin", "navigatorIsEmpty in embedding FlutterFragment"); + } + @VisibleForTesting @NonNull boolean shouldDelayFirstAndroidViewDraw() { diff --git a/shell/platform/android/io/flutter/plugin/platform/PlatformPlugin.java b/shell/platform/android/io/flutter/plugin/platform/PlatformPlugin.java index 02b61cebdb6ff..a2eec420e2325 100644 --- a/shell/platform/android/io/flutter/plugin/platform/PlatformPlugin.java +++ b/shell/platform/android/io/flutter/plugin/platform/PlatformPlugin.java @@ -56,6 +56,8 @@ public interface PlatformPluginDelegate { * androidx.activity.OnBackPressedDispatcher} will be executed. */ boolean popSystemNavigator(); + + void navigatorIsEmpty(); } @VisibleForTesting @@ -111,6 +113,7 @@ public void setSystemUiOverlayStyle( @Override public void navigatorIsEmpty() { + Log.e("justin", "navigatorIsEmpty in PlatformHandler.PlatformMessageChannel."); PlatformPlugin.this.navigatorIsEmpty(); } @@ -482,8 +485,7 @@ private void setSystemChromeSystemUIOverlayStyle( private void navigatorIsEmpty() { Log.e("justin", "navigatorIsEmpty in PlatformPlugin"); - // TODO(justinmc): Can't quite call it like this, need FlutterActivity. - // activity.unregisterOnBackInvokedCallback(); + platformPluginDelegate.navigatorIsEmpty(); } private void popSystemNavigator() {