Skip to content

Conversation

@victorsanni
Copy link
Contributor

@victorsanni victorsanni commented Oct 8, 2024

Fixes CupertinoSliverNavigationBar should snap between large and middle title
Fixes CupertinoSliverNavigationBar needs to implement snapping

Flutter (with this PR):

Screen.Recording.2024-10-16.at.4.26.18.PM.mov

Native:

Screen.Recording.2024-10-16.at.4.28.17.PM.mov

Pre-launch Checklist

If you need help, consider asking for advice on the #hackers-new channel on Discord.

@github-actions github-actions bot added framework flutter/packages/flutter repository. See also f: labels. f: cupertino flutter/packages/flutter/cupertino repository labels Oct 8, 2024
@victorsanni victorsanni marked this pull request as ready for review October 11, 2024 20:56
Copy link
Contributor

@MitchellGoodwin MitchellGoodwin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was ScrollEndNotification unable to be used for this? Just following up on this comment: #126028 (comment)

: 0.0,
// Eyeballed on an iPhone 16 simulator running iOS 18.
duration: const Duration(milliseconds: 100),
curve: Curves.easeOut,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To my eye, the animation isn't snappy enough. I wonder if the curve should have a faster start. On iOS it might be a spring animation.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, tbh I don't know what animation curve or values are used. The native one seems more snappy, but not too fast at the same time. If only there was a way to get these values...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe Curves.easeOutExpo? That one seems to start off faster. There is a helpful video with graphs and sample animation for every curve at https://api.flutter.dev/flutter/animation/Curves-class.html

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a strong suspicion that it's a spring animation. That's what iOS uses for releasing a partially dragged page transition. There is a way to check with Xcode debugging, but I do not remember off the top of my head. @dkwingsmt was working with using the spring simulation for an animation: #155575

But my opinion for this PR is it's fine to use a curve we already have for now, but one that's closer. fastEaseInToSlowEaseOut is what the Cupertino routes use.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

easeOutExpo started a little bit too fast, but fastEaseInToSlowEaseOut was closer-ish. It's not perfect but definitely better.

@victorsanni
Copy link
Contributor Author

Was ScrollEndNotification unable to be used for this?

I was having difficulty making scroll notifications and scroll position play well together. I added a listener to be called on ScrollNotifications, but when I tried to animate the scroll position within that listener, it didn't work. So I added a separate listener for the scroll position, and tried making both callbacks talk to each other, but that also didn't work.

I agree that responding to ScrollEndNotifications seems like the most intuitive way to do this. I think Hans' examples worked with ScrollNotifications because it had control of the parent CustomScrollView and so could wrap it directly in a NotificationListener. But it's trickier to do (but maybe there is a way to do it) when we're entirely within a sliver within the CustomScrollView and can only look up the tree with inherited widgets.

: 0.0,
// Eyeballed on an iPhone 16 simulator running iOS 18.
duration: const Duration(milliseconds: 100),
curve: Curves.easeOut,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe Curves.easeOutExpo? That one seems to start off faster. There is a helpful video with graphs and sample animation for every curve at https://api.flutter.dev/flutter/animation/Curves-class.html

@override
void didChangeDependencies() {
super.didChangeDependencies();
_scrollableState?.position.isScrollingNotifier.removeListener(_handleScrollChange);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using the isScrollingNotifier makes sense to me. It will only notify when scrolling starts and stops, which is exactly what is needed here. 👍 Using scroll notifications would mean a lot of notifications we would not need.

Copy link
Contributor

@MitchellGoodwin MitchellGoodwin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@victorsanni
Copy link
Contributor Author

Converting to draft... Since the bottom to nav bar PR has been merged, I'm working to make it snap for both the search bar and the large title.

@victorsanni victorsanni marked this pull request as draft October 16, 2024 19:48
@victorsanni
Copy link
Contributor Author

Snapping only the large title causes problems in NavigationBarBottomMode.automatic, since the search bar scrolls first instead of the large title (so we should be using the search bar height to snap first, not the large title height).

@victorsanni victorsanni marked this pull request as ready for review October 16, 2024 22:36
@victorsanni victorsanni changed the title Snap CupertinoSliverNavigationBar large title Snap CupertinoSliverNavigationBar large title and bottom widget Oct 16, 2024
Copy link
Contributor

@MitchellGoodwin MitchellGoodwin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renewing my LGTM with some nits.

Copy link
Contributor

@Piinks Piinks left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@victorsanni victorsanni added the autosubmit Merge PR when tree becomes green via auto submit App label Oct 18, 2024
@auto-submit auto-submit bot merged commit 83a0b85 into flutter:master Oct 18, 2024
@victorsanni victorsanni deleted the snap-large-title branch October 18, 2024 20:32
}

if (target != null) {
position.animateTo(
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using 'animateTo' can be very risky as it breaks the entire scrollable widget if one attempts to scroll within the 300ms timeframe (refer to issue #14452). This issue is easily reproducible by increasing the animation duration and trying to scroll the CustomScrollView during that period. Subsequently, assertions fail, such as '_hold == null || _drag == null'.

github-merge-queue bot pushed a commit that referenced this pull request Jan 30, 2025
…y scrolled in .always bottom mode (#162425)

Forgot to add these in #156381.
Spotted it when debugging
#159120.
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 12, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 13, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 13, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 6, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

autosubmit Merge PR when tree becomes green via auto submit App f: cupertino flutter/packages/flutter/cupertino repository framework flutter/packages/flutter repository. See also f: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CupertinoSliverNavigationBar should snap between large and middle title CupertinoSliverNavigationBar needs to implement snapping

4 participants