Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Fix Scrollbar thumb drag behavior on desktop. #111250

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Sep 19, 2022

Conversation

TahaTesser
Copy link
Member

@TahaTesser TahaTesser commented Sep 9, 2022

fixes #107765

macOS, Windows, and Linux support dragging scrollbar from only where the thumb is pressed.

Demo: #108166 (comment)

Code Sample
import 'package:flutter/material.dart';

void main() => runApp(const MyApp());

class MyApp extends StatelessWidget {
  const MyApp({super.key, this.dark = true, this.useMaterial3 = true});

  final bool dark;
  final bool useMaterial3;

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      themeMode: dark ? ThemeMode.dark : ThemeMode.light,
      theme: ThemeData(
        useMaterial3: useMaterial3,
        brightness: Brightness.light,
        colorSchemeSeed: const Color(0xff6750a4),
      ),
      darkTheme: ThemeData(
        useMaterial3: useMaterial3,
        brightness: Brightness.dark,
        colorSchemeSeed: const Color(0xff6750a4),
      ),
      home: const Example(),
    );
  }
}

class Example extends StatelessWidget {
  const Example({super.key});

  @override
  Widget build(BuildContext context) {
    final ScrollController scrollController = ScrollController();
    final UniqueKey uniqueKey = UniqueKey();
    return Directionality(
      textDirection: TextDirection.ltr,
      child: MediaQuery(
        data: const MediaQueryData(),
        child: ScrollConfiguration(
          behavior: const ScrollBehavior().copyWith(
            scrollbars: false,
          ),
          child: PrimaryScrollController(
            controller: scrollController,
            child: RawScrollbar(
              isAlwaysShown: true,
              thumbColor: const Color(0xffff0000),
              controller: scrollController,
              child: CustomScrollView(
                primary: true,
                // scrollDirection: Axis.horizontal,
                // center: uniqueKey,
                slivers: <Widget>[
                  SliverToBoxAdapter(
                    child: Container(
                      height: 600.0,
                    ),
                  ),
                  SliverToBoxAdapter(
                    key: uniqueKey,
                    child: Container(
                      height: 600.0,
                    ),
                  ),
                  SliverToBoxAdapter(
                    child: Container(
                      height: 600.0,
                    ),
                  ),
                ],
              ),
            ),
          ),
        ),
      ),
    );
  }
}

Pre-launch Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I read and followed the Flutter Style Guide, including Features we expect every widget to implement.
  • I signed the CLA.
  • I listed at least one issue that this PR fixes in the description above.
  • I updated/added relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making, or this PR is test-exempt.
  • All existing and new tests are passing.

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

@flutter-dashboard flutter-dashboard bot added f: scrolling Viewports, list views, slivers, etc. framework flutter/packages/flutter repository. See also f: labels. labels Sep 9, 2022
@TahaTesser
Copy link
Member Author

cc: @werainkhatri
Since you're the one who pointed out this behavior, do you wanna take a look at this PR?

@werainkhatri
Copy link
Member

cc: @werainkhatri
Since you're the one who pointed out this behavior, do you wanna take a look at this PR?

hey! ya it's in my to-do. am a little busy this week. will try to pick it up if a get a bit of time. hope that's okay.

@Piinks Piinks added the a: quality A truly polished experience label Sep 15, 2022
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.

I checked this out today and played around with it. Very nice, elegant.

Comment on lines 1790 to 1791
_thumbPressVertical = localPosition.dy - scrollbarPainter._thumbOffset;
_thumbPressHorizontal = localPosition.dx - scrollbarPainter._thumbOffset;
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need to keep track of both the horizontal and the vertical? Or just the axis we care about? It looks like you filter for it later in handleThumbPressUpdate

Copy link
Member Author

Choose a reason for hiding this comment

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

Great idea, I cleaned this up.

But for some reason, the golden file change message is thrown. This shouldn't have any golden changes AFAIK.

@flutter-dashboard
Copy link

Golden file changes have been found for this pull request. Click here to view and triage (e.g. because this is an intentional change).

If you are still iterating on this change and are not ready to resolve the images on the Flutter Gold dashboard, consider marking this PR as a draft pull request above. You will still be able to view image results on the dashboard, commenting will be silenced, and the check will not try to resolve itself until marked ready for review.

For more guidance, visit Writing a golden file test for package:flutter.

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing.

Changes reported for pull request #111250 at sha bf99455316929e0ebd51bf9a5ef73ff34d3f10e2

@flutter-dashboard flutter-dashboard bot added the will affect goldens Changes to golden files label Sep 15, 2022
@TahaTesser TahaTesser requested a review from Piinks September 15, 2022 13:41
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.

This LGTM! Thanks!

The golden file change is not related to your PR. That test has been flaky and should be skipped now if you update your branch. We are tracking that in a separate issue as well - sorry for the inconvenience!

@TahaTesser TahaTesser force-pushed the drag_scrollbar_desktop branch from bf99455 to 441491d Compare September 19, 2022 07:13
@TahaTesser TahaTesser added the autosubmit Merge PR when tree becomes green via auto submit App label Sep 19, 2022
@auto-submit auto-submit bot merged commit ff6aa92 into flutter:master Sep 19, 2022
@TahaTesser TahaTesser deleted the drag_scrollbar_desktop branch September 19, 2022 09:08
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Sep 19, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/plugins that referenced this pull request Sep 19, 2022
Piinks added a commit that referenced this pull request Sep 20, 2022
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 autosubmit Merge PR when tree becomes green via auto submit App f: scrolling Viewports, list views, slivers, etc. framework flutter/packages/flutter repository. See also f: labels. will affect goldens Changes to golden files
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ScrollBar moves with an offset if cursor leaves flutter application.
3 participants