Skip to content

Improve the ScrollBar behavior when nested - #71843

Merged
fluttergithubbot merged 2 commits into
flutter:masterfrom
xu-baolin:1207scrollbar
Jan 15, 2021
Merged

fluttergithubbot merged 2 commits into
flutter:masterfrom
xu-baolin:1207scrollbar

Conversation

@xu-baolin

@xu-baolin xu-baolin commented Dec 7, 2020 •

Copy link
Copy Markdown
Member

Description

This change let the ScrollBar widget ignore the ScrollNotification message that depth not equal to zero.

This change can resolve the situation that scrolls the inner scrollable widget cause the outer scrollbar paint incorrectly such as #66444.
@Piinks Hi, please review, thanks.

Related Issues

Related #66444
Fixes #36474
Fixes #70771
Fixes #73697

Tests

I added the following tests:

See files.

@flutter-dashboard flutter-dashboard Bot added p: cupertino_ui cupertino_ui package in flutter/packages p: material_ui material_ui package in flutter/packages framework flutter/packages/flutter repository. See also f: labels. labels Dec 7, 2020
@google-cla google-cla Bot added the cla: yes label Dec 7, 2020

@Piinks Piinks 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.

Hi @xu-baolin thank you for another quality contribution!
I'm currently working on a large change to scrollbars, let's coordinate to land this once that is in since the _handleScrollNotification will be in a new class.

Also, can you ping me on discord when you have a chance? (@Piinks https://github.com/flutter/flutter/wiki/Chat)

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.

We should make this configurable, some folks may expect their nested scrollbars to show up. This would break them.
I think this is one such case #70380

@Piinks

Piinks commented Dec 7, 2020

Copy link
Copy Markdown
Contributor

Reference: #71664

@xu-baolin

Copy link
Copy Markdown
Member Author

Hi @xu-baolin thank you for another quality contribution!
I'm currently working on a large change to scrollbars, let's coordinate to land this once that is in since the _handleScrollNotification will be in a new class.

Also, can you ping me on discord when you have a chance? (@Piinks https://github.com/flutter/flutter/wiki/Chat)

Good job 👍
I have now registered an account of Discord, the same ID with GitHub.

@Piinks Piinks added f: scrolling Viewports, list views, slivers, etc. c: new feature Nothing broken; request for a new capability a: quality A truly polished experience labels Dec 8, 2020
@Piinks

Piinks commented Dec 10, 2020

Copy link
Copy Markdown
Contributor

Triage update: Waiting on #71664

@xu-baolin

Copy link
Copy Markdown
Member Author

Triage update: Waiting on #71664

#71664 There is another problem hidden here. When the cross axis of the scrollbar is also a scrollable widget, the size may exceed the screen range, and our bar is also drawn to the outside of the screen.

: size.width - thickness - crossAxisMargin - padding.right;

So for this situation, what do you think is the expected result?

Sample code(only one scrollbar can reproduce)

import 'package:flutter/material.dart';

main() => runApp(MaterialApp(home: MyApp()));

class MyApp extends StatefulWidget {
  @override
  MyAppState createState() => MyAppState();
}

class MyAppState extends State<MyApp> {
  ScrollController verticalController = ScrollController();
  ScrollController horizontalController = ScrollController();
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text('ScrollBar')),
      body: Container(
        child: SingleChildScrollView(
          controller: horizontalController,
          scrollDirection: Axis.horizontal,
          physics: const AlwaysScrollableScrollPhysics(),
          child: Scrollbar(
            controller: verticalController,
            isAlwaysShown: true,
            child: SingleChildScrollView(
              controller: verticalController,
              physics: const AlwaysScrollableScrollPhysics(),
              child: Column(
                children: [
                  Row(
                    children: [
                      Container(
                        color: Colors.yellow,
                        height: 1000,
                        width: 1000,
                      ),
                    ],
                  ),
                ],
              ),
            ),
          ),
        ),
      ),
    );
  }
}

@Piinks

Piinks commented Dec 16, 2020

Copy link
Copy Markdown
Contributor

I am not familiar with that use case, but we should file a separate bug so we can investigate. I have a few more follow up changes I'm going to make based on some early feedback on scrollbars, I'll share when I have a PR. :)

@pedromassangocode

pedromassangocode commented Jan 11, 2021 •

Copy link
Copy Markdown

Hi @xu-baolin
Can you please confirm that this PR fixes #70771 and #73697? If so, can you update this PR so that the issues get fixed once the PR is closed? Thank you.

@xu-baolin

Copy link
Copy Markdown
Member Author

an you update this

OK.

@xu-baolin

Copy link
Copy Markdown
Member Author

I am ready for review now! :)

@Piinks Piinks 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.

This looks really great - and it fixes a bunch of issues! Well done! I think we just need to touch up the docs and this is ready. :)

Comment on lines +765 to +769
/// A check that specifies whether a [ScrollNotification] should be
/// handled by this widget.
///
/// By default, checks whether `notification.depth == 0`. Set it to something
/// else for more complicated layouts.

@Piinks Piinks Jan 14, 2021 •

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.

Let's make this documentation a little clearer. Often I look to the bugs I am fixing that describe the problem to help write the docs.
Mentioning how this can be helpful when the scrollbar is wrapped around multiple or nested scroll views would be a good idea, since that appears to be the most common issue you're solving here.

@xu-baolin
xu-baolin requested a review from Piinks January 15, 2021 06:05

@Piinks Piinks 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.

Flutter_LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

a: quality A truly polished experience c: new feature Nothing broken; request for a new capability f: scrolling Viewports, list views, slivers, etc. framework flutter/packages/flutter repository. See also f: labels. p: cupertino_ui cupertino_ui package in flutter/packages p: material_ui material_ui package in flutter/packages

Projects

None yet

4 participants