Add haptic feedback when going through sections when using the scrollbar

This commit is contained in:
ashilkn
2025-07-15 15:53:37 +05:30
parent 03c116c2ba
commit e4f10d0e69
2 changed files with 14 additions and 4 deletions

View File

@@ -2,6 +2,7 @@ import 'dart:async';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import "package:flutter/services.dart";
import 'package:logging/logging.dart';
import 'package:photos/core/constants.dart';
import 'package:photos/core/event_bus.dart';
@@ -136,6 +137,7 @@ class GalleryState extends State<Gallery> {
}
final miscUtil = MiscUtil();
final scrollBarInUseNotifier = ValueNotifier<bool>(false);
@override
void initState() {
@@ -429,6 +431,7 @@ class GalleryState extends State<Gallery> {
}
_debouncer.cancelDebounceTimer();
_scrollController.dispose();
scrollBarInUseNotifier.dispose();
super.dispose();
}
@@ -481,6 +484,7 @@ class GalleryState extends State<Gallery> {
child: CustomScrollBar2(
scrollController: _scrollController,
galleryGroups: galleryGroups,
inUseNotifier: scrollBarInUseNotifier,
child: Stack(
key: _stackKey,
clipBehavior: Clip.none,
@@ -512,6 +516,7 @@ class GalleryState extends State<Gallery> {
_sectionedListSliverRenderBoxYOffsetRelativeToStackRenderBox,
selectedFiles: widget.selectedFiles,
showSelectAllByDefault: widget.showSelectAllByDefault,
scrollbarInUseNotifier: scrollBarInUseNotifier,
),
],
),
@@ -588,6 +593,7 @@ class PinnedGroupHeader extends StatefulWidget {
getSectionedListSliverRenderBoxYOffsetRelativeToStackRenderBox;
final SelectedFiles? selectedFiles;
final bool showSelectAllByDefault;
final ValueNotifier<bool> scrollbarInUseNotifier;
const PinnedGroupHeader({
required this.scrollController,
@@ -595,6 +601,7 @@ class PinnedGroupHeader extends StatefulWidget {
required this.getSectionedListSliverRenderBoxYOffsetRelativeToStackRenderBox,
required this.selectedFiles,
required this.showSelectAllByDefault,
required this.scrollbarInUseNotifier,
super.key,
});
@@ -672,6 +679,9 @@ class _PinnedGroupHeaderState extends State<PinnedGroupHeader> {
}
setState(() {});
if (widget.scrollbarInUseNotifier.value) {
HapticFeedback.selectionClick();
}
}
@override

View File

@@ -10,11 +10,13 @@ class CustomScrollBar2 extends StatefulWidget {
final Widget child;
final ScrollController scrollController;
final GalleryGroups galleryGroups;
final ValueNotifier<bool> inUseNotifier;
const CustomScrollBar2({
super.key,
required this.child,
required this.scrollController,
required this.galleryGroups,
required this.inUseNotifier,
});
@override
@@ -38,7 +40,6 @@ division and populate position to title mapping.
class _CustomScrollBar2State extends State<CustomScrollBar2> {
final _logger = Logger("CustomScrollBar2");
final _key = GlobalKey();
final inUseNotifier = ValueNotifier<bool>(false);
List<({double position, String title})>? positionToTitleMap;
static const _bottomPadding = 92.0;
@@ -58,7 +59,6 @@ class _CustomScrollBar2State extends State<CustomScrollBar2> {
@override
void dispose() {
inUseNotifier.dispose();
super.dispose();
}
@@ -133,14 +133,14 @@ class _CustomScrollBar2State extends State<CustomScrollBar2> {
key: _key,
controller: widget.scrollController,
interactive: true,
inUseNotifier: inUseNotifier,
inUseNotifier: widget.inUseNotifier,
child: widget.child,
),
),
positionToTitleMap == null
? const SizedBox.shrink()
: ValueListenableBuilder<bool>(
valueListenable: inUseNotifier,
valueListenable: widget.inUseNotifier,
builder: (context, inUse, _) {
return AnimatedSwitcher(
duration: const Duration(milliseconds: 250),