Skip to content

Scrollbar should have option to specify effective depth for nested scrollable #36474

Closed

Description

@coreysprague

Horizontal Scrollables in a list view are causing the Scrollbars of the containing Scrollable to be drawn. Ideally, the Scrollbar would only show for the axis of the immediate Scrollable descendent, or perhaps allow consumers to specify the allowed depth of Scrollable to listen to.

Steps to Reproduce

  1. Create a ListView and Wrap with a Scrollbar widget
  2. Place a horizontal PageView widget in a list item
  3. Swipe the PageView
  4. Observe that the scrollbar for the ListView is scrolling horizontally

I created a sample app to demonstrate:
https://github.com/coreysprague/flutter_nested_pageview_scrollbars

flutter doctor -v
[✓] Flutter (Channel unknown, v1.7.8+hotfix.3, on Mac OS X 10.14.5 18F132,
locale en-US)
• Flutter version 1.7.8+hotfix.3 at /Users/cosprague/Library/Code/flutter
• Framework revision b712a17 (9 days ago), 2019-07-09 13:14:38 -0700
• Engine revision 54ad777fd2
• Dart version 2.4.0

[✓] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
• Android SDK at /Users/cosprague/Library/Android/sdk
• Android NDK location not configured (optional; useful for native profiling support)
• Platform android-28, build-tools 28.0.3
• ANDROID_HOME = /Users/cosprague/Library/Android/sdk
• Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1343-b01)
• All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 10.2.1)
• Xcode at /Applications/Xcode.app/Contents/Developer
• Xcode 10.2.1, Build version 10E1001
• CocoaPods version 1.7.1

[✓] iOS tools - develop for iOS devices
• ios-deploy 1.9.4

[✓] Chrome - develop for the web
• Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 3.4)
• Android Studio at /Applications/Android Studio.app/Contents
• Flutter plugin version 36.0.1
• Dart plugin version 183.6270
• Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1343-b01)

[✓] VS Code (version 1.36.1)
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension version 3.2.0

[✓] Connected device (3 available)
• iPhone Xs • CB2CBFCD-D56F-412E-B17C-B5908F7D749E • ios •
com.apple.CoreSimulator.SimRuntime.iOS-12-2 (simulator)
• macOS • macOS • darwin-x64 • Mac OS X 10.14.5 18F132
• web • web • web-javascript • Google Chrome 75.0.3770.142

• No issues found!

