π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
[mob][photos] Refactor gallery filmstrip coordination
ashil-pilot4fcd9362ea1e
diff --git a/mobile/apps/photos/lib/ui/viewer/file/detail_page.dart b/mobile/apps/photos/lib/ui/viewer/file/detail_page.dartindex fe6275fa97..640ad24fe1 100644--- a/mobile/apps/photos/lib/ui/viewer/file/detail_page.dart+++ b/mobile/apps/photos/lib/ui/viewer/file/detail_page.dart@@ -12,7 +12,6 @@ import 'package:flutter/services.dart';import "package:flutter_svg/flutter_svg.dart";import 'package:logging/logging.dart';import 'package:photos/core/configuration.dart';-import "package:photos/core/constants.dart";import 'package:photos/core/errors.dart';import "package:photos/core/event_bus.dart";import "package:photos/events/file_caption_updated_event.dart";@@ -37,14 +36,13 @@ import "package:photos/ui/tools/editor/image_editor/image_editor_page.dart";import "package:photos/ui/tools/editor/video_editor_page.dart";import "package:photos/ui/viewer/file/file_app_bar.dart";import "package:photos/ui/viewer/file/file_bottom_bar.dart";-import "package:photos/ui/viewer/file/file_viewer_filmstrip.dart";-import "package:photos/ui/viewer/file/file_viewer_filmstrip_preview_handoff.dart";+import "package:photos/ui/viewer/file/file_viewer_filmstrip_coordinator.dart";import 'package:photos/ui/viewer/file/file_widget.dart';+import "package:photos/ui/viewer/file/gallery_file_viewer_filmstrip.dart";import "package:photos/ui/viewer/file/ocr/inline_text_detection.dart";import "package:photos/ui/viewer/file/panorama_viewer_screen.dart";import "package:photos/ui/viewer/file/qr_code_detection_helper.dart";import "package:photos/ui/viewer/file/qr_code_highlight_overlay.dart";-import "package:photos/ui/viewer/file/thumbnail_widget.dart";import "package:photos/ui/viewer/file/video_control/gallery_video_controls.dart";import 'package:photos/ui/viewer/gallery/gallery.dart';import 'package:photos/utils/dialog_util.dart';@@ -133,8 +131,13 @@ class _DetailPageState extends State<DetailPage> {void initState() {super.initState();_bottomControlsAdditionalInsetNotifier.value =- widget.config.showGalleryFilmstrip && widget.config.files.length > 1- ? kFileViewerFilmstripAdditionalBottomInset+ shouldShowGalleryFileViewerFilmstrip(+ isEnabled: widget.config.showGalleryFilmstrip,+ isMinimalistic: widget.config.mode == DetailPageMode.minimalistic,+ isGuestView: false,+ itemCount: widget.config.files.length,+ )+ ? GalleryFileViewerFilmstripLayout.additionalBottomInset: 0;}@@ -181,7 +184,7 @@ class _BodyState extends State<_Body> {List<EnteFile>? _files;late PageController _pageController;final _selectedIndexNotifier = ValueNotifier(0);- final _filmstripPreviewHandoff = FileViewerFilmstripPreviewHandoff();+ late final FileViewerFilmstripCoordinator _filmstripCoordinator;final _inlineTextDetectionController = InlineTextDetectionController();bool _isFirstOpened = true;bool isGuestView = false;@@ -194,8 +197,6 @@ class _BodyState extends State<_Body> {final _playbackSpeed = ValueNotifier<double>(1.0);final Map<EnteFile, int> _fileIndexByIdentity = Map.identity();ValueNotifier<double>? _bottomControlsAdditionalInsetNotifier;- bool _isFilmstripScrubbing = false;- bool _didPauseVideoForFilmstripScrub = false;@overridevoid initState() {@@ -209,6 +210,21 @@ class _BodyState extends State<_Body> {: configuredIndex;_selectedIndexNotifier.value = selectedIndex;_pageController = PageController(initialPage: max(0, selectedIndex));+ _filmstripCoordinator = FileViewerFilmstripCoordinator(+ currentIndex: () => _selectedIndexNotifier.value,+ identityAt: _fileAt,+ jumpToPageImmediately: (index) {+ if (!_pageController.hasClients) return false;+ _pageController.jumpToPage(index);+ return true;+ },+ requestPauseCurrentMedia: () {+ final selectedFile = _selectedFile;+ if (selectedFile?.fileType == FileType.video) {+ Bus.instance.fire(PauseVideoEvent(fileTag: selectedFile!.tag));+ }+ },+ );_guestViewEventSubscription = Bus.instance.on<GuestViewEvent>().listen((event,) {@@ -260,9 +276,9 @@ class _BodyState extends State<_Body> {void dispose() {_guestViewEventSubscription.cancel();_captionUpdatedSubscription.cancel();+ _filmstripCoordinator.dispose();_pageController.dispose();_selectedIndexNotifier.dispose();- _filmstripPreviewHandoff.dispose();_qrHelper?.dispose();_playbackSpeed.dispose();super.dispose();@@ -310,7 +326,7 @@ class _BodyState extends State<_Body> {appBar: PreferredSize(preferredSize: const Size.fromHeight(80),child: ValueListenableBuilder<int?>(- valueListenable: _filmstripPreviewHandoff,+ valueListenable: _filmstripCoordinator.previewIndex,builder: (context, previewIndex, child) =>AbsorbPointer(absorbing: previewIndex != null, child: child),child: ValueListenableBuilder(@@ -455,32 +471,13 @@ class _BodyState extends State<_Body> {},),if (_shouldShowFilmstrip)- ValueListenableBuilder<int?>(- valueListenable: _filmstripPreviewHandoff,- builder: (context, previewIndex, _) {- final previewFile = previewIndex == null- ? null- : _fileAt(previewIndex);- if (previewFile == null) {- return const SizedBox.shrink();- }- return Positioned.fill(- child: AbsorbPointer(- child: ColoredBox(- key: fileViewerFilmstripPreviewKey,- color: Colors.black,- child: _GalleryFilmstripThumbnail(- file: previewFile,- fit: BoxFit.contain,- ),- ),- ),- );- },+ GalleryFileViewerFilmstripPreviewLayer(+ files: _files!,+ previewIndex: _filmstripCoordinator.previewIndex,),if (widget.config.mode != DetailPageMode.minimalistic)ValueListenableBuilder<int?>(- valueListenable: _filmstripPreviewHandoff,+ valueListenable: _filmstripCoordinator.previewIndex,builder: (context, previewIndex, child) => AbsorbPointer(// The toolbar stays visible, but must not act on the old// committed file while another file is being previewed.@@ -506,14 +503,15 @@ class _BodyState extends State<_Body> {ValueListenableBuilder(valueListenable: _selectedIndexNotifier,builder: (BuildContext context, int selectedIndex, _) {- return _GalleryFileViewerFilmstripOverlay(+ return GalleryFileViewerFilmstripOverlay(files: _files!,selectedIndex: selectedIndex,+ bottomControlsHeight: _galleryBottomBarHeight,findChildIndexCallback: _findChildIndex,enableFullScreenNotifier: InheritedDetailPageState.of(context,).enableFullScreenNotifier,- onSelectionChanged: _onFilmstripSelectionChanged,+ onEvent: _filmstripCoordinator.handleEvent,);},),@@ -550,7 +548,7 @@ class _BodyState extends State<_Body> {clipBehavior: Clip.none,itemBuilder: (context, index) {final file = _files![index];- if (!_isFilmstripScrubbing) {+ if (!_filmstripCoordinator.isUserScrollSessionActive) {_preloadFiles(index);}final Widget fileContent = FileWidget(@@ -628,19 +626,8 @@ class _BodyState extends State<_Body> {} else {_selectedIndexNotifier.value = index;}- _filmstripPreviewHandoff.onPageChanged(- index: index,- fileIdentity: file,- onPagePainted: () {- if (!mounted ||- _selectedIndexNotifier.value != index ||- !identical(_fileAt(index), file)) {- return;- }- _clearFilmstripPreview();- },- );- if (!_isFilmstripScrubbing) {+ _filmstripCoordinator.handlePageChanged(index, file);+ if (!_filmstripCoordinator.isUserScrollSessionActive) {_runSelectedFileSideEffects(file);}},@@ -678,71 +665,6 @@ class _BodyState extends State<_Body> {}}- void _onFilmstripSelectionChanged(- int index,- FileViewerFilmstripSelectionSource source,- ) {- final file = _fileAt(index);- if (file == null) return;-- switch (source) {- case FileViewerFilmstripSelectionSource.tap:- _clearFilmstripPreview();- if (_pageController.hasClients &&- index != _selectedIndexNotifier.value) {- _pageController.jumpToPage(index);- }- break;- case FileViewerFilmstripSelectionSource.scrubStart:- _clearFilmstripPreview();- _isFilmstripScrubbing = true;- break;- case FileViewerFilmstripSelectionSource.scrubPreview:- _isFilmstripScrubbing = true;- if (index == _selectedIndexNotifier.value) {- _filmstripPreviewHandoff.clear();- break;- }- if (!_didPauseVideoForFilmstripScrub) {- _didPauseVideoForFilmstripScrub = true;- final selectedFile = _selectedFile;- if (selectedFile?.fileType == FileType.video) {- Bus.instance.fire(PauseVideoEvent(fileTag: selectedFile!.tag));- }- }- _filmstripPreviewHandoff.showPreview(index);- break;- case FileViewerFilmstripSelectionSource.scrubCommit:- _isFilmstripScrubbing = false;- _beginFilmstripHandoff(index, file);- break;- }- }-- void _beginFilmstripHandoff(int index, EnteFile file) {- if (!_pageController.hasClients) {- _clearFilmstripPreview();- return;- }- if (index == _selectedIndexNotifier.value) {- if (!_filmstripPreviewHandoff.isPendingCommit(- index: index,- fileIdentity: file,- )) {- _clearFilmstripPreview();- }- return;- }- _filmstripPreviewHandoff.beginCommit(index: index, fileIdentity: file);- _pageController.jumpToPage(index);- }-- void _clearFilmstripPreview() {- _isFilmstripScrubbing = false;- _didPauseVideoForFilmstripScrub = false;- _filmstripPreviewHandoff.clear();- }-void _runSelectedFileSideEffects(EnteFile file) {Bus.instance.fire(GuestViewEvent(isGuestView, swipeLocked));_updateSharedCollectionState(file);@@ -751,7 +673,7 @@ class _BodyState extends State<_Body> {Future<void> _onFileRemoved(EnteFile file) async {if (!mounted || _files == null) return;- _clearFilmstripPreview();+ _filmstripCoordinator.reset();final files = _files!;final removedIndex = _indexOfFile(file);if (removedIndex < 0) {@@ -920,18 +842,19 @@ class _BodyState extends State<_Body> {EnteFile? get _selectedFile => _fileAt(_selectedIndexNotifier.value);- bool get _shouldShowFilmstrip =>- widget.config.showGalleryFilmstrip &&- widget.config.mode != DetailPageMode.minimalistic &&- !isGuestView &&- (_files?.length ?? 0) > 1;+ bool get _shouldShowFilmstrip => shouldShowGalleryFileViewerFilmstrip(+ isEnabled: widget.config.showGalleryFilmstrip,+ isMinimalistic: widget.config.mode == DetailPageMode.minimalistic,+ isGuestView: isGuestView,+ itemCount: _files?.length ?? 0,+ );void _syncBottomControlsInset() {final notifier = _bottomControlsAdditionalInsetNotifier;if (notifier == null) return;- if (!_shouldShowFilmstrip) _clearFilmstripPreview();+ if (!_shouldShowFilmstrip) _filmstripCoordinator.reset();final inset = _shouldShowFilmstrip- ? kFileViewerFilmstripAdditionalBottomInset+ ? GalleryFileViewerFilmstripLayout.additionalBottomInset: 0.0;notifier.value = inset;}@@ -1003,7 +926,7 @@ class _GalleryFileViewerBottomOverlay extends StatelessWidget {context,).mini.copyWith(color: textBaseDark.withValues(alpha: 0.8));final filmstripInset = hasFilmstrip- ? kFileViewerFilmstripAdditionalBottomInset+ ? GalleryFileViewerFilmstripLayout.additionalBottomInset: 0.0;return ValueListenableBuilder<bool>(valueListenable: enableFullScreenNotifier,@@ -1092,100 +1015,6 @@ class _GalleryFileViewerBottomOverlay extends StatelessWidget {}}-// This widget returns Positioned, so its parent must be a Stack.-class _GalleryFileViewerFilmstripOverlay extends StatelessWidget {- final List<EnteFile> files;- final int selectedIndex;- final int? Function(Key key) findChildIndexCallback;- final ValueListenable<bool> enableFullScreenNotifier;- final FileViewerFilmstripSelectionCallback onSelectionChanged;-- const _GalleryFileViewerFilmstripOverlay({- required this.files,- required this.selectedIndex,- required this.findChildIndexCallback,- required this.enableFullScreenNotifier,- required this.onSelectionChanged,- });-- @override- Widget build(BuildContext context) {- final safePadding = MediaQuery.paddingOf(context);- return Positioned(- left: safePadding.left,- right: safePadding.right,- bottom:- safePadding.bottom +- _galleryBottomBarHeight +- kFileViewerFilmstripGap,- height: kFileViewerFilmstripHeight,- child: ValueListenableBuilder<bool>(- valueListenable: enableFullScreenNotifier,- builder: (context, isFullScreen, child) => IgnorePointer(- ignoring: isFullScreen,- child: AnimatedOpacity(- opacity: isFullScreen ? 0 : 1,- duration: const Duration(milliseconds: 250),- curve: Curves.easeInOut,- child: child,- ),- ),- child: FileViewerFilmstrip(- itemCount: files.length,- selectedIndex: selectedIndex,- semanticLabel: context.strings.photoViewerFilmstripLabel,- semanticValueBuilder: (current, total) => context.strings- .photoViewerFilmstripPosition(current: current, total: total),- itemKeyBuilder: (index) => ObjectKey(files[index]),- findChildIndexCallback: findChildIndexCallback,- itemBuilder: (context, index) {- final file = files[index];- return Stack(- fit: StackFit.expand,- children: [- _GalleryFilmstripThumbnail(file: file, fit: BoxFit.cover),- if (file.fileType == FileType.video)- const Center(- child: Icon(- Icons.play_arrow_rounded,- color: Colors.white,- size: 14,- shadows: [Shadow(color: Colors.black87, blurRadius: 3)],- ),- ),- ],- );- },- onSelectionChanged: onSelectionChanged,- ),- ),- );- }-}--class _GalleryFilmstripThumbnail extends StatelessWidget {- final EnteFile file;- final BoxFit fit;-- const _GalleryFilmstripThumbnail({required this.file, required this.fit});-- @override- Widget build(BuildContext context) {- return ThumbnailWidget(- file,- key: ObjectKey(file),- rawThumbnail: true,- diskLoadDeferDuration: galleryThumbnailDiskLoadDeferDuration,- serverLoadDeferDuration: galleryThumbnailServerLoadDeferDuration,- shouldShowSyncStatus: false,- shouldShowFavoriteIcon: false,- shouldShowVideoOverlayIcon: false,- shouldShowLivePhotoOverlay: false,- fit: fit,- );- }-}-// This widget returns Positioned, so its parent must be a Stack.class _GallerySocialOverlay extends StatelessWidget {final EnteFile file;@@ -1215,7 +1044,9 @@ class _GallerySocialOverlay extends StatelessWidget {bottom:padding.bottom +_socialBottomBarClearance +- (hasFilmstrip ? kFileViewerFilmstripAdditionalBottomInset : 0),+ (hasFilmstrip+ ? GalleryFileViewerFilmstripLayout.additionalBottomInset+ : 0),child: ValueListenableBuilder<bool>(valueListenable: fullScreenNotifier,builder: (context, isFullScreen, child) => IgnorePointer(diff --git a/mobile/apps/photos/lib/ui/viewer/file/file_viewer_filmstrip.dart b/mobile/apps/photos/lib/ui/viewer/file/file_viewer_filmstrip.dartindex 09a8b33a54..8429074d45 100644--- a/mobile/apps/photos/lib/ui/viewer/file/file_viewer_filmstrip.dart+++ b/mobile/apps/photos/lib/ui/viewer/file/file_viewer_filmstrip.dart@@ -3,19 +3,17 @@ import "dart:math";import "package:flutter/material.dart";import "package:flutter/services.dart";+import "package:photos/ui/viewer/file/file_viewer_filmstrip_event.dart";+import "package:photos/ui/viewer/file/file_viewer_filmstrip_physics.dart";const fileViewerFilmstripKey = ValueKey<String>("file-viewer-filmstrip");const fileViewerFilmstripListKey = ValueKey<String>("file-viewer-filmstrip-list",);-const fileViewerFilmstripPreviewKey = ValueKey<String>(- "file-viewer-filmstrip-preview",-);-const kFileViewerFilmstripHeight = 45.0;-const kFileViewerFilmstripGap = 6.0;-const kFileViewerFilmstripAdditionalBottomInset =- kFileViewerFilmstripHeight + kFileViewerFilmstripGap + 6.0;+abstract final class FileViewerFilmstripLayout {+ static const height = 45.0;+}const _itemExtent = 33.0;const _selectedThumbnailSize = Size(34, 43);@@ -23,22 +21,7 @@ const _thumbnailSize = Size(29, 35);const _thumbnailBorderRadius = BorderRadius.all(Radius.circular(2.5));const _cacheExtentInItems = 4;const _scrollAnimationDuration = Duration(milliseconds: 180);-const _maxFlingVelocity = 800.0;-// Evaluating a slightly faster platform simulation on a slower clock keeps the-// launch velocity unchanged while extending its distance and settling time.-const _ballisticTimeScale = 0.7;--enum FileViewerFilmstripSelectionSource {- tap,- scrubStart,- scrubPreview,- scrubCommit,-}--enum _AlignmentState { idle, scheduled, deferred }-typedef FileViewerFilmstripSelectionCallback =- void Function(int index, FileViewerFilmstripSelectionSource source);typedef FileViewerFilmstripSemanticValueBuilder =String Function(int current, int total);@@ -48,7 +31,7 @@ class FileViewerFilmstrip extends StatefulWidget {final IndexedWidgetBuilder itemBuilder;final Key? Function(int index)? itemKeyBuilder;final int? Function(Key key)? findChildIndexCallback;- final FileViewerFilmstripSelectionCallback onSelectionChanged;+ final FileViewerFilmstripEventCallback onEvent;final String? semanticLabel;final FileViewerFilmstripSemanticValueBuilder semanticValueBuilder;@@ -56,7 +39,7 @@ class FileViewerFilmstrip extends StatefulWidget {required this.itemCount,required this.selectedIndex,required this.itemBuilder,- required this.onSelectionChanged,+ required this.onEvent,required this.semanticValueBuilder,this.itemKeyBuilder,this.findChildIndexCallback,@@ -71,14 +54,10 @@ class FileViewerFilmstrip extends StatefulWidget {class _FileViewerFilmstripState extends State<FileViewerFilmstrip> {late final ScrollController _scrollController;late final ValueNotifier<int> _focusedIndexNotifier;- final Set<int> _activePointerIds = {};- bool _isScrubbing = false;- _AlignmentState _alignmentState = _AlignmentState.idle;+ final _interaction = _FilmstripInteractionState();int get _focusedIndex => _focusedIndexNotifier.value;- bool get _isInteracting => _isScrubbing || _activePointerIds.isNotEmpty;-@overridevoid initState() {super.initState();@@ -94,14 +73,14 @@ class _FileViewerFilmstripState extends State<FileViewerFilmstrip> {super.didUpdateWidget(oldWidget);final selectedIndex = _clampIndex(widget.selectedIndex);final itemCountChanged = widget.itemCount != oldWidget.itemCount;- final shouldSyncFocus = !_isScrubbing || _focusedIndex >= widget.itemCount;- final focusChanged = shouldSyncFocus && _focusedIndex != selectedIndex;- if (focusChanged) {- _focusedIndexNotifier.value = selectedIndex;- }-- if (!_isScrubbing && (focusChanged || itemCountChanged)) {- _scheduleCentering();+ final shouldSyncFocus =+ !_interaction.isUserScrollSessionActive ||+ _focusedIndex >= widget.itemCount;+ final focusChanged = shouldSyncFocus && _setFocusedIndex(selectedIndex);++ if (!_interaction.isUserScrollSessionActive &&+ (focusChanged || itemCountChanged)) {+ _requestCentering();}}@@ -129,19 +108,19 @@ class _FileViewerFilmstripState extends State<FileViewerFilmstrip> {(constraints.maxWidth - _itemExtent) / 2,);return Listener(- onPointerDown: (event) => _activePointerIds.add(event.pointer),- onPointerUp: _onPointerReleased,- onPointerCancel: _onPointerReleased,+ onPointerDown: (event) => _interaction.pointerDown(event.pointer),+ onPointerUp: _onPointerEnded,+ onPointerCancel: _onPointerEnded,child: NotificationListener<ScrollNotification>(onNotification: _onScrollNotification,child: SizedBox(- height: kFileViewerFilmstripHeight,+ height: FileViewerFilmstripLayout.height,child: ListView.builder(key: fileViewerFilmstripListKey,controller: _scrollController,clipBehavior: Clip.none,scrollDirection: Axis.horizontal,- physics: const _FilmstripScrollPhysics(),+ physics: fileViewerFilmstripPhysics,itemCount: widget.itemCount,itemExtent: _itemExtent,findChildIndexCallback: widget.findChildIndexCallback,@@ -160,30 +139,36 @@ class _FileViewerFilmstripState extends State<FileViewerFilmstrip> {),),builder: (context, focusedIndex, child) {- final selectedIndex = _clampIndex(focusedIndex);+ final clampedFocusedIndex = _clampIndex(focusedIndex);return Semantics(container: true,label: widget.semanticLabel,value: widget.semanticValueBuilder(- selectedIndex + 1,+ clampedFocusedIndex + 1,widget.itemCount,),- increasedValue: selectedIndex < widget.itemCount - 1- ? widget.semanticValueBuilder(selectedIndex + 2, widget.itemCount)+ increasedValue: clampedFocusedIndex < widget.itemCount - 1+ ? widget.semanticValueBuilder(+ clampedFocusedIndex + 2,+ widget.itemCount,+ ): null,- decreasedValue: selectedIndex > 0- ? widget.semanticValueBuilder(selectedIndex, widget.itemCount)+ decreasedValue: clampedFocusedIndex > 0+ ? widget.semanticValueBuilder(+ clampedFocusedIndex,+ widget.itemCount,+ ): null,- onIncrease: selectedIndex < widget.itemCount - 1- ? () => _select(- selectedIndex + 1,- FileViewerFilmstripSelectionSource.tap,+ onIncrease: clampedFocusedIndex < widget.itemCount - 1+ ? () => _selectIndex(+ clampedFocusedIndex + 1,+ FileViewerFilmstripEventType.tap,): null,- onDecrease: selectedIndex > 0- ? () => _select(- selectedIndex - 1,- FileViewerFilmstripSelectionSource.tap,+ onDecrease: clampedFocusedIndex > 0+ ? () => _selectIndex(+ clampedFocusedIndex - 1,+ FileViewerFilmstripEventType.tap,): null,child: child,@@ -195,61 +180,19 @@ class _FileViewerFilmstripState extends State<FileViewerFilmstrip> {Widget _buildItem(BuildContext context, int index) {final item = GestureDetector(behavior: HitTestBehavior.opaque,- onTap: () => _select(index, FileViewerFilmstripSelectionSource.tap),+ onTap: () => _selectIndex(index, FileViewerFilmstripEventType.tap),child: SizedBox(width: _itemExtent,- height: kFileViewerFilmstripHeight,+ height: FileViewerFilmstripLayout.height,child: OverflowBox(minWidth: 0,maxWidth: _selectedThumbnailSize.width,minHeight: 0,maxHeight: _selectedThumbnailSize.height,- child: AnimatedBuilder(- animation: _scrollController,+ child: _FilmstripThumbnailFrame(+ scrollPosition: _scrollController,+ proximity: () => _centerProximity(index),child: widget.itemBuilder(context, index),- builder: (context, thumbnail) {- final proximity = _centerProximity(index);- final size = Size.lerp(- _thumbnailSize,- _selectedThumbnailSize,- proximity,- )!;- return SizedBox.fromSize(- size: size,- child: DecoratedBox(- decoration: BoxDecoration(- borderRadius: _thumbnailBorderRadius,- boxShadow: [- BoxShadow(- color: Color.lerp(- const Color(0x24000000),- const Color(0x33000000),- proximity,- )!,- blurRadius: 2 + proximity,- offset: const Offset(0, 1),- ),- ],- ),- child: ClipRRect(- borderRadius: _thumbnailBorderRadius,- child: Stack(- fit: StackFit.expand,- children: [- thumbnail!,- ColoredBox(- color: Color.lerp(- Colors.black26,- Colors.transparent,- proximity,- )!,- ),- ],- ),- ),- ),- );- },),),),@@ -259,51 +202,55 @@ class _FileViewerFilmstripState extends State<FileViewerFilmstrip> {}bool _onScrollNotification(ScrollNotification notification) {+ // Notifications delimit the drag + ballistic lifecycle. The controller+ // listener updates focus from offsets so thumbnail visuals do not trail+ // scrolling by a rendered frame.if (notification is ScrollStartNotification &¬ification.dragDetails != null) {- _isScrubbing = true;- widget.onSelectionChanged(- _focusedIndex,- FileViewerFilmstripSelectionSource.scrubStart,- );+ _beginUserScrollSession();}if (notification is ScrollEndNotification) {- if (_isScrubbing) {- final finalIndex = _syncFocusToScrollPosition();- _isScrubbing = false;- widget.onSelectionChanged(- finalIndex,- FileViewerFilmstripSelectionSource.scrubCommit,- );- }- _scheduleCentering();+ _finishScrollActivity();}return false;}- int _syncFocusToScrollPosition() {+ void _beginUserScrollSession() {+ _interaction.beginUserScrollSession();+ _emitEvent(_focusedIndex, FileViewerFilmstripEventType.scrubStart);+ }++ void _finishScrollActivity() {+ if (_interaction.isUserScrollSessionActive) {+ final finalIndex = _updateFocusFromScrollOffset();+ _interaction.endUserScrollSession();+ _emitEvent(finalIndex, FileViewerFilmstripEventType.scrubCommit);+ }+ _requestCentering();+ }++ int _updateFocusFromScrollOffset() {final index = _nearestScrolledIndex();if (index != _focusedIndex) {- _select(+ _selectIndex(index,- FileViewerFilmstripSelectionSource.scrubPreview,- center: false,+ FileViewerFilmstripEventType.scrubPreview,+ animateToCenter: false,);}return index;}void _onScrollOffsetChanged() {- if (_isScrubbing) _syncFocusToScrollPosition();+ if (_interaction.isUserScrollSessionActive) {+ _updateFocusFromScrollOffset();+ }}- void _onPointerReleased(PointerEvent event) {- _activePointerIds.remove(event.pointer);- if (_activePointerIds.isEmpty &&- !_isScrubbing &&- _alignmentState == _AlignmentState.deferred) {- _scheduleCentering();+ void _onPointerEnded(PointerEvent event) {+ if (_interaction.pointerEnded(event.pointer)) {+ _requestCentering();}}@@ -312,23 +259,34 @@ class _FileViewerFilmstripState extends State<FileViewerFilmstrip> {return _clampIndex((_scrollController.offset / _itemExtent).round());}- void _select(+ void _selectIndex(int index,- FileViewerFilmstripSelectionSource source, {- bool center = true,+ FileViewerFilmstripEventType type, {+ bool animateToCenter = true,}) {final clampedIndex = _clampIndex(index);- final focusChanged = clampedIndex != _focusedIndex;+ final focusChanged = _setFocusedIndex(clampedIndex);final shouldNotify =focusChanged || clampedIndex != _clampIndex(widget.selectedIndex);- if (focusChanged) {- _focusedIndexNotifier.value = clampedIndex;- }if (shouldNotify) {- unawaited(HapticFeedback.selectionClick());- widget.onSelectionChanged(clampedIndex, source);+ _emitEvent(clampedIndex, type, withHaptic: true);}- if (center) _animateToIndex(clampedIndex);+ if (animateToCenter) _animateToIndex(clampedIndex);+ }++ bool _setFocusedIndex(int index) {+ if (index == _focusedIndex) return false;+ _focusedIndexNotifier.value = index;+ return true;+ }++ void _emitEvent(+ int index,+ FileViewerFilmstripEventType type, {+ bool withHaptic = false,+ }) {+ if (withHaptic) unawaited(HapticFeedback.selectionClick());+ widget.onEvent((index: index, type: type));}double _centerProximity(int index) {@@ -345,21 +303,18 @@ class _FileViewerFilmstripState extends State<FileViewerFilmstrip> {(1 - ((scrollOffset - _offsetForIndex(index)).abs() / _itemExtent)).clamp(0.0, 1.0).toDouble();+ // Smoothstep avoids a visible change in slope as an item enters or leaves+ // the centered state.return linearProximity * linearProximity * (3 - (2 * linearProximity));}- void _scheduleCentering() {- if (widget.itemCount == 0 || _alignmentState == _AlignmentState.scheduled) {+ void _requestCentering() {+ if (widget.itemCount == 0 || !_interaction.tryScheduleCentering()) {return;}- _alignmentState = _AlignmentState.scheduled;WidgetsBinding.instance.addPostFrameCallback((_) {if (!mounted) return;- if (_isInteracting) {- _alignmentState = _AlignmentState.deferred;- return;- }- _alignmentState = _AlignmentState.idle;+ if (!_interaction.resolveScheduledCentering()) return;_animateToIndex(_focusedIndex);});}@@ -388,64 +343,109 @@ class _FileViewerFilmstripState extends State<FileViewerFilmstrip> {double _offsetForIndex(int index) => index * _itemExtent;}-class _FilmstripScrollPhysics extends ScrollPhysics {- const _FilmstripScrollPhysics({super.parent});+enum _CenteringRequestState { idle, scheduled, deferred }- @override- _FilmstripScrollPhysics applyTo(ScrollPhysics? ancestor) =>- _FilmstripScrollPhysics(parent: buildParent(ancestor));+class _FilmstripInteractionState {+ // Pointer state is independent from the scroll session: touching a coasting+ // strip can end its ballistic activity before the replacement drag starts.+ final Set<int> _activePointerIds = {};- @override- double get maxFlingVelocity => _maxFlingVelocity;+ // A user session spans both the direct drag and its ballistic coast.+ bool _userScrollSessionActive = false;- @override- double carriedMomentum(double existingVelocity) {- final momentum = const BouncingScrollPhysics().carriedMomentum(- existingVelocity,- );- return momentum.clamp(-_maxFlingVelocity, _maxFlingVelocity).toDouble();+ // A deferred request is retried when both the session and all pointers end.+ _CenteringRequestState _centeringState = _CenteringRequestState.idle;++ bool get isUserScrollSessionActive => _userScrollSessionActive;++ bool get _blocksCentering =>+ _userScrollSessionActive || _activePointerIds.isNotEmpty;++ void pointerDown(int pointerId) => _activePointerIds.add(pointerId);++ bool pointerEnded(int pointerId) {+ _activePointerIds.remove(pointerId);+ return !_blocksCentering &&+ _centeringState == _CenteringRequestState.deferred;}- @override- Simulation? createBallisticSimulation(- ScrollMetrics position,- double velocity,- ) {- final cappedVelocity = velocity- .clamp(-_maxFlingVelocity, _maxFlingVelocity)- .toDouble();- if (position.outOfRange ||- cappedVelocity.abs() < toleranceFor(position).velocity) {- return super.createBallisticSimulation(position, cappedVelocity);- }- final simulation = super.createBallisticSimulation(- position,- cappedVelocity / _ballisticTimeScale,- );- return simulation == null- ? null- : _FilmstripBallisticSimulation(- simulation,- timeScale: _ballisticTimeScale,- );+ void beginUserScrollSession() {+ _userScrollSessionActive = true;}-}-class _FilmstripBallisticSimulation extends Simulation {- final Simulation _simulation;- final double _timeScale;+ void endUserScrollSession() {+ _userScrollSessionActive = false;+ }- _FilmstripBallisticSimulation(this._simulation, {required double timeScale})- : assert(timeScale > 0 && timeScale <= 1),- _timeScale = timeScale,- super(tolerance: _simulation.tolerance);+ bool tryScheduleCentering() {+ if (_centeringState == _CenteringRequestState.scheduled) return false;+ _centeringState = _CenteringRequestState.scheduled;+ return true;+ }- @override- double x(double time) => _simulation.x(time * _timeScale);+ bool resolveScheduledCentering() {+ assert(_centeringState == _CenteringRequestState.scheduled);+ if (_blocksCentering) {+ _centeringState = _CenteringRequestState.deferred;+ return false;+ }+ _centeringState = _CenteringRequestState.idle;+ return true;+ }+}- @override- double dx(double time) => _simulation.dx(time * _timeScale) * _timeScale;+class _FilmstripThumbnailFrame extends AnimatedWidget {+ final ValueGetter<double> proximity;+ final Widget child;++ const _FilmstripThumbnailFrame({+ required Listenable scrollPosition,+ required this.proximity,+ required this.child,+ }) : super(listenable: scrollPosition);@override- bool isDone(double time) => _simulation.isDone(time * _timeScale);+ Widget build(BuildContext context) {+ final centerProximity = proximity();+ final size = Size.lerp(+ _thumbnailSize,+ _selectedThumbnailSize,+ centerProximity,+ )!;+ return SizedBox.fromSize(+ size: size,+ child: DecoratedBox(+ decoration: BoxDecoration(+ borderRadius: _thumbnailBorderRadius,+ boxShadow: [+ BoxShadow(+ color: Color.lerp(+ const Color(0x24000000),+ const Color(0x33000000),+ centerProximity,+ )!,+ blurRadius: 2 + centerProximity,+ offset: const Offset(0, 1),+ ),+ ],+ ),+ child: ClipRRect(+ borderRadius: _thumbnailBorderRadius,+ child: Stack(+ fit: StackFit.expand,+ children: [+ child,+ ColoredBox(+ color: Color.lerp(+ Colors.black26,+ Colors.transparent,+ centerProximity,+ )!,+ ),+ ],+ ),+ ),+ ),+ );+ }}diff --git a/mobile/apps/photos/lib/ui/viewer/file/file_viewer_filmstrip_coordinator.dart b/mobile/apps/photos/lib/ui/viewer/file/file_viewer_filmstrip_coordinator.dartnew file mode 100644index 0000000000..2e38f7fe92--- /dev/null+++ b/mobile/apps/photos/lib/ui/viewer/file/file_viewer_filmstrip_coordinator.dart@@ -0,0 +1,208 @@+import "package:flutter/foundation.dart";+import "package:flutter/widgets.dart";+import "package:photos/ui/viewer/file/file_viewer_filmstrip_event.dart";++/// Returns the viewer's currently committed page index.+typedef FileViewerFilmstripCurrentIndex = int Function();++/// Returns the stable identity currently stored at [index], or null if absent.+typedef FileViewerFilmstripIdentityAt = Object? Function(int index);++/// Requests an animation-free page jump and reports whether it was dispatched.+typedef FileViewerFilmstripImmediatePageJump = bool Function(int index);++/// Runs [callback] after a guaranteed future frame's paint phase.+typedef FileViewerFilmstripPaintScheduler =+ void Function(VoidCallback callback);++/// Coordinates the filmstrip's interaction lifecycle with the full-page+/// viewer without depending on media, navigation, or application services.+///+/// A user scroll session starts with the drag and remains active through any+/// ballistic coast. During that session, [previewIndex] exposes the centered+/// thumbnail when it differs from the committed page. On commit, the preview+/// stays visible until the destination page has had a guaranteed future paint+/// opportunity.+class FileViewerFilmstripCoordinator {+ final FileViewerFilmstripCurrentIndex _currentIndex;+ final FileViewerFilmstripIdentityAt _identityAt;+ final FileViewerFilmstripImmediatePageJump _jumpToPageImmediately;+ final VoidCallback _requestPauseCurrentMedia;+ final FileViewerFilmstripPaintScheduler _scheduleAfterNextFramePaint;++ final ValueNotifier<int?> _previewIndexNotifier = ValueNotifier(null);++ // The session is the source of truth; previewIndex is its UI-facing mirror.+ _FilmstripSession _session = const _IdleFilmstripSession();+ bool _isDisposed = false;++ FileViewerFilmstripCoordinator({+ required FileViewerFilmstripCurrentIndex currentIndex,+ required FileViewerFilmstripIdentityAt identityAt,+ required FileViewerFilmstripImmediatePageJump jumpToPageImmediately,+ required VoidCallback requestPauseCurrentMedia,+ FileViewerFilmstripPaintScheduler? scheduleAfterNextFramePaint,+ }) : _currentIndex = currentIndex,+ _identityAt = identityAt,+ _jumpToPageImmediately = jumpToPageImmediately,+ _requestPauseCurrentMedia = requestPauseCurrentMedia,+ _scheduleAfterNextFramePaint =+ scheduleAfterNextFramePaint ?? _afterNextFramePaint;++ ValueListenable<int?> get previewIndex => _previewIndexNotifier;++ bool get isUserScrollSessionActive => _session is _ScrubbingFilmstripSession;++ void handleEvent(FileViewerFilmstripEvent event) {+ if (_isDisposed) return;+ final (:index, :type) = event;++ switch (type) {+ case FileViewerFilmstripEventType.tap:+ reset();+ if (_identityAt(index) == null) return;+ if (index != _currentIndex()) {+ _jumpToPageImmediately(index);+ }+ return;+ case FileViewerFilmstripEventType.scrubStart:+ _setSession(const _ScrubbingFilmstripSession());+ return;+ case FileViewerFilmstripEventType.scrubPreview:+ if (_identityAt(index) == null) return;+ final session = _session is _ScrubbingFilmstripSession+ ? _session as _ScrubbingFilmstripSession+ : const _ScrubbingFilmstripSession();+ final previewIndex = index == _currentIndex() ? null : index;+ final shouldRequestPause =+ previewIndex != null && !session.didRequestPause;+ final nextSession = _ScrubbingFilmstripSession(+ previewIndex: previewIndex,+ didRequestPause: session.didRequestPause || shouldRequestPause,+ );+ _setSession(nextSession);+ if (shouldRequestPause && identical(_session, nextSession)) {+ _requestPauseCurrentMedia();+ }+ return;+ case FileViewerFilmstripEventType.scrubCommit:+ final targetIdentity = _identityAt(index);+ if (targetIdentity == null) {+ reset();+ return;+ }+ _commit(index, targetIdentity);+ return;+ }+ }++ void handlePageChanged(int index, Object fileIdentity) {+ if (_isDisposed) return;+ final pendingSession = _session;+ if (pendingSession is! _AwaitingPagePaintFilmstripSession ||+ pendingSession.hasScheduledPaintBarrier ||+ !_matchesAwaitingSession(pendingSession, index, fileIdentity)) {+ return;+ }+ final session = _AwaitingPagePaintFilmstripSession(+ index,+ fileIdentity,+ hasScheduledPaintBarrier: true,+ );+ _setSession(session);+ _scheduleAfterNextFramePaint(() {+ if (_isDisposed ||+ !identical(_session, session) ||+ _currentIndex() != index ||+ !identical(_identityAt(index), fileIdentity)) {+ return;+ }+ reset();+ });+ }++ void reset() {+ if (_isDisposed) return;+ _setSession(const _IdleFilmstripSession());+ }++ void _commit(int index, Object targetIdentity) {+ if (index == _currentIndex()) {+ final session = _session;+ if (session is! _AwaitingPagePaintFilmstripSession ||+ !_matchesAwaitingSession(session, index, targetIdentity)) {+ reset();+ }+ return;+ }++ final session = _AwaitingPagePaintFilmstripSession(index, targetIdentity);+ _setSession(session);+ if (!identical(_session, session)) return;+ if (!_jumpToPageImmediately(index)) {+ reset();+ }+ }++ bool _matchesAwaitingSession(+ _AwaitingPagePaintFilmstripSession session,+ int index,+ Object identity,+ ) => session.index == index && identical(session.identity, identity);++ void _setSession(_FilmstripSession session) {+ _session = session;+ _previewIndexNotifier.value = session.previewIndex;+ }++ void dispose() {+ _isDisposed = true;+ _session = const _IdleFilmstripSession();+ _previewIndexNotifier.dispose();+ }+}++sealed class _FilmstripSession {+ const _FilmstripSession();++ int? get previewIndex;+}++final class _IdleFilmstripSession extends _FilmstripSession {+ const _IdleFilmstripSession();++ @override+ int? get previewIndex => null;+}++final class _ScrubbingFilmstripSession extends _FilmstripSession {+ @override+ final int? previewIndex;+ final bool didRequestPause;++ const _ScrubbingFilmstripSession({+ this.previewIndex,+ this.didRequestPause = false,+ });+}++final class _AwaitingPagePaintFilmstripSession extends _FilmstripSession {+ final int index;+ final Object identity;+ final bool hasScheduledPaintBarrier;++ @override+ int get previewIndex => index;++ const _AwaitingPagePaintFilmstripSession(+ this.index,+ this.identity, {+ this.hasScheduledPaintBarrier = false,+ });+}++void _afterNextFramePaint(VoidCallback callback) {+ WidgetsBinding.instance.scheduleFrameCallback((_) {+ WidgetsBinding.instance.addPostFrameCallback((_) => callback());+ });+}diff --git a/mobile/apps/photos/lib/ui/viewer/file/file_viewer_filmstrip_event.dart b/mobile/apps/photos/lib/ui/viewer/file/file_viewer_filmstrip_event.dartnew file mode 100644index 0000000000..1373bee976--- /dev/null+++ b/mobile/apps/photos/lib/ui/viewer/file/file_viewer_filmstrip_event.dart@@ -0,0 +1,17 @@+import "package:flutter/foundation.dart";++/// The interaction that caused a [FileViewerFilmstripEvent].+enum FileViewerFilmstripEventType { tap, scrubStart, scrubPreview, scrubCommit }++/// A user interaction emitted by the filmstrip.+///+/// Scrub start and commit are lifecycle events, so they are emitted even when+/// [index] has not changed. Preview and tap events identify a newly focused+/// item.+typedef FileViewerFilmstripEvent = ({+ int index,+ FileViewerFilmstripEventType type,+});++typedef FileViewerFilmstripEventCallback =+ ValueChanged<FileViewerFilmstripEvent>;diff --git a/mobile/apps/photos/lib/ui/viewer/file/file_viewer_filmstrip_physics.dart b/mobile/apps/photos/lib/ui/viewer/file/file_viewer_filmstrip_physics.dartnew file mode 100644index 0000000000..d10dbc1cc2--- /dev/null+++ b/mobile/apps/photos/lib/ui/viewer/file/file_viewer_filmstrip_physics.dart@@ -0,0 +1,73 @@+import "package:flutter/widgets.dart";++/// The capped, long-coasting scroll behavior used by the file-viewer filmstrip.+const ScrollPhysics fileViewerFilmstripPhysics = _FilmstripScrollPhysics();++const _maxFlingVelocity = 800.0;+// Evaluating a slightly faster platform simulation on a slower clock keeps the+// launch velocity unchanged while extending its distance and settling time.+const _ballisticTimeScale = 0.7;++class _FilmstripScrollPhysics extends ScrollPhysics {+ const _FilmstripScrollPhysics({super.parent});++ @override+ _FilmstripScrollPhysics applyTo(ScrollPhysics? ancestor) =>+ _FilmstripScrollPhysics(parent: buildParent(ancestor));++ @override+ double get maxFlingVelocity => _maxFlingVelocity;++ @override+ double carriedMomentum(double existingVelocity) {+ // Preserve repeated-fling acceleration on clamping platforms as well as+ // platforms whose parent physics already bounce.+ final momentum = const BouncingScrollPhysics().carriedMomentum(+ existingVelocity,+ );+ return momentum.clamp(-_maxFlingVelocity, _maxFlingVelocity).toDouble();+ }++ @override+ Simulation? createBallisticSimulation(+ ScrollMetrics position,+ double velocity,+ ) {+ final cappedVelocity = velocity+ .clamp(-_maxFlingVelocity, _maxFlingVelocity)+ .toDouble();+ if (position.outOfRange ||+ cappedVelocity.abs() < toleranceFor(position).velocity) {+ return super.createBallisticSimulation(position, cappedVelocity);+ }+ final simulation = super.createBallisticSimulation(+ position,+ cappedVelocity / _ballisticTimeScale,+ );+ return simulation == null+ ? null+ : _FilmstripBallisticSimulation(+ simulation,+ timeScale: _ballisticTimeScale,+ );+ }+}++class _FilmstripBallisticSimulation extends Simulation {+ final Simulation _simulation;+ final double _timeScale;++ _FilmstripBallisticSimulation(this._simulation, {required double timeScale})+ : assert(timeScale > 0 && timeScale <= 1),+ _timeScale = timeScale,+ super(tolerance: _simulation.tolerance);++ @override+ double x(double time) => _simulation.x(time * _timeScale);++ @override+ double dx(double time) => _simulation.dx(time * _timeScale) * _timeScale;++ @override+ bool isDone(double time) => _simulation.isDone(time * _timeScale);+}diff --git a/mobile/apps/photos/lib/ui/viewer/file/file_viewer_filmstrip_preview_handoff.dart b/mobile/apps/photos/lib/ui/viewer/file/file_viewer_filmstrip_preview_handoff.dartdeleted file mode 100644index 43d7a61650..0000000000--- a/mobile/apps/photos/lib/ui/viewer/file/file_viewer_filmstrip_preview_handoff.dart+++ /dev/null@@ -1,82 +0,0 @@-import "package:flutter/widgets.dart";--/// Keeps the filmstrip preview visible until the committed page has painted.-///-/// Each pending clear is tied to both a generation and the file object so a-/// late callback cannot clear a newer preview after rapid navigation or a list-/// mutation.-class FileViewerFilmstripPreviewHandoff extends ValueNotifier<int?> {- final void Function(VoidCallback callback) _scheduleAfterNextFramePaint;-- int _generation = 0;- int? _pendingCommitIndex;- Object? _pendingFileIdentity;- bool _isDisposed = false;-- FileViewerFilmstripPreviewHandoff({- void Function(VoidCallback callback)? scheduleAfterNextFramePaint,- }) : _scheduleAfterNextFramePaint =- scheduleAfterNextFramePaint ?? _afterNextFramePaint,- super(null);-- void showPreview(int index) {- _invalidatePendingCommit();- value = index;- }-- void beginCommit({required int index, required Object fileIdentity}) {- _generation++;- _pendingCommitIndex = index;- _pendingFileIdentity = fileIdentity;- value = index;- }-- bool isPendingCommit({required int index, required Object fileIdentity}) =>- _matchesPendingCommit(index, fileIdentity);-- void onPageChanged({- required int index,- required Object fileIdentity,- required VoidCallback onPagePainted,- }) {- if (!_matchesPendingCommit(index, fileIdentity)) return;- final generation = _generation;- _scheduleAfterNextFramePaint(() {- if (_isDisposed ||- generation != _generation ||- !_matchesPendingCommit(index, fileIdentity)) {- return;- }- onPagePainted();- });- }-- void clear() {- _invalidatePendingCommit();- value = null;- }-- void _invalidatePendingCommit() {- _generation++;- _pendingCommitIndex = null;- _pendingFileIdentity = null;- }-- bool _matchesPendingCommit(int index, Object fileIdentity) =>- value == index &&- _pendingCommitIndex == index &&- identical(_pendingFileIdentity, fileIdentity);-- @override- void dispose() {- _isDisposed = true;- _invalidatePendingCommit();- super.dispose();- }-}--void _afterNextFramePaint(VoidCallback callback) {- WidgetsBinding.instance.scheduleFrameCallback((_) {- WidgetsBinding.instance.addPostFrameCallback((_) => callback());- });-}diff --git a/mobile/apps/photos/lib/ui/viewer/file/file_viewer_filmstrip_preview_layer.dart b/mobile/apps/photos/lib/ui/viewer/file/file_viewer_filmstrip_preview_layer.dartnew file mode 100644index 0000000000..b218477ac4--- /dev/null+++ b/mobile/apps/photos/lib/ui/viewer/file/file_viewer_filmstrip_preview_layer.dart@@ -0,0 +1,46 @@+import "package:flutter/foundation.dart";+import "package:flutter/material.dart";++const fileViewerFilmstripPreviewKey = ValueKey<String>(+ "file-viewer-filmstrip-preview",+);++typedef FileViewerFilmstripPreviewBuilder =+ Widget Function(BuildContext context, int index);++/// Opaque preview shown above the page viewer while the filmstrip is scrubbed.+///+/// A non-null preview index always produces an absorbing, opaque layer; the+/// builder supplies only its content.+///+/// This widget returns [Positioned.fill], so its parent must be a [Stack].+class FileViewerFilmstripPreviewLayer extends StatelessWidget {+ final ValueListenable<int?> previewIndex;+ final FileViewerFilmstripPreviewBuilder itemBuilder;++ const FileViewerFilmstripPreviewLayer({+ required this.previewIndex,+ required this.itemBuilder,+ super.key,+ });++ @override+ Widget build(BuildContext context) {+ return ValueListenableBuilder<int?>(+ valueListenable: previewIndex,+ builder: (context, index, _) {+ if (index == null) return const SizedBox.shrink();+ final preview = itemBuilder(context, index);+ return Positioned.fill(+ child: AbsorbPointer(+ child: ColoredBox(+ key: fileViewerFilmstripPreviewKey,+ color: Colors.black,+ child: preview,+ ),+ ),+ );+ },+ );+ }+}diff --git a/mobile/apps/photos/lib/ui/viewer/file/gallery_file_viewer_filmstrip.dart b/mobile/apps/photos/lib/ui/viewer/file/gallery_file_viewer_filmstrip.dartnew file mode 100644index 0000000000..079c6f6b8e--- /dev/null+++ b/mobile/apps/photos/lib/ui/viewer/file/gallery_file_viewer_filmstrip.dart@@ -0,0 +1,155 @@+import "package:ente_strings/ente_strings.dart";+import "package:flutter/foundation.dart";+import "package:flutter/material.dart";+import "package:photos/core/constants.dart";+import "package:photos/models/file/file.dart";+import "package:photos/models/file/file_type.dart";+import "package:photos/ui/viewer/file/file_viewer_filmstrip.dart";+import "package:photos/ui/viewer/file/file_viewer_filmstrip_event.dart";+import "package:photos/ui/viewer/file/file_viewer_filmstrip_preview_layer.dart";+import "package:photos/ui/viewer/file/thumbnail_widget.dart";++/// Spacing contributed by the filmstrip to the gallery viewer's chrome.+abstract final class GalleryFileViewerFilmstripLayout {+ static const bottomControlsGap = 6.0;+ static const upperContentGap = 6.0;+ static const additionalBottomInset =+ FileViewerFilmstripLayout.height + bottomControlsGap + upperContentGap;+}++/// Whether the gallery-specific viewer may expose its neighboring files.+bool shouldShowGalleryFileViewerFilmstrip({+ required bool isEnabled,+ required bool isMinimalistic,+ required bool isGuestView,+ required int itemCount,+}) => isEnabled && !isMinimalistic && !isGuestView && itemCount > 1;++/// Renders the opaque, lightweight gallery thumbnail used while scrubbing.+///+/// This widget returns [Positioned.fill], so its parent must be a [Stack].+class GalleryFileViewerFilmstripPreviewLayer extends StatelessWidget {+ final List<EnteFile> files;+ final ValueListenable<int?> previewIndex;++ const GalleryFileViewerFilmstripPreviewLayer({+ required this.files,+ required this.previewIndex,+ super.key,+ });++ @override+ Widget build(BuildContext context) {+ return FileViewerFilmstripPreviewLayer(+ previewIndex: previewIndex,+ itemBuilder: (context, index) {+ if (index < 0 || index >= files.length) {+ return const SizedBox.shrink();+ }+ return _GalleryFilmstripThumbnail(+ file: files[index],+ fit: BoxFit.contain,+ );+ },+ );+ }+}++/// Positions and presents the filmstrip above the gallery viewer's controls.+///+/// This widget returns [Positioned], so its parent must be a [Stack].+class GalleryFileViewerFilmstripOverlay extends StatelessWidget {+ final List<EnteFile> files;+ final int selectedIndex;+ final double bottomControlsHeight;+ final int? Function(Key key) findChildIndexCallback;+ final ValueListenable<bool> enableFullScreenNotifier;+ final FileViewerFilmstripEventCallback onEvent;++ const GalleryFileViewerFilmstripOverlay({+ required this.files,+ required this.selectedIndex,+ required this.bottomControlsHeight,+ required this.findChildIndexCallback,+ required this.enableFullScreenNotifier,+ required this.onEvent,+ super.key,+ });++ @override+ Widget build(BuildContext context) {+ final safePadding = MediaQuery.paddingOf(context);+ return Positioned(+ left: safePadding.left,+ right: safePadding.right,+ bottom:+ safePadding.bottom ++ bottomControlsHeight ++ GalleryFileViewerFilmstripLayout.bottomControlsGap,+ height: FileViewerFilmstripLayout.height,+ child: ValueListenableBuilder<bool>(+ valueListenable: enableFullScreenNotifier,+ builder: (context, isFullScreen, child) => IgnorePointer(+ ignoring: isFullScreen,+ child: AnimatedOpacity(+ opacity: isFullScreen ? 0 : 1,+ duration: const Duration(milliseconds: 250),+ curve: Curves.easeInOut,+ child: child,+ ),+ ),+ child: FileViewerFilmstrip(+ itemCount: files.length,+ selectedIndex: selectedIndex,+ semanticLabel: context.strings.photoViewerFilmstripLabel,+ semanticValueBuilder: (current, total) => context.strings+ .photoViewerFilmstripPosition(current: current, total: total),+ itemKeyBuilder: (index) => ObjectKey(files[index]),+ findChildIndexCallback: findChildIndexCallback,+ itemBuilder: (context, index) {+ final file = files[index];+ return Stack(+ fit: StackFit.expand,+ children: [+ _GalleryFilmstripThumbnail(file: file, fit: BoxFit.cover),+ if (file.fileType == FileType.video)+ const Center(+ child: Icon(+ Icons.play_arrow_rounded,+ color: Colors.white,+ size: 14,+ shadows: [Shadow(color: Colors.black87, blurRadius: 3)],+ ),+ ),+ ],+ );+ },+ onEvent: onEvent,+ ),+ ),+ );+ }+}++class _GalleryFilmstripThumbnail extends StatelessWidget {+ final EnteFile file;+ final BoxFit fit;++ const _GalleryFilmstripThumbnail({required this.file, required this.fit});++ @override+ Widget build(BuildContext context) {+ return ThumbnailWidget(+ file,+ key: ObjectKey(file),+ rawThumbnail: true,+ diskLoadDeferDuration: galleryThumbnailDiskLoadDeferDuration,+ serverLoadDeferDuration: galleryThumbnailServerLoadDeferDuration,+ shouldShowSyncStatus: false,+ shouldShowFavoriteIcon: false,+ shouldShowVideoOverlayIcon: false,+ shouldShowLivePhotoOverlay: false,+ fit: fit,+ );+ }+}diff --git a/mobile/apps/photos/test/ui/viewer/file/detail_page_configuration_test.dart b/mobile/apps/photos/test/ui/viewer/file/detail_page_configuration_test.dartindex 213f9def9a..e85160401a 100644--- a/mobile/apps/photos/test/ui/viewer/file/detail_page_configuration_test.dart+++ b/mobile/apps/photos/test/ui/viewer/file/detail_page_configuration_test.dart@@ -2,6 +2,7 @@ import "package:flutter_test/flutter_test.dart";import "package:photos/models/file/file.dart";import "package:photos/models/file/file_type.dart";import "package:photos/ui/viewer/file/detail_page.dart";+import "package:photos/ui/viewer/file/gallery_file_viewer_filmstrip.dart";void main() {test("gallery filmstrip defaults off and copyWith preserves opt-in", () {@@ -18,4 +19,60 @@ void main() {);expect(galleryConfig.copyWith().showGalleryFilmstrip, isTrue);});++ test("gallery filmstrip visibility requires an eligible gallery", () {+ for (final scenario in [+ (+ name: "eligible gallery",+ isEnabled: true,+ isMinimalistic: false,+ isGuestView: false,+ itemCount: 2,+ expected: true,+ ),+ (+ name: "not opted in",+ isEnabled: false,+ isMinimalistic: false,+ isGuestView: false,+ itemCount: 2,+ expected: false,+ ),+ (+ name: "minimalistic viewer",+ isEnabled: true,+ isMinimalistic: true,+ isGuestView: false,+ itemCount: 2,+ expected: false,+ ),+ (+ name: "guest view",+ isEnabled: true,+ isMinimalistic: false,+ isGuestView: true,+ itemCount: 2,+ expected: false,+ ),+ (+ name: "single file",+ isEnabled: true,+ isMinimalistic: false,+ isGuestView: false,+ itemCount: 1,+ expected: false,+ ),+ ]) {+ expect(+ shouldShowGalleryFileViewerFilmstrip(+ isEnabled: scenario.isEnabled,+ isMinimalistic: scenario.isMinimalistic,+ isGuestView: scenario.isGuestView,+ itemCount: scenario.itemCount,+ ),+ scenario.expected,+ reason: scenario.name,+ );+ }+ });}diff --git a/mobile/apps/photos/test/ui/viewer/file/file_viewer_filmstrip_coordinator_test.dart b/mobile/apps/photos/test/ui/viewer/file/file_viewer_filmstrip_coordinator_test.dartnew file mode 100644index 0000000000..8429db9474--- /dev/null+++ b/mobile/apps/photos/test/ui/viewer/file/file_viewer_filmstrip_coordinator_test.dart@@ -0,0 +1,292 @@+import "package:flutter/foundation.dart";+import "package:flutter/material.dart";+import "package:flutter_test/flutter_test.dart";+import "package:photos/ui/viewer/file/file_viewer_filmstrip_coordinator.dart";+import "package:photos/ui/viewer/file/file_viewer_filmstrip_event.dart";+import "package:photos/ui/viewer/file/file_viewer_filmstrip_preview_layer.dart";++void main() {+ test("a tap cancels transient state and jumps immediately", () {+ final harness = _CoordinatorHarness();+ addTearDown(harness.dispose);++ harness.send(7, FileViewerFilmstripEventType.scrubStart);+ harness.send(8, FileViewerFilmstripEventType.scrubPreview);+ expect(harness.coordinator.previewIndex.value, 8);++ harness.send(12, FileViewerFilmstripEventType.tap);++ expect(harness.jumps, [12]);+ expect(harness.selectedIndex, 12);+ expect(harness.coordinator.previewIndex.value, isNull);+ expect(harness.coordinator.isUserScrollSessionActive, isFalse);++ harness.send(12, FileViewerFilmstripEventType.tap);+ expect(harness.jumps, [12]);+ });++ test("scrubbing previews live and requests one media pause per session", () {+ final harness = _CoordinatorHarness();+ addTearDown(harness.dispose);++ harness.send(7, FileViewerFilmstripEventType.scrubStart);+ expect(harness.coordinator.isUserScrollSessionActive, isTrue);+ expect(harness.coordinator.previewIndex.value, isNull);++ harness.send(8, FileViewerFilmstripEventType.scrubPreview);+ expect(harness.coordinator.previewIndex.value, 8);+ expect(harness.pauseCount, 1);++ harness.send(9, FileViewerFilmstripEventType.scrubPreview);+ expect(harness.coordinator.previewIndex.value, 9);++ harness.send(7, FileViewerFilmstripEventType.scrubPreview);+ expect(harness.coordinator.previewIndex.value, isNull);++ harness.send(8, FileViewerFilmstripEventType.scrubPreview);+ expect(harness.coordinator.previewIndex.value, 8);+ expect(harness.pauseCount, 1);+ expect(harness.jumps, isEmpty);+ expect(harness.coordinator.isUserScrollSessionActive, isTrue);++ harness.send(7, FileViewerFilmstripEventType.scrubPreview);+ harness.send(7, FileViewerFilmstripEventType.scrubCommit);+ expect(harness.coordinator.previewIndex.value, isNull);+ expect(harness.coordinator.isUserScrollSessionActive, isFalse);+ expect(harness.jumps, isEmpty);++ harness.send(7, FileViewerFilmstripEventType.scrubStart);+ harness.send(8, FileViewerFilmstripEventType.scrubPreview);+ expect(harness.pauseCount, 2);+ expect(harness.coordinator.isUserScrollSessionActive, isTrue);+ });++ test("commit installs its handoff before a synchronous page change", () {+ final harness = _CoordinatorHarness();+ addTearDown(harness.dispose);++ harness.send(7, FileViewerFilmstripEventType.scrubStart);+ harness.send(8, FileViewerFilmstripEventType.scrubPreview);+ harness.send(8, FileViewerFilmstripEventType.scrubCommit);++ expect(harness.jumps, [8]);+ expect(harness.selectedIndex, 8);+ expect(harness.coordinator.previewIndex.value, 8);+ expect(harness.coordinator.isUserScrollSessionActive, isFalse);+ expect(harness.paintBarriers, hasLength(1));++ harness.coordinator.handlePageChanged(8, harness.identities[8]);+ expect(harness.paintBarriers, hasLength(1));++ harness.send(8, FileViewerFilmstripEventType.scrubCommit);+ expect(harness.jumps, [8]);+ expect(harness.coordinator.previewIndex.value, 8);++ harness.paintBarriers.single();+ expect(harness.coordinator.previewIndex.value, isNull);+ });++ test("a detached page viewer cancels the commit", () {+ final harness = _CoordinatorHarness()..pageAttached = false;+ addTearDown(harness.dispose);++ harness.send(7, FileViewerFilmstripEventType.scrubStart);+ harness.send(8, FileViewerFilmstripEventType.scrubPreview);+ harness.send(8, FileViewerFilmstripEventType.scrubCommit);++ expect(harness.jumps, isEmpty);+ expect(harness.coordinator.previewIndex.value, isNull);+ expect(harness.coordinator.isUserScrollSessionActive, isFalse);+ expect(harness.paintBarriers, isEmpty);+ });++ test("a stale paint barrier cannot clear a newer scrub preview", () {+ final harness = _CoordinatorHarness();+ addTearDown(harness.dispose);++ harness.send(7, FileViewerFilmstripEventType.scrubStart);+ harness.send(8, FileViewerFilmstripEventType.scrubPreview);+ harness.send(8, FileViewerFilmstripEventType.scrubCommit);+ final staleBarrier = harness.paintBarriers.single;++ harness.send(8, FileViewerFilmstripEventType.scrubStart);+ harness.send(9, FileViewerFilmstripEventType.scrubPreview);+ staleBarrier();++ expect(harness.coordinator.previewIndex.value, 9);+ expect(harness.coordinator.isUserScrollSessionActive, isTrue);+ });++ test("page handoff requires the same file identity", () {+ final harness = _CoordinatorHarness(synchronousPageChanges: false);+ addTearDown(harness.dispose);++ harness.send(7, FileViewerFilmstripEventType.scrubStart);+ harness.send(8, FileViewerFilmstripEventType.scrubPreview);+ harness.send(8, FileViewerFilmstripEventType.scrubCommit);+ final committedIdentity = harness.identities[8];++ harness.coordinator.handlePageChanged(8, Object());+ expect(harness.paintBarriers, isEmpty);++ harness.coordinator.handlePageChanged(8, committedIdentity);+ expect(harness.paintBarriers, hasLength(1));+ harness.identities[8] = Object();+ harness.paintBarriers.single();++ expect(harness.coordinator.previewIndex.value, 8);+ });++ testWidgets("keeps the preview through the committed page's first paint", (+ tester,+ ) async {+ var selectedIndex = 0;+ final identities = [Object(), Object()];+ final committedPage = ValueNotifier(0);+ final targetPainter = _CountingPainter();+ late FileViewerFilmstripCoordinator coordinator;+ coordinator = FileViewerFilmstripCoordinator(+ currentIndex: () => selectedIndex,+ identityAt: (index) => identities[index],+ jumpToPageImmediately: (index) {+ selectedIndex = index;+ WidgetsBinding.instance.addPostFrameCallback((_) {+ committedPage.value = index;+ coordinator.handlePageChanged(index, identities[index]);+ });+ tester.binding.scheduleFrame();+ return true;+ },+ requestPauseCurrentMedia: () {},+ );+ addTearDown(coordinator.dispose);+ addTearDown(committedPage.dispose);++ await tester.pumpWidget(+ _PreviewHandoffHarness(+ previewIndex: coordinator.previewIndex,+ committedPage: committedPage,+ targetPainter: targetPainter,+ ),+ );++ coordinator.handleEvent((+ index: 0,+ type: FileViewerFilmstripEventType.scrubStart,+ ));+ coordinator.handleEvent((+ index: 1,+ type: FileViewerFilmstripEventType.scrubPreview,+ ));+ await tester.pump();+ expect(find.byKey(fileViewerFilmstripPreviewKey), findsOneWidget);+ expect(targetPainter.paintCount, 0);++ coordinator.handleEvent((+ index: 1,+ type: FileViewerFilmstripEventType.scrubCommit,+ ));+ await tester.pump();++ expect(committedPage.value, 1);+ expect(targetPainter.paintCount, 0);+ expect(find.byKey(fileViewerFilmstripPreviewKey), findsOneWidget);++ await tester.pump();++ expect(targetPainter.paintCount, greaterThan(0));+ expect(find.byKey(fileViewerFilmstripPreviewKey), findsOneWidget);+ expect(coordinator.previewIndex.value, isNull);++ await tester.pump();+ expect(find.byKey(fileViewerFilmstripPreviewKey), findsNothing);+ });+}++class _CoordinatorHarness {+ final List<Object> identities = List.generate(20, (_) => Object());+ final List<int> jumps = [];+ final List<VoidCallback> paintBarriers = [];+ final bool synchronousPageChanges;++ late final FileViewerFilmstripCoordinator coordinator;+ int selectedIndex = 7;+ int pauseCount = 0;+ bool pageAttached = true;++ _CoordinatorHarness({this.synchronousPageChanges = true}) {+ coordinator = FileViewerFilmstripCoordinator(+ currentIndex: () => selectedIndex,+ identityAt: (index) =>+ index >= 0 && index < identities.length ? identities[index] : null,+ jumpToPageImmediately: (index) {+ if (!pageAttached) return false;+ jumps.add(index);+ selectedIndex = index;+ if (synchronousPageChanges) {+ coordinator.handlePageChanged(index, identities[index]);+ }+ return true;+ },+ requestPauseCurrentMedia: () => pauseCount++,+ scheduleAfterNextFramePaint: paintBarriers.add,+ );+ }++ void send(int index, FileViewerFilmstripEventType type) {+ coordinator.handleEvent((index: index, type: type));+ }++ void dispose() => coordinator.dispose();+}++class _PreviewHandoffHarness extends StatelessWidget {+ final ValueListenable<int?> previewIndex;+ final ValueNotifier<int> committedPage;+ final CustomPainter targetPainter;++ const _PreviewHandoffHarness({+ required this.previewIndex,+ required this.committedPage,+ required this.targetPainter,+ });++ @override+ Widget build(BuildContext context) => MaterialApp(+ home: Scaffold(+ body: Stack(+ fit: StackFit.expand,+ children: [+ ValueListenableBuilder<int>(+ valueListenable: committedPage,+ builder: (context, page, _) => page == 1+ ? CustomPaint(+ painter: targetPainter,+ child: const ColoredBox(color: Colors.blue),+ )+ : const ColoredBox(color: Colors.black),+ ),+ FileViewerFilmstripPreviewLayer(+ previewIndex: previewIndex,+ itemBuilder: (context, index) => ColoredBox(+ color: Colors.grey,+ child: Center(child: Text("Preview $index")),+ ),+ ),+ ],+ ),+ ),+ );+}++class _CountingPainter extends CustomPainter {+ int paintCount = 0;++ @override+ void paint(Canvas canvas, Size size) {+ paintCount++;+ }++ @override+ bool shouldRepaint(covariant _CountingPainter oldDelegate) => false;+}diff --git a/mobile/apps/photos/test/ui/viewer/file/file_viewer_filmstrip_preview_handoff_test.dart b/mobile/apps/photos/test/ui/viewer/file/file_viewer_filmstrip_preview_handoff_test.dartdeleted file mode 100644index 31929b3007..0000000000--- a/mobile/apps/photos/test/ui/viewer/file/file_viewer_filmstrip_preview_handoff_test.dart+++ /dev/null@@ -1,170 +0,0 @@-import "package:flutter/material.dart";-import "package:flutter_test/flutter_test.dart";-import "package:photos/ui/viewer/file/file_viewer_filmstrip_preview_handoff.dart";--const _previewKey = ValueKey<String>("filmstrip-preview-handoff-test");-const _targetPageKey = ValueKey<String>("filmstrip-target-page-test");--void main() {- testWidgets("keeps the preview through the committed page's first paint", (- tester,- ) async {- final handoff = FileViewerFilmstripPreviewHandoff();- final committedPage = ValueNotifier(0);- final targetPainter = _CountingPainter();- addTearDown(handoff.dispose);- addTearDown(committedPage.dispose);-- await tester.pumpWidget(- _HandoffHarness(- handoff: handoff,- committedPage: committedPage,- targetPainter: targetPainter,- ),- );-- handoff.showPreview(1);- await tester.pump();- expect(find.byKey(_previewKey), findsOneWidget);- expect(targetPainter.paintCount, 0);-- final targetFile = Object();- handoff.beginCommit(index: 1, fileIdentity: targetFile);- WidgetsBinding.instance.addPostFrameCallback((_) {- committedPage.value = 1;- handoff.onPageChanged(- index: 1,- fileIdentity: targetFile,- onPagePainted: handoff.clear,- );- });- tester.binding.scheduleFrame();-- expect(handoff.value, 1);-- await tester.pump();- expect(committedPage.value, 1);- expect(targetPainter.paintCount, 0);- expect(find.byKey(_previewKey), findsOneWidget);-- await tester.pump();-- expect(find.byKey(_targetPageKey), findsOneWidget);- expect(targetPainter.paintCount, greaterThan(0));- expect(find.byKey(_previewKey), findsOneWidget);- expect(handoff.value, isNull);-- await tester.pump();- expect(find.byKey(_previewKey), findsNothing);- });-- test("a stale page-change callback cannot clear a newer preview", () {- VoidCallback? scheduledCallback;- final handoff = FileViewerFilmstripPreviewHandoff(- scheduleAfterNextFramePaint: (callback) => scheduledCallback = callback,- );- addTearDown(handoff.dispose);- var pagePaintedCount = 0;-- final staleFile = Object();- handoff.beginCommit(index: 1, fileIdentity: staleFile);- handoff.onPageChanged(- index: 1,- fileIdentity: staleFile,- onPagePainted: () {- pagePaintedCount++;- handoff.clear();- },- );- handoff.showPreview(2);- scheduledCallback!();-- expect(pagePaintedCount, 0);- expect(handoff.value, 2);- });-- test("a page callback must match the committed file identity", () {- VoidCallback? scheduledCallback;- final handoff = FileViewerFilmstripPreviewHandoff(- scheduleAfterNextFramePaint: (callback) => scheduledCallback = callback,- );- addTearDown(handoff.dispose);-- final committedFile = Object();- final replacementFile = Object();- handoff.beginCommit(index: 1, fileIdentity: committedFile);- expect(- handoff.isPendingCommit(index: 1, fileIdentity: committedFile),- isTrue,- );- expect(- handoff.isPendingCommit(index: 1, fileIdentity: replacementFile),- isFalse,- );- handoff.onPageChanged(- index: 1,- fileIdentity: replacementFile,- onPagePainted: handoff.clear,- );-- expect(scheduledCallback, isNull);- expect(handoff.value, 1);- });-}--class _HandoffHarness extends StatelessWidget {- final FileViewerFilmstripPreviewHandoff handoff;- final ValueNotifier<int> committedPage;- final CustomPainter targetPainter;-- const _HandoffHarness({- required this.handoff,- required this.committedPage,- required this.targetPainter,- });-- @override- Widget build(BuildContext context) => MaterialApp(- home: Scaffold(- body: Stack(- fit: StackFit.expand,- children: [- ValueListenableBuilder<int>(- valueListenable: committedPage,- builder: (context, page, _) => page == 1- ? CustomPaint(- key: _targetPageKey,- painter: targetPainter,- child: const ColoredBox(color: Colors.blue),- )- : const ColoredBox(color: Colors.black),- ),- ValueListenableBuilder<int?>(- valueListenable: handoff,- builder: (context, previewIndex, _) => previewIndex == null- ? const SizedBox.shrink()- : Positioned.fill(- child: ColoredBox(- key: _previewKey,- color: Colors.grey,- child: Center(child: Text("Preview $previewIndex")),- ),- ),- ),- ],- ),- ),- );-}--class _CountingPainter extends CustomPainter {- int paintCount = 0;-- @override- void paint(Canvas canvas, Size size) {- paintCount++;- }-- @override- bool shouldRepaint(covariant _CountingPainter oldDelegate) => false;-}diff --git a/mobile/apps/photos/test/ui/viewer/file/file_viewer_filmstrip_test.dart b/mobile/apps/photos/test/ui/viewer/file/file_viewer_filmstrip_test.dartindex cda75b3be8..f4be55ab7f 100644--- a/mobile/apps/photos/test/ui/viewer/file/file_viewer_filmstrip_test.dart+++ b/mobile/apps/photos/test/ui/viewer/file/file_viewer_filmstrip_test.dart@@ -3,6 +3,7 @@ import "package:flutter/semantics.dart" show SemanticsAction;import "package:flutter/services.dart" show SystemChannels;import "package:flutter_test/flutter_test.dart";import "package:photos/ui/viewer/file/file_viewer_filmstrip.dart";+import "package:photos/ui/viewer/file/file_viewer_filmstrip_event.dart";void main() {testWidgets("centers the selected item and exposes adjustable semantics", (@@ -58,8 +59,8 @@ void main() {);await tester.pumpAndSettle();expect(key.currentState!.selections, [- (index: 8, source: FileViewerFilmstripSelectionSource.tap),- (index: 7, source: FileViewerFilmstripSelectionSource.tap),+ (index: 8, type: FileViewerFilmstripEventType.tap),+ (index: 7, type: FileViewerFilmstripEventType.tap),]);_expectCentered(tester, 7);} finally {@@ -83,7 +84,7 @@ void main() {expect(key.currentState!.selections.single, (index: 8,- source: FileViewerFilmstripSelectionSource.tap,+ type: FileViewerFilmstripEventType.tap,));await tester.pump();expect(_thumbnailSize(tester, 8), const Size(29, 35));@@ -95,7 +96,7 @@ void main() {await tester.pumpAndSettle();expect(key.currentState!.selections, [- (index: 8, source: FileViewerFilmstripSelectionSource.tap),+ (index: 8, type: FileViewerFilmstripEventType.tap),]);expect(haptics.count, 1);_expectCentered(tester, 8);@@ -140,8 +141,8 @@ void main() {final incomingAt25 = _thumbnailSize(tester, 8);expect(outgoingAt25.width, inExclusiveRange(29, 34));expect(incomingAt25.width, inExclusiveRange(29, outgoingAt25.width));- expect(key.currentState!.selections.map((event) => event.source), [- FileViewerFilmstripSelectionSource.scrubStart,+ expect(key.currentState!.selections.map((event) => event.type), [+ FileViewerFilmstripEventType.scrubStart,]);expect(haptics.count, 0);@@ -161,7 +162,7 @@ void main() {expect((incomingAt55.width - incomingAt45.width).abs(), lessThan(2));expect(key.currentState!.selections.last, (index: 8,- source: FileViewerFilmstripSelectionSource.scrubPreview,+ type: FileViewerFilmstripEventType.scrubPreview,));expect(haptics.count, 1);@@ -175,7 +176,7 @@ void main() {await tester.pumpAndSettle();expect(key.currentState!.selections.last, (index: 8,- source: FileViewerFilmstripSelectionSource.scrubCommit,+ type: FileViewerFilmstripEventType.scrubCommit,));expect(haptics.count, 1);_expectCentered(tester, 8);@@ -211,7 +212,7 @@ void main() {expect(key.currentState!.selections.last, (index: 8,- source: FileViewerFilmstripSelectionSource.scrubPreview,+ type: FileViewerFilmstripEventType.scrubPreview,));expect(buildCounts[7], initialBuilds[7]);expect(buildCounts[8], initialBuilds[8]);@@ -244,16 +245,14 @@ void main() {expect(key.currentState!.selections.where(- (event) =>- event.source == FileViewerFilmstripSelectionSource.scrubStart,+ (event) => event.type == FileViewerFilmstripEventType.scrubStart,).length,1,);var previewsBeforeUp = key.currentState!.selections.where(- (event) =>- event.source == FileViewerFilmstripSelectionSource.scrubPreview,+ (event) => event.type == FileViewerFilmstripEventType.scrubPreview,).toList();expect(previewsBeforeUp.map((event) => event.index), [8]);@@ -265,8 +264,7 @@ void main() {previewsBeforeUp = key.currentState!.selections.where(- (event) =>- event.source == FileViewerFilmstripSelectionSource.scrubPreview,+ (event) => event.type == FileViewerFilmstripEventType.scrubPreview,).toList();expect(previewsBeforeUp.map((event) => event.index), [8, 9]);@@ -277,8 +275,7 @@ void main() {previewsBeforeUp = key.currentState!.selections.where(- (event) =>- event.source == FileViewerFilmstripSelectionSource.scrubPreview,+ (event) => event.type == FileViewerFilmstripEventType.scrubPreview,).toList();expect(previewsBeforeUp.map((event) => event.index), [8, 9, 8]);@@ -293,13 +290,12 @@ void main() {expect(haptics.count, previewsBeforeUp.length);expect(key.currentState!.selections.last, (index: previewIndex,- source: FileViewerFilmstripSelectionSource.scrubCommit,+ type: FileViewerFilmstripEventType.scrubCommit,));expect(key.currentState!.selections.where(- (event) =>- event.source == FileViewerFilmstripSelectionSource.scrubCommit,+ (event) => event.type == FileViewerFilmstripEventType.scrubCommit,).length,1,@@ -408,15 +404,13 @@ void main() {final position = _filmstripPosition(tester);final previewsAtLaunch = key.currentState!.selections.where(- (event) =>- event.source == FileViewerFilmstripSelectionSource.scrubPreview,+ (event) => event.type == FileViewerFilmstripEventType.scrubPreview,).length;expect(position.isScrollingNotifier.value, isTrue);expect(key.currentState!.selections.where(- (event) =>- event.source == FileViewerFilmstripSelectionSource.scrubCommit,+ (event) => event.type == FileViewerFilmstripEventType.scrubCommit,),isEmpty,);@@ -426,16 +420,14 @@ void main() {expect(key.currentState!.selections.where(- (event) =>- event.source == FileViewerFilmstripSelectionSource.scrubPreview,+ (event) => event.type == FileViewerFilmstripEventType.scrubPreview,).length,greaterThan(previewsAtLaunch),);expect(key.currentState!.selections.where(- (event) =>- event.source == FileViewerFilmstripSelectionSource.scrubCommit,+ (event) => event.type == FileViewerFilmstripEventType.scrubCommit,),isEmpty,);@@ -445,21 +437,18 @@ void main() {final selections = key.currentState!.selections;final previews = selections.where(- (event) =>- event.source == FileViewerFilmstripSelectionSource.scrubPreview,+ (event) => event.type == FileViewerFilmstripEventType.scrubPreview,).toList();final commits = selections.where(- (event) =>- event.source == FileViewerFilmstripSelectionSource.scrubCommit,+ (event) => event.type == FileViewerFilmstripEventType.scrubCommit,).toList();expect(selections.where(- (event) =>- event.source == FileViewerFilmstripSelectionSource.scrubStart,+ (event) => event.type == FileViewerFilmstripEventType.scrubStart,).length,1,@@ -522,8 +511,8 @@ void main() {await tester.pumpAndSettle();expect(key.currentState!.selections, [- (index: 7, source: FileViewerFilmstripSelectionSource.scrubStart),- (index: 7, source: FileViewerFilmstripSelectionSource.scrubCommit),+ (index: 7, type: FileViewerFilmstripEventType.scrubStart),+ (index: 7, type: FileViewerFilmstripEventType.scrubCommit),]);expect(haptics.count, 0);_expectCentered(tester, 7);@@ -680,8 +669,7 @@ class _FilmstripHarness extends StatefulWidget {class _FilmstripHarnessState extends State<_FilmstripHarness> {late int itemCount = widget.itemCount;late int selectedIndex = widget.selectedIndex;- final selections =- <({int index, FileViewerFilmstripSelectionSource source})>[];+ final selections = <FileViewerFilmstripEvent>[];void update({int? itemCount, int? selectedIndex}) {setState(() {@@ -705,11 +693,11 @@ class _FilmstripHarnessState extends State<_FilmstripHarness> {color: Color(0xFF000000 + index),);},- onSelectionChanged: (index, source) {- selections.add((index: index, source: source));- if (source == FileViewerFilmstripSelectionSource.tap ||- source == FileViewerFilmstripSelectionSource.scrubCommit) {- setState(() => selectedIndex = index);+ onEvent: (event) {+ selections.add(event);+ if (event.type == FileViewerFilmstripEventType.tap ||+ event.type == FileViewerFilmstripEventType.scrubCommit) {+ setState(() => selectedIndex = event.index);}},);