Skip to content

RouteObserver/NavigatorObserver.didPop no longer called on iOS back swipe #29596

Closed

Description

@1AlexFix1

Hello, on master, deb, beta channel didPop no calls, it is bad, because need check screen pop,

final RouteObserver<PageRoute> routeObserver = RouteObserver<PageRoute>();

class _BaseWidgetState extends State<BaseWidget>
    with RouteAware, WidgetsBindingObserver {

@override
  void initState() {
    super.initState();
    WidgetsBinding.instance.addObserver(this);
  }

@override
  void didChangeDependencies() {
    super.didChangeDependencies();
    routeObserver.subscribe(this, ModalRoute.of(context));
  }

  @override
  void didPushNext() {
    super.didPushNext();
    print('didPushNext');
    if (widget.pushNext != null) widget.pushNext();
  }

  @override
  void didPop() {
    super.didPop();
    print('didPop');
    if (widget.pop != null) widget.pop();
  }

  @override
  void didPopNext() {
    super.didPopNext();
    print('didPopNext');
    if (widget.popNext != null) widget.popNext();
  }

  @override
  void didPush() {
    super.didPush();
    print('didPush');
    if (widget.push != null) widget.push();
  }

  @override
  void dispose() {
    routeObserver.unsubscribe(this);
    WidgetsBinding.instance.removeObserver(this);
    super.dispose();
  }

}

I test channel

  1. stable
    //push next screen
    flutter: didPushNext
    flutter: didPush
    -----swipe screen(iOS)
    flutter: didPopNext
    flutter: didPop
    -----touch back button (Android)
    flutter: didPopNext
    flutter: didPop

test: successful

  1. master
    //push next screen
    flutter: didPushNext
    flutter: didPush
    -----swipe screen(iOS)
    no reaction!!!
    -----touch back button (Android)
    flutter: didPopNext
    flutter: didPop

  2. dev
    //push next screen
    flutter: didPushNext
    flutter: didPush
    ----- swipe screen(iOS)
    no reaction!!!
    -----touch back button (Android)
    flutter: didPopNext
    flutter: didPop

  3. beta
    //push next screen
    flutter: didPushNext
    flutter: didPush
    -----swipe screen(iOS)
    no reaction!!!
    -----touch back button (Android)
    flutter: didPopNext
    flutter: didPop

Flutter 1.3.12-pre.29 • channel master • https://github.com/flutter/flutter.git
Framework • revision af6e09f (34 hours ago) • 2019-03-18 21:40:21 -0700
Engine • revision 5088735
Tools • Dart 2.2.1 (build 2.2.1-dev.1.0 None)

Running flutter doctor...
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel master, v1.3.14-pre.7, on Mac OS X 10.14.3 18D109, locale ru-RU)
[✓] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
[✓] iOS toolchain - develop for iOS devices (Xcode 10.1)
[✓] Android Studio (version 3.3)
[✓] Connected device (1 available)

• No issues found!