Activity

  1. added
    f: scrolling
    c: regression
    on Jul 18, 2019
  2. coreysprague commented on Jul 19, 2019

    @coreysprague
    Author

    I found a workaround for this. I can wrap the nested scrollview with this code:

    NotificationListener<ScrollNotification>(
              onNotification: (notification) => true,
              child: <nested scrollview>
    );
    

    this will prevent the notification event from bubbling up to the parent scrollview.

    I was also able to solve it by forking Scrollbar & CupertinoScrollbar and doing an early return in the scroll handler if the depth was greater than 0 (but the earlier solution of trapping the notification is more elegant).

    Regardless, the current default behavior doesn't seem intuitive or allow people to fall into the pit of success.

  3. added
    framework
    on Nov 26, 2019
  4. Piinks commented on Feb 27, 2020

    @Piinks
    Contributor

    Hey @coreysprague Thanks for bring this to our attention, and for the really good reproduction.

    I am not sure this is a regression, I checked out 1.5.4 and ran your repro and found that the Scrollbars are still there, they are just a little less noticeable along the edges of the screen.
    I think they are more apparent in 1.7.8 because #31763 added padding to the Scrollbars, bringing them more into view.

    I don't know what the expected behavior should be here then. I could see expecting either case (to show the Scrollbar or not) depending on the situation. Perhaps this is something we can make configurable on the Scrollbar?

  5. added
    c: new feature
    waiting for response
    and removed
    c: regression
    on Feb 27, 2020
  6. coreysprague commented on Feb 27, 2020

    @coreysprague
    Author

    Hi @Piinks

    Making it configurable on the ScrollBar would make sense. It seems like it would make the most sense to default the behavior to only respond to scroll notifications from the immediate descendent, and optionally respond to all? That would of course be a breaking change, but I think it would be the case that most use cases would expect.

  7. removed
    waiting for response
    on Feb 27, 2020
  8. changed the title [-]Nested Scrollable is displaying Scrollbars on outer Scrollable in Flutter 1.7.8-hotfix-3[/-] [+]Scrollbar should have option to specify effective depth for nested scrollable[/+] on Feb 27, 2020
  9. Piinks commented on Feb 27, 2020

    @Piinks
    Contributor

    Thanks for coming back! :)
    That sounds like a good idea to me! We try not to make breaking changes, so we may configure it the other way around where the default behavior is the current behavior. That way no one is broken.

  10. coreysprague commented on Mar 6, 2020

    @coreysprague
    Author

    @Piinks -- I just wanted to throw out another thought that might also address this problem (and maybe is easier to solve).

    I suspect this issue is primarily isolated to when you have nested content that scrolls perpendicular to the parent's scrollview

    I wonder if instead of making Scrollbar aware of nesting... if instead scrollbar could have a property to define which axes to show the scroll indicators. It could default to both horizontal & vertical, but an optional parameter could specify vertical only (or horizontal only).

    I could see this feature potentially having value outside of the nesting use case as well.

  11. added
    customer: gallery
    on May 5, 2020
  12. carmas123 commented on Aug 2, 2020

    @carmas123

    I think that the ScrollBar need to be visibile only for direct child and not for all tree.
    If I've a multiple childs into a SingleChildScrollView and I want to show scrollbar for all childs the ScrollBar widget must have a simple parameter like "infiniteDeep" that make to be able to have scrollbar for all the tree.
    But if I need to have the scrollbar only for the main container like a SingleChildScrollView I leave this parameter false or
    as said by @coreysprague we need to have a parameter to specify the effective depth of scrollbar.

  13. simrat39 commented on Sep 1, 2020

    @simrat39

    I found a workaround for this. I can wrap the nested scrollview with this code:

    NotificationListener<ScrollNotification>(
              onNotification: (notification) => true,
              child: <nested scrollview>
    );
    

    this will prevent the notification event from bubbling up to the parent scrollview.

    I was also able to solve it by forking Scrollbar & CupertinoScrollbar and doing an early return in the scroll handler if the depth was greater than 0 (but the earlier solution of trapping the notification is more elegant).

    Regardless, the current default behavior doesn't seem intuitive or allow people to fall into the pit of success.

    Thanks! Works perfect for me
    For anyone who has a lot of scrollviews, you can use this extension:

    import 'package:flutter/material.dart';
    
    extension NestedScrollFixExtension on Widget {
      Widget fixNestedDoubleScrollbar() {
        return NotificationListener<ScrollNotification>(
          onNotification: (notification) => true,
          child: this,
        );
      }
    }
    
  14. added
    P2
    on Sep 29, 2020
  15. pedromassangocode commented on Dec 9, 2020

    @pedromassangocode

    I was able to reproduce this with the latest master and beta channel. Code based on #66444 that was closed as duplicate.

    I don't see this as new feature but as a bug because it is an unwanted behavior comparing with the native implementations. So, removing new feature label. Feel free to add it back if I'm wrong.

    Edit: Ok, this seems to a new feature, @Piinks I think this is not similar to #66444. I see #66444 as to not show/scroll multiple scrollbar when only one should scroll. See image bellow.

    flutter doctor -v
    [✓] Flutter (Channel beta, 1.24.0-10.2.pre, on Mac OS X 10.15.7 19H2 darwin-x64, locale en)
        • Flutter version 1.24.0-10.2.pre at /Users/pedromassango/dev/SDKs/flutter_beta
        • Framework revision 022b333a08 (3 weeks ago), 2020-11-18 11:35:09 -0800
        • Engine revision 07c1eed46b
        • Dart version 2.12.0 (build 2.12.0-29.10.beta)
    
    [✓] Android toolchain - develop for Android devices (Android SDK version 30.0.2)
        • Android SDK at /Users/pedromassango/Library/Android/sdk
        • Platform android-30, build-tools 30.0.2
        • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
        • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6915495)
        • All Android licenses accepted.
    
    [✓] Xcode - develop for iOS and macOS (Xcode 12.1)
        • Xcode at /Applications/Xcode.app/Contents/Developer
        • Xcode 12.1, Build version 12A7403
        • CocoaPods version 1.9.3
    
    [✓] Chrome - develop for the web
        • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
    
    [✓] Android Studio (version 4.1)
        • Android Studio at /Applications/Android Studio.app/Contents
        • Flutter plugin can be installed from:
          🔨 https://plugins.jetbrains.com/plugin/9212-flutter
        • Dart plugin can be installed from:
          🔨 https://plugins.jetbrains.com/plugin/6351-dart
        • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6915495)
    
    [✓] IntelliJ IDEA Community Edition (version 2020.2.4)
        • IntelliJ at /Applications/IntelliJ IDEA CE.app
        • Flutter plugin version 52.0.4
        • Dart plugin version 202.8070
    
    [✓] VS Code (version 1.51.1)
        • VS Code at /Applications/Visual Studio Code.app/Contents
        • Flutter extension version 3.16.0
    
    [✓] Connected device (2 available)
        • Web Server (web) • web-server • web-javascript • Flutter Tools
        • Chrome (web)     • chrome     • web-javascript • Google Chrome 87.0.4280.88
    
    • No issues found!
    Process finished with exit code 0
    
  16. added
    found in release: 1.24
    found in release: 1.25
    has reproducible steps
    c: new feature
    and removed
    c: new feature
    on Dec 9, 2020
  17. alaydeliwala commented on Jan 4, 2021

    @alaydeliwala

    I found a workaround for this. I can wrap the nested scrollview with this code:

    NotificationListener<ScrollNotification>(
              onNotification: (notification) => true,
              child: <nested scrollview>
    );
    

    this will prevent the notification event from bubbling up to the parent scrollview.
    I was also able to solve it by forking Scrollbar & CupertinoScrollbar and doing an early return in the scroll handler if the depth was greater than 0 (but the earlier solution of trapping the notification is more elegant).
    Regardless, the current default behavior doesn't seem intuitive or allow people to fall into the pit of success.

    Thanks! Works perfect for me
    For anyone who has a lot of scrollviews, you can use this extension:

    import 'package:flutter/material.dart';
    
    extension NestedScrollFixExtension on Widget {
      Widget fixNestedDoubleScrollbar() {
        return NotificationListener<ScrollNotification>(
          onNotification: (notification) => true,
          child: this,
        );
      }
    }
    

    I tried this and it worked (partially). With this workaround, a double scrollbar does not show up, however, no scrollbar shows up for the nested scroll view. Is there a workaround for that?

    scrollbar issue

    As you can see in the gif above, the vertical scroll displays a scrollbar but when I try to scroll horizontally on the call field, no scrollbar shows up.

  18. github-actions commented on Aug 7, 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.

  19. locked as resolved and limited conversation to collaborators on Aug 7, 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

    P2c: new featurecustomer: gallerycustomer: web10f: scrollingfound in release: 1.24found in release: 1.25frameworkhas reproducible steps

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions