Skip to content

Snap CupertinoSliverNavigationBar large title and bottom widget - #156381

Merged
auto-submit[bot] merged 22 commits into
flutter:masterfrom
victorsanni:snap-large-title
Oct 18, 2024
Merged

Snap CupertinoSliverNavigationBar large title and bottom widget#156381
auto-submit[bot] merged 22 commits into
flutter:masterfrom
victorsanni:snap-large-title

Conversation

@victorsanni

@victorsannivictorsanni commented Oct 8, 2024

Copy link
Copy Markdown
Contributor

FixesCupertinoSliverNavigationBar should snap between large and middle title
FixesCupertinoSliverNavigationBar 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-actionsgithub-actionsBot added framework flutter/packages/flutter repository. See also f: labels. p: cupertino_ui cupertino_ui package in flutter/packages labels Oct 8, 2024
@victorsanni
victorsanni marked this pull request as ready for review October 11, 2024 20:56

@MitchellGoodwinMitchellGoodwin left a comment

Copy link
Copy Markdown
Contributor

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
Copy Markdown
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
Copy Markdown
ContributorAuthor

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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
ContributorAuthor

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
Copy Markdown
ContributorAuthor

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
Copy Markdown
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
Copy Markdown
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.

Comment threadpackages/flutter/lib/src/cupertino/nav_bar.dart Outdated

@MitchellGoodwinMitchellGoodwin left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM!

@victorsanni

Copy link
Copy Markdown
ContributorAuthor

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
Copy Markdown
ContributorAuthor

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
@victorsannivictorsanni changed the title Snap CupertinoSliverNavigationBar large titleSnap CupertinoSliverNavigationBar large title and bottom widgetOct 16, 2024

@MitchellGoodwinMitchellGoodwin left a comment

Copy link
Copy Markdown
Contributor

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.

Comment threadpackages/flutter/test/cupertino/nav_bar_test.dart
Comment threadpackages/flutter/test/cupertino/nav_bar_test.dart

@PiinksPiinks left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

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

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

Copy link
Copy Markdown

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-queueBot 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
chunhtai pushed a commit to chunhtai/packages that referenced this pull request Jun 12, 2026
…y scrolled in .always bottom mode (#162425)
Forgot to add these in flutter/flutter#156381.
Spotted it when debugging
flutter/flutter#159120.
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

autosubmitMerge PR when tree becomes green via auto submit Appframeworkflutter/packages/flutter repository. See also f: labels.p: cupertino_uicupertino_ui package in flutter/packages

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

@victorsanni@Piinks@b3nni97@MitchellGoodwin