auto_route_library icon indicating copy to clipboard operation
auto_route_library copied to clipboard

BackGesture is disabled only on iOs when using @CustomRoute

Open wer-mathurin opened this issue 2 years ago • 13 comments

Is there any tricks we can use to enable that?

wer-mathurin avatar May 25 '22 14:05 wer-mathurin

@wer-mathurin BackGesture is enabled in Custom routes? I'm not sure I understand your question!

Milad-Akarie avatar May 26 '22 13:05 Milad-Akarie

@Milad-Akarie If you have a theme like this

final ThemeData myTheme = ThemeData(
  pageTransitionsTheme: const PageTransitionsTheme(builders: {
    TargetPlatform.iOS: CupertinoPageTransitionsBuilder(),
    TargetPlatform.android: FadeUpwardsPageTransitionsBuilder(),
  }),
)

If i'm using AutoRoute(page:xxxxxx) Back gesture is working fine on Android and iOS

if you change it to CustomRoute(page:xxxxxx) BackGesture is working only on Android

wer-mathurin avatar May 26 '22 14:05 wer-mathurin

@wer-mathurin are you using a CupertinoAutoRouter?

Milad-Akarie avatar May 26 '22 14:05 Milad-Akarie

@Milad-Akarie : AdaptiveAutoRouter

wer-mathurin avatar May 26 '22 14:05 wer-mathurin

@wer-mathurin I'm confused because it doesn't make sense to me that BackGesture is enabled on Android.

Milad-Akarie avatar May 26 '22 14:05 Milad-Akarie

@Milad-Akarie I wrap my Widget in a WillPopScope, doing some action and eventually calling context.router.pop() That's is doing the trick for Android, but that's why I'm focussing on the iOS problem.

Just changing from AutoRoute to CustomRoute the behavior change without changing the code

wer-mathurin avatar May 26 '22 14:05 wer-mathurin

@wer-mathurin AutoRoute inherits it's type from AdaptiveAutoRouter so it becomes AdaptiveRoute, which on IOS uses CupertinoRoute

Milad-Akarie avatar May 26 '22 15:05 Milad-Akarie

@wer-mathurin are you saying that your problem is on IOS will pop scope is not triggered when using BackGesture?

Milad-Akarie avatar May 26 '22 15:05 Milad-Akarie

@Milad-Akarie Good catch. Is this something you can do in the library while they fix the problem https://github.com/flutter/flutter/issues/14203#issuecomment-540663717

wer-mathurin avatar May 26 '22 15:05 wer-mathurin

@wer-mathurin the problem is with the WillPopScope on ios when using CupertinoRoute there isn't any workaround unless you rewrite the CupertinoPageRoute class

 bool get popGestureEnabled => _isPopGestureEnabled(this);

  static bool _isPopGestureEnabled<T>(PageRoute<T> route) {
    // If there's nothing to go back to, then obviously we don't support
    // the back gesture.
    if (route.isFirst)
      return false;
    // If the route wouldn't actually pop if we popped it, then the gesture
    // would be really confusing (or would skip internal routes), so disallow it.
    if (route.willHandlePopInternally)
      return false;
    // If attempts to dismiss this route might be vetoed such as in a page
    // with forms, then do not allow the user to dismiss the route with a swipe.
    if (route.hasScopedWillPopCallback)
      return false;
    // Fullscreen dialogs aren't dismissible by back swipe.
    if (route.fullscreenDialog)
      return false;
    // If we're in an animation already, we cannot be manually swiped.
    if (route.animation!.status != AnimationStatus.completed)
      return false;
    // If we're being popped into, we also cannot be swiped until the pop above
    // it completes. This translates to our secondary animation being
    // dismissed.
    if (route.secondaryAnimation!.status != AnimationStatus.dismissed)
      return false;
    // If we're in a gesture already, we cannot start another.
    if (isPopGestureInProgress(route))
      return false;

    // Looks like a back gesture would be welcome!
    return true;
  }

as you can see there it will check if there's a WillPopCallback it will prevent the user from using the gesture tho as I said you can rewrite the class so it can check the callback and determine if the user can pop or not

omaralmgerbie avatar May 28 '22 19:05 omaralmgerbie

same issue

Johnny-sel avatar Jul 03 '22 10:07 Johnny-sel

How to enable back gesture using CustomRoute on iOS @Milad-Akarie ?

feduke-nukem avatar Sep 02 '22 14:09 feduke-nukem

same problem here with IOS, and CustomRoute

xalikoutis avatar Oct 11 '22 11:10 xalikoutis