Skip to content

Commit

Permalink
navigationStackIsEmpty method to enable predictive back
Browse files Browse the repository at this point in the history
  • Loading branch information
justinmc committed Feb 8, 2023
1 parent 9c0e7cc commit 205d1e5
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -666,14 +666,21 @@ 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(
OnBackInvokedDispatcher.PRIORITY_DEFAULT, onBackInvokedCallback);
}
}

@Override
public void navigatorIsEmpty() {
Log.e("justin", "navigatorIsEmpty in embedding FlutterActivity");
unregisterOnBackInvokedCallback();
}

/**
* Unregisters the callback from OnBackInvokedDispatcher.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ public interface PlatformPluginDelegate {
* androidx.activity.OnBackPressedDispatcher} will be executed.
*/
boolean popSystemNavigator();

void navigatorIsEmpty();
}

@VisibleForTesting
Expand Down Expand Up @@ -111,6 +113,7 @@ public void setSystemUiOverlayStyle(

@Override
public void navigatorIsEmpty() {
Log.e("justin", "navigatorIsEmpty in PlatformHandler.PlatformMessageChannel.");
PlatformPlugin.this.navigatorIsEmpty();
}

Expand Down Expand Up @@ -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() {
Expand Down

0 comments on commit 205d1e5

Please sign in to comment.