From 584e5cae6cb0b59a8e78f0617fdb5012c6b41d79 Mon Sep 17 00:00:00 2001 From: Thibault Deckers Date: Mon, 23 Jan 2023 12:01:07 +0100 Subject: [PATCH] fixed scrolling to highlight item in some cases --- lib/widgets/collection/collection_page.dart | 11 +++++++---- lib/widgets/common/grid/item_tracker.dart | 16 ++++++++-------- .../filter_grids/common/filter_grid_page.dart | 17 ++++++++++------- 3 files changed, 25 insertions(+), 19 deletions(-) diff --git a/lib/widgets/collection/collection_page.dart b/lib/widgets/collection/collection_page.dart index 39b2ea928..3392ad66e 100644 --- a/lib/widgets/collection/collection_page.dart +++ b/lib/widgets/collection/collection_page.dart @@ -7,6 +7,7 @@ import 'package:aves/model/filters/query.dart'; import 'package:aves/model/filters/trash.dart'; import 'package:aves/model/highlight.dart'; import 'package:aves/model/selection.dart'; +import 'package:aves/model/settings/enums/accessibility_animations.dart'; import 'package:aves/model/settings/settings.dart'; import 'package:aves/model/source/collection_lens.dart'; import 'package:aves/model/source/collection_source.dart'; @@ -214,11 +215,13 @@ class _CollectionPageState extends State { final highlightTest = widget.highlightTest; if (highlightTest == null) return; + final item = _collection.sortedEntries.firstWhereOrNull(highlightTest); + if (item == null) return; + final delayDuration = context.read().staggeredAnimationPageTarget; await Future.delayed(delayDuration + Durations.highlightScrollInitDelay); - final targetEntry = _collection.sortedEntries.firstWhereOrNull(highlightTest); - if (targetEntry != null) { - context.read().trackItem(targetEntry, highlightItem: targetEntry); - } + + final animate = context.read().accessibilityAnimations.animate; + context.read().trackItem(item, animate: animate, highlightItem: item); } } diff --git a/lib/widgets/common/grid/item_tracker.dart b/lib/widgets/common/grid/item_tracker.dart index a693ec0bd..86cf83777 100644 --- a/lib/widgets/common/grid/item_tracker.dart +++ b/lib/widgets/common/grid/item_tracker.dart @@ -110,23 +110,23 @@ class _GridItemTrackerState extends State> with WidgetsBin final itemVisibility = max(0, tileRect.intersect(viewportRect).height) / tileRect.height; if (!event.predicate(itemVisibility)) return; + double scrollOffset = tileRect.top + (tileRect.height - scrollableSize.height) * ((event.alignment.y + 1) / 2); // most of the time the app bar will be scrolled away after scaling, // so we compensate for it to center the focal point thumbnail - final appBarHeight = appBarHeightNotifier.value; - final scrollOffset = appBarHeight + tileRect.top + (tileRect.height - scrollableSize.height) * ((event.alignment.y + 1) / 2); + scrollOffset += appBarHeightNotifier.value; + scrollOffset = scrollOffset.clamp(0, scrollController.position.maxScrollExtent); - if (event.animate) { - if (scrollOffset > 0) { + if (scrollOffset > 0) { + if (event.animate) { await scrollController.animateTo( scrollOffset, duration: Duration(milliseconds: (scrollOffset / 2).round().clamp(Durations.highlightScrollAnimationMinMillis, Durations.highlightScrollAnimationMaxMillis)), curve: Curves.easeInOutCubic, ); + } else { + scrollController.jumpTo(scrollOffset); + await Future.delayed(Durations.highlightJumpDelay); } - } else { - final maxScrollExtent = scrollController.position.maxScrollExtent; - scrollController.jumpTo(scrollOffset.clamp(.0, maxScrollExtent)); - await Future.delayed(Durations.highlightJumpDelay); } final highlightItem = event.highlightItem; diff --git a/lib/widgets/filter_grids/common/filter_grid_page.dart b/lib/widgets/filter_grids/common/filter_grid_page.dart index 7f0e61c5b..0689fcd71 100644 --- a/lib/widgets/filter_grids/common/filter_grid_page.dart +++ b/lib/widgets/filter_grids/common/filter_grid_page.dart @@ -5,6 +5,7 @@ import 'package:aves/model/filters/filters.dart'; import 'package:aves/model/highlight.dart'; import 'package:aves/model/query.dart'; import 'package:aves/model/selection.dart'; +import 'package:aves/model/settings/enums/accessibility_animations.dart'; import 'package:aves/model/settings/settings.dart'; import 'package:aves/model/source/collection_source.dart'; import 'package:aves/model/source/enums/enums.dart'; @@ -520,13 +521,15 @@ class _FilterSectionedContentState extends State<_Fi Future _checkInitHighlight() async { final highlightInfo = context.read(); final filter = highlightInfo.clear(); - if (filter is T) { - final gridItem = visibleSections.values.expand((list) => list).firstWhereOrNull((gridItem) => gridItem.filter == filter); - if (gridItem != null) { - await Future.delayed(Durations.highlightScrollInitDelay); - highlightInfo.trackItem(gridItem, highlightItem: filter); - } - } + if (filter is! T) return; + + final item = visibleSections.values.expand((list) => list).firstWhereOrNull((gridItem) => gridItem.filter == filter); + if (item == null) return; + + await Future.delayed(Durations.highlightScrollInitDelay); + + final animate = context.read().accessibilityAnimations.animate; + highlightInfo.trackItem(item, animate: animate, highlightItem: filter); } }