Skip to content

Conversation

@PaulGrandperrin
Copy link

This is a minimal effort patch that I'm using to fix some of the issues I had with the back gesture animation described in: #153577

This fixes:

  1. the front page abruptly disappears when swiping across 35% of the screen
  2. the front page ignore if the gesture started from the left or right edge
  3. the front page don't go up and down following finger
  4. the animation goes way too fast (<100ms, should be ~300ms)
  5. the animation blocks all user inputs for about 700ms after the animation is visually finished
  6. the animation is the same as the "pre-commit" one, which is not what happens in the rest of Android and in the spec.

This doesn't fix:

  1. the back page ignore if the gesture started from the left or right edge
  2. the back page don't go up and down following finger

The patch is very low effort, and I'm a newbie with flutter. It's the first time I write animation code..
I know I'm supposed to use Tweens, but I'm not used to them and I just wrote what was most intuitive for me, ATM.
My animation algorithm is very ugly, but there would need deeper breaking changes to route.dart to be fixed correctly.

All this to say that this PR is not supposed to be merged. I hope it could be useful to someone to willing to contribute a better PR to the codebase, but that would need a lot deeper changes to adapt the design to how the back gestures work on Android, which is very different from iOS.

Actually, maybe I'll propose better code in the future if I feel like spending more time on this.

@github-actions github-actions bot added framework flutter/packages/flutter repository. See also f: labels. f: material design flutter/packages/flutter/material repository. f: routes Navigator, Router, and related APIs. labels Aug 17, 2024
@github-actions github-actions bot added engine flutter/engine related. See also e: labels. team-release d: docs/ flutter/flutter/docs, for contributors labels Aug 17, 2024
@github-actions github-actions bot removed engine flutter/engine related. See also e: labels. team-release d: docs/ flutter/flutter/docs, for contributors labels Aug 17, 2024
@PaulGrandperrin
Copy link
Author

To replicate the native back gesture animation, both the front and the back page need to have access to the BackEvents data.

One solution could be to change WidgetBinding::_handleStartBackGesture() to allow registering 2 observers in _backGestureObserver instead of one, but that feels hacky IMO.

Another one could be to make the Navigator or the Router receive the BackEvents and then forward them to the 2 relevant PageRoutes.

I just started glancing at how those classes interact with each other, but it seems to me that Router is the better candidate.

It's documentation states that it's "The dispatcher for opening and closing pages of an application" and it's already responsible for the BackButtonDispacher. I also guess that there should only be one active Router per app when there could be many Navigators.

I'll try moving the reception of BackEvents to the Router and see where it lead me.

@justinmc
Copy link
Contributor

I left a comment on the issue (#153577 (comment)) about what the transition should look like. Let's leave this PR open until @maRci002 or I pick up the work of making it look like that transition. I'm sure any future work will take inspiration from this, so thank you for the work on this PR.

I took some time to investigate how the classic back button events are dispatched, and I was thinking that in theory, the back gesture events should follow the same path. What do you think?

Are you talking about WidgetsBinding.handlePopRoute versus WidgetsBinding._handleStartBackGesture etc.?

@justinmc
Copy link
Contributor

I tried this out locally and it does look pretty close to the correct Shared Element transition!

@Piinks
Copy link
Contributor

Piinks commented Nov 19, 2024

(PR Triage): Hey @justinmc is this still on your radar to adopt in the future?

@justinmc
Copy link
Contributor

@PaulGrandperrin Are you still around and able to fix the merge conflicts?

I'm planning to try to update the animation this quarter by taking a look at this PR and #154718.

@Piinks
Copy link
Contributor

Piinks commented Mar 25, 2025

Hey @PaulGrandperrin thanks for sending this PR, @justinmc has now picked up #153577 to resolve. I am going to close this PR, but really appreciate your contributions here. Thanks!

@Piinks Piinks closed this Mar 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

f: material design flutter/packages/flutter/material repository. f: routes Navigator, Router, and related APIs. framework flutter/packages/flutter repository. See also f: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants