Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

[mob][photos] Make the gallery scrollbar easier to grab

ashil-pilot17c90339f885
diff --git a/mobile/apps/photos/changes/gallery-scrollbar-easier-to-grab.md b/mobile/apps/photos/changes/gallery-scrollbar-easier-to-grab.md
new file mode 100644
index 0000000000..b0fa207c50
--- /dev/null
+++ b/mobile/apps/photos/changes/gallery-scrollbar-easier-to-grab.md
@@ -0,0 +1 @@
+- Made the gallery scrollbar easier to grab and kept it visible longer after scrolling.
diff --git a/mobile/apps/photos/lib/ui/viewer/gallery/scrollbar/scroll_bar_with_use_notifier.dart b/mobile/apps/photos/lib/ui/viewer/gallery/scrollbar/scroll_bar_with_use_notifier.dart
index cfada8dc85..03ee439862 100644
--- a/mobile/apps/photos/lib/ui/viewer/gallery/scrollbar/scroll_bar_with_use_notifier.dart
+++ b/mobile/apps/photos/lib/ui/viewer/gallery/scrollbar/scroll_bar_with_use_notifier.dart
@@ -12,7 +12,7 @@ const double _kScrollbarThicknessWithTrack = 12.0;
const double _kScrollbarMargin = 2.0;
const Radius _kScrollbarRadius = Radius.circular(8.0);
const Duration _kScrollbarFadeDuration = Duration(milliseconds: 300);
-const Duration _kScrollbarTimeToFade = Duration(milliseconds: 600);
+const Duration _kScrollbarTimeToFade = Duration(seconds: 2);
class ScrollbarWithUseNotifer extends StatelessWidget {
const ScrollbarWithUseNotifer({
@@ -124,12 +124,16 @@ class _MaterialScrollbar extends RawScrollbar {
class _MaterialScrollbarState extends RawScrollbarState<_MaterialScrollbar> {
late AnimationController _hoverAnimationController;
+ late final ScrollbarPainter _thumbTargetPainter;
bool _dragIsActive = false;
bool _hoverIsActive = false;
late ColorScheme _colorScheme;
late ScrollbarThemeData _scrollbarTheme;
late bool _useAndroidScrollbar;
+ @override
+ ScrollbarPainter get scrollbarPainter => _thumbTargetPainter;
+
@override
bool get showScrollbar =>
widget.thumbVisibility ??
@@ -249,6 +253,15 @@ class _MaterialScrollbarState extends RawScrollbarState<_MaterialScrollbar> {
@override
void initState() {
super.initState();
+ // The base painter is final, so override its getter and reuse its animation.
+ final originalPainter = super.scrollbarPainter;
+ _thumbTargetPainter = _ThumbTargetScrollbarPainter(
+ color: originalPainter.color,
+ fadeoutOpacityAnimation: originalPainter.fadeoutOpacityAnimation,
+ minLength: originalPainter.minLength,
+ minOverscrollLength: originalPainter.minOverscrollLength,
+ );
+ originalPainter.dispose();
_hoverAnimationController = AnimationController(
vsync: this,
duration: const Duration(milliseconds: 200),
@@ -352,3 +365,45 @@ class _MaterialScrollbarState extends RawScrollbarState<_MaterialScrollbar> {
super.dispose();
}
}
+
+class _ThumbTargetScrollbarPainter extends ScrollbarPainter {
+ _ThumbTargetScrollbarPainter({
+ required super.color,
+ required super.fadeoutOpacityAnimation,
+ required super.minLength,
+ required super.minOverscrollLength,
+ });
+
+ Axis _axis = Axis.vertical;
+
+ @override
+ void update(ScrollMetrics metrics, AxisDirection axisDirection) {
+ _axis = metrics.axis;
+ super.update(metrics, axisDirection);
+ }
+
+ @override
+ bool hitTestOnlyThumbInteractive(Offset position, PointerDeviceKind kind) {
+ if (super.hitTestOnlyThumbInteractive(position, kind)) {
+ return true;
+ }
+ if (kind != PointerDeviceKind.touch || color.a == 0) {
+ return false;
+ }
+ final orientation =
+ scrollbarOrientation ??
+ (_axis == Axis.horizontal
+ ? ScrollbarOrientation.bottom
+ : textDirection == TextDirection.rtl
+ ? ScrollbarOrientation.left
+ : ScrollbarOrientation.right);
+ // Extend Flutter's padded thumb target inward without extending the track.
+ final offset = switch (orientation) {
+ ScrollbarOrientation.right => const Offset(16, 0),
+ ScrollbarOrientation.left => const Offset(-16, 0),
+ ScrollbarOrientation.bottom => const Offset(0, 16),
+ ScrollbarOrientation.top => const Offset(0, -16),
+ };
+ return super.hitTestOnlyThumbInteractive(position + offset, kind);
+ }
+}
diff --git a/mobile/apps/photos/test/ui/viewer/gallery/scroll_bar_with_use_notifier_test.dart b/mobile/apps/photos/test/ui/viewer/gallery/scroll_bar_with_use_notifier_test.dart
index d1892dc3ee..425312fef2 100644
--- a/mobile/apps/photos/test/ui/viewer/gallery/scroll_bar_with_use_notifier_test.dart
+++ b/mobile/apps/photos/test/ui/viewer/gallery/scroll_bar_with_use_notifier_test.dart
@@ -21,10 +21,14 @@ void main() {
Future<void> pumpScrollbar(
WidgetTester tester, {
VoidCallback? onPhotoTap,
+ bool thumbVisibility = true,
+ TextDirection textDirection = TextDirection.ltr,
}) async {
await tester.pumpWidget(
MaterialApp(
theme: ThemeData(platform: platform),
+ builder: (context, child) =>
+ Directionality(textDirection: textDirection, child: child!),
home: Align(
alignment: Alignment.topLeft,
child: SizedBox(
@@ -34,7 +38,7 @@ void main() {
controller: controller,
inUseNotifier: inUseNotifier,
interactive: true,
- thumbVisibility: true,
+ thumbVisibility: thumbVisibility,
minScrollbarLength: 36,
thickness: 8,
scrollbarPadding: const EdgeInsets.only(right: 3),
@@ -54,6 +58,114 @@ void main() {
await tester.pumpAndSettle();
}
+ ScrollbarPainter painter(WidgetTester tester) => tester
+ .widgetList<CustomPaint>(find.byType(CustomPaint))
+ .map((widget) => widget.foregroundPainter)
+ .whereType<ScrollbarPainter>()
+ .single;
+
+ testWidgets(
+ "thumb waits two seconds then fades and releases its target",
+ (tester) async {
+ var photoTaps = 0;
+ await pumpScrollbar(
+ tester,
+ thumbVisibility: false,
+ onPhotoTap: () => photoTaps++,
+ );
+ controller.jumpTo(3000);
+ await tester.pump();
+ await tester.pump(const Duration(milliseconds: 1900));
+ expect(painter(tester).fadeoutOpacityAnimation.value, 1);
+ await tester.pump(const Duration(milliseconds: 100));
+ await tester.pump(const Duration(milliseconds: 150));
+ expect(
+ painter(tester).fadeoutOpacityAnimation.value,
+ inExclusiveRange(0, 1),
+ );
+ await tester.pump(const Duration(milliseconds: 150));
+ expect(painter(tester).fadeoutOpacityAnimation.value, 0);
+
+ await tester.tapAt(const Offset(360, 166));
+ await tester.pump();
+ expect(photoTaps, 1);
+ final gesture = await tester.startGesture(const Offset(360, 166));
+ await gesture.moveBy(const Offset(0, -20));
+ await tester.pump();
+ await gesture.moveBy(const Offset(0, -60));
+ await tester.pump();
+ expect(inUseNotifier.value, isFalse);
+ expect(controller.offset, greaterThan(3000));
+ await gesture.up();
+ await tester.pumpAndSettle();
+ },
+ );
+
+ testWidgets(
+ "inward target follows the thumb and keeps an acquired drag",
+ (tester) async {
+ var photoTaps = 0;
+ await pumpScrollbar(tester, onPhotoTap: () => photoTaps++);
+ controller.jumpTo(3000);
+ await tester.pumpAndSettle();
+
+ final gesture = await tester.startGesture(const Offset(360, 166));
+ await gesture.moveBy(const Offset(0, 10));
+ await tester.pump();
+ expect(inUseNotifier.value, isTrue);
+ await gesture.moveBy(const Offset(-160, 90));
+ await tester.pump();
+ expect(inUseNotifier.value, isTrue);
+ expect(controller.offset, greaterThan(4500));
+ await gesture.up();
+ await tester.pumpAndSettle();
+ expect(inUseNotifier.value, isFalse);
+
+ for (final position in [
+ const Offset(360, 18),
+ const Offset(350, 166),
+ const Offset(360, 196),
+ ]) {
+ controller.jumpTo(3000);
+ await tester.pumpAndSettle();
+ await tester.tapAt(position);
+ await tester.pump();
+ final swipe = await tester.startGesture(position);
+ await swipe.moveBy(const Offset(0, -20));
+ await tester.pump();
+ await swipe.moveBy(const Offset(0, -60));
+ await tester.pump();
+ expect(
+ inUseNotifier.value,
+ isFalse,
+ reason: "swipe from $position",
+ );
+ expect(controller.offset, greaterThan(3000));
+ await swipe.up();
+ await tester.pumpAndSettle();
+ }
+ expect(photoTaps, 3);
+ },
+ );
+
+ testWidgets("inward target mirrors with a left-side RTL thumb", (
+ tester,
+ ) async {
+ await pumpScrollbar(tester, textDirection: TextDirection.rtl);
+ controller.jumpTo(3000);
+ await tester.pumpAndSettle();
+ final gesture = await tester.startGesture(const Offset(36, 166));
+ await gesture.moveBy(const Offset(0, 10));
+ await tester.pump();
+ expect(inUseNotifier.value, isTrue);
+ await gesture.moveBy(const Offset(0, 90));
+ await tester.pump();
+ expect(controller.offset, greaterThan(4500));
+ await gesture.up();
+ await tester.pumpAndSettle();
+ expect(inUseNotifier.value, isFalse);
+ });
+
testWidgets("track taps above and below the thumb do not scroll", (
tester,
) async {