fixed scrolling to highlight item in some cases

This commit is contained in:
Thibault Deckers 2023-01-23 12:01:07 +01:00
parent d889a26e62
commit 584e5cae6c
3 changed files with 25 additions and 19 deletions

View file

@ -7,6 +7,7 @@ import 'package:aves/model/filters/query.dart';
import 'package:aves/model/filters/trash.dart'; import 'package:aves/model/filters/trash.dart';
import 'package:aves/model/highlight.dart'; import 'package:aves/model/highlight.dart';
import 'package:aves/model/selection.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/settings/settings.dart';
import 'package:aves/model/source/collection_lens.dart'; import 'package:aves/model/source/collection_lens.dart';
import 'package:aves/model/source/collection_source.dart'; import 'package:aves/model/source/collection_source.dart';
@ -214,11 +215,13 @@ class _CollectionPageState extends State<CollectionPage> {
final highlightTest = widget.highlightTest; final highlightTest = widget.highlightTest;
if (highlightTest == null) return; if (highlightTest == null) return;
final item = _collection.sortedEntries.firstWhereOrNull(highlightTest);
if (item == null) return;
final delayDuration = context.read<DurationsData>().staggeredAnimationPageTarget; final delayDuration = context.read<DurationsData>().staggeredAnimationPageTarget;
await Future.delayed(delayDuration + Durations.highlightScrollInitDelay); await Future.delayed(delayDuration + Durations.highlightScrollInitDelay);
final targetEntry = _collection.sortedEntries.firstWhereOrNull(highlightTest);
if (targetEntry != null) { final animate = context.read<Settings>().accessibilityAnimations.animate;
context.read<HighlightInfo>().trackItem(targetEntry, highlightItem: targetEntry); context.read<HighlightInfo>().trackItem(item, animate: animate, highlightItem: item);
}
} }
} }

View file

@ -110,23 +110,23 @@ class _GridItemTrackerState<T> extends State<GridItemTracker<T>> with WidgetsBin
final itemVisibility = max(0, tileRect.intersect(viewportRect).height) / tileRect.height; final itemVisibility = max(0, tileRect.intersect(viewportRect).height) / tileRect.height;
if (!event.predicate(itemVisibility)) return; 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, // most of the time the app bar will be scrolled away after scaling,
// so we compensate for it to center the focal point thumbnail // so we compensate for it to center the focal point thumbnail
final appBarHeight = appBarHeightNotifier.value; scrollOffset += appBarHeightNotifier.value;
final scrollOffset = appBarHeight + tileRect.top + (tileRect.height - scrollableSize.height) * ((event.alignment.y + 1) / 2); scrollOffset = scrollOffset.clamp(0, scrollController.position.maxScrollExtent);
if (event.animate) { if (scrollOffset > 0) {
if (scrollOffset > 0) { if (event.animate) {
await scrollController.animateTo( await scrollController.animateTo(
scrollOffset, scrollOffset,
duration: Duration(milliseconds: (scrollOffset / 2).round().clamp(Durations.highlightScrollAnimationMinMillis, Durations.highlightScrollAnimationMaxMillis)), duration: Duration(milliseconds: (scrollOffset / 2).round().clamp(Durations.highlightScrollAnimationMinMillis, Durations.highlightScrollAnimationMaxMillis)),
curve: Curves.easeInOutCubic, 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; final highlightItem = event.highlightItem;

View file

@ -5,6 +5,7 @@ import 'package:aves/model/filters/filters.dart';
import 'package:aves/model/highlight.dart'; import 'package:aves/model/highlight.dart';
import 'package:aves/model/query.dart'; import 'package:aves/model/query.dart';
import 'package:aves/model/selection.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/settings/settings.dart';
import 'package:aves/model/source/collection_source.dart'; import 'package:aves/model/source/collection_source.dart';
import 'package:aves/model/source/enums/enums.dart'; import 'package:aves/model/source/enums/enums.dart';
@ -520,13 +521,15 @@ class _FilterSectionedContentState<T extends CollectionFilter> extends State<_Fi
Future<void> _checkInitHighlight() async { Future<void> _checkInitHighlight() async {
final highlightInfo = context.read<HighlightInfo>(); final highlightInfo = context.read<HighlightInfo>();
final filter = highlightInfo.clear(); final filter = highlightInfo.clear();
if (filter is T) { if (filter is! T) return;
final gridItem = visibleSections.values.expand((list) => list).firstWhereOrNull((gridItem) => gridItem.filter == filter);
if (gridItem != null) { final item = visibleSections.values.expand((list) => list).firstWhereOrNull((gridItem) => gridItem.filter == filter);
await Future.delayed(Durations.highlightScrollInitDelay); if (item == null) return;
highlightInfo.trackItem(gridItem, highlightItem: filter);
} await Future.delayed(Durations.highlightScrollInitDelay);
}
final animate = context.read<Settings>().accessibilityAnimations.animate;
highlightInfo.trackItem(item, animate: animate, highlightItem: filter);
} }
} }