Activity

  1. changed the title [-]RouteObserver can't didPop[/-] [+]RouteObserver can't call didPop on iOS Swipe[/+] on Mar 19, 2019
  2. msw333 commented on Mar 20, 2019

    @msw333

    Might be related to #28756

  3. added
    frameworkflutter/packages/flutter repository. See also f: labels.
    on Mar 26, 2019
  4. xster commented on Mar 26, 2019

    @xster
    Member

    Can you help us clarify what is the API you're trying to use? Since there are 2 'iOS swipe' mechanism that may be relevant to your described issue.

    On the one hand, Flutter itself handles iOS back swipes within the Flutter navigation mechanism. That's related to #28756 but not related to WidgetsBinding etc.

    On the other hand, you might be referring to executing an iOS back swipe one level higher on a FlutterViewController part of a UINavigationController that you have in your own native project. And you're manually calling FlutterViewController.popRoute. In that case, it's related to WidgetsBinding.

    These 2 things are somewhat orthogonal. What scenario are you referring to?

  5. added
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Mar 26, 2019
  6. 1AlexFix1 commented on Mar 26, 2019

    @1AlexFix1
    Author

    Can you help us clarify what is the API you're trying to use? Since there are 2 'iOS swipe' mechanism that may be relevant to your described issue.

    On the one hand, Flutter itself handles iOS back swipes within the Flutter navigation mechanism. That's related to #28756 but not related to WidgetsBinding etc.

    On the other hand, you might be referring to executing an iOS back swipe one level higher on a FlutterViewController part of a UINavigationController that you have in your own native project. And you're manually calling FlutterViewController.popRoute. In that case, it's related to WidgetsBinding.

    These 2 things are somewhat orthogonal. What scenario are you referring to?

    I do Navigator.pushNamed then I do the swipe back and I do not get the message about didPop,

  7. removed
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Mar 26, 2019
  8. added
    d: api docsIssues with https://api.flutter.dev/
    f: routesNavigator, Router, and related APIs.
    and removed
    p: cupertino_uicupertino_ui package in flutter/packages
    on Mar 26, 2019
  9. xster commented on Mar 26, 2019

    @xster
    Member

    Thanks for the response. This might be a bug in our documentation for not being clearer. Those are orthogonal mechanisms. WidgetsBinding only observes platform triggered navigations against the ViewController or Activity etc.

    To observe the Flutter side Navigator, pass a NavigatorObserver list into the Navigator constructor (or the Material/CupertinoApp etc).

    Did I interpret the question correctly?

  10. 1AlexFix1 commented on Mar 27, 2019

    @1AlexFix1
    Author

    Thanks for the response. This might be a bug in our documentation for not being clearer. Those are orthogonal mechanisms. WidgetsBinding only observes platform triggered navigations against the ViewController or Activity etc.

    To observe the Flutter side Navigator, pass a NavigatorObserver list into the Navigator constructor (or the Material/CupertinoApp etc).

    Did I interpret the question correctly?

    I think I understood, I'm sorry, I did not provide the full information in the question (full code), I, of course, pass the routeObserver to MaterialApp, I did everything as in the documentation https: //docs.flutter .io / flutter / widgets / RouteObserver -class.html and everything works fine on a stable branch, but on the remaining 3 branches didpop flutter is not called when swipe, if there was a transition using CupertinoPageRoute, however, if you press the button on android onBack, didPop is called

  11. msw333 commented on Mar 29, 2019

    @msw333

    Thanks for the response. This might be a bug in our documentation for not being clearer. Those are orthogonal mechanisms. WidgetsBinding only observes platform triggered navigations against the ViewController or Activity etc.

    To observe the Flutter side Navigator, pass a NavigatorObserver list into the Navigator constructor (or the Material/CupertinoApp etc).

    Did I interpret the question correctly?

    Can you show us how (example code)? There is no documentation on this. I think most people (including me) do it like this:

    final RouteObserver<PageRoute> routeObserver = new RouteObserver<PageRoute>();
    main() {..}
    
    MaterialApp(
    navigatorObservers: <NavigatorObserver>[routeObserver], ...)
    
    class SingleChatScreenState extends State<SingleChatScreen>
        with RouteAware {...
    
     void didPop() {
        print('Screen closed');
      }
    }
    
  12. 8 remaining items

  13. xster commented on Mar 29, 2019

    @xster
    Member

    Yes, it is related to #28728, which makes the solution to this tricky too. If you popped something and while it's animating, pushed something else, what should we call on the NavigatorObserver? Calling didPop is ambiguous because the route that's popped is no longer the top route by the time it's called.

  14. alexelsn commented on Apr 2, 2019

    @alexelsn

    We are also desperately waiting for a fix. Do you have any update guys ;-)?

  15. xster commented on Apr 3, 2019

    @xster
    Member

    As @Hixie suggested, since the navigation is 'committed' as soon as the back swipe gesture's pointer is lifted, we can let the pop happen at the start of the final snap animation instead of at the end of it.

  16. xster commented on Apr 3, 2019

    @xster
    Member

    It can probably be worked out but it turned out not as easy as I thought because by calling pop earlier the TransitionRoute.didPop is rather specific on how it animates


    whereas we want to be very particular about the snapping animation, duration and curve when we drop the back swipe gesture.

  17. msw333 commented on Apr 6, 2019

    @msw333

    @xster, can you elaborate on the 'hacky' solution. I am doing the following and it is not triggered when page pops. Maybe I am missing out 'route' and 'previousRoute'? No idea what to insert. I haven't named my routes, but rely on Navigator.push:

    final NavigatorObserver navigatorObserver = new NavigatorObserver();
    main() {..}
    MaterialApp(
    navigatorObservers: <NavigatorObserver>[navigatorObserver]... )
    
    
    class ChatScreenState extends State<ChatScreen> with NavigatorObserver { ...
    
    @override
    void didRemove(Route<dynamic> route, Route<dynamic> previousRoute) async{  
    
    // I PLACE THE ASYNC FUNCTIONS HERE, WHICH I WOULD LIKE TO BE TRIGGERED WHEN PAGE POPS
    
      }
    }
    
  18. xster commented on Apr 8, 2019

    @xster
    Member

    Since the fix is out in #30422, you could potentially just patch the PR into your Flutter SDK and keep using didPop.

  19. msw333 commented on Apr 8, 2019

    @msw333

    Any idea when it will be merged into the master? Not feeling well messing around on the SDK.

  20. xster commented on Apr 17, 2019

    @xster
    Member

    Sorry for the wait all. It's been fixed on master.

  21. msw333 commented on Apr 20, 2019

    @msw333

    Leads to a new behavior on my iPhone X. After some 'using' of swipe gestures, they stop working. I can then only get back via BackButton. Then animation is much slower.

  22. alexelsn commented on Apr 22, 2019

    @alexelsn

    Yes, the fix was also pretty important for us. But now, after some time, the swipe back stops working. Hope for new fix asap :-)

  23. xster commented on Apr 23, 2019

    @xster
    Member

    Thanks for reporting. #31471

  24. github-actions commented on Aug 30, 2021

    @github-actions

    This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

  25. locked as resolved and limited conversation to collaborators on Aug 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    c: regressionIt was better in the past than it is nowf: routesNavigator, Router, and related APIs.frameworkflutter/packages/flutter repository. See also f: labels.p: cupertino_uicupertino_ui package in flutter/packagesplatform-iosiOS applications specificallywaiting for PR to land (fixed)A fix is in flight

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions