Skip to content

armgit / ente

Public Imported from GitHub
0

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

[mob][photos] Add filmstrip scrubbing to gallery viewer

ashil-pilotb40ff72e5778
diff --git a/mobile/apps/photos/lib/events/pause_video_event.dart b/mobile/apps/photos/lib/events/pause_video_event.dart
index 3583abddbf..2069f3cb23 100644
--- a/mobile/apps/photos/lib/events/pause_video_event.dart
+++ b/mobile/apps/photos/lib/events/pause_video_event.dart
@@ -1,3 +1,7 @@
import "package:photos/events/event.dart";
-class PauseVideoEvent extends Event {}
+class PauseVideoEvent extends Event {
+ final String? fileTag;
+
+ PauseVideoEvent({this.fileTag});
+}
diff --git a/mobile/apps/photos/lib/states/detail_page_state.dart b/mobile/apps/photos/lib/states/detail_page_state.dart
index 05ca490da6..314b14fe21 100644
--- a/mobile/apps/photos/lib/states/detail_page_state.dart
+++ b/mobile/apps/photos/lib/states/detail_page_state.dart
@@ -48,6 +48,7 @@ class InheritedDetailPageState extends InheritedWidget {
final ValueNotifier<String?> showingThumbnailFallbackNotifier;
final ValueNotifier<bool> isZoomedNotifier;
final ValueNotifier<ZoomTransform> zoomTransformNotifier;
+ final ValueNotifier<double> bottomControlsAdditionalInsetNotifier;
// ignore: prefer_const_constructors_in_immutables
InheritedDetailPageState({
@@ -58,6 +59,7 @@ class InheritedDetailPageState extends InheritedWidget {
required this.showingThumbnailFallbackNotifier,
required this.isZoomedNotifier,
required this.zoomTransformNotifier,
+ required this.bottomControlsAdditionalInsetNotifier,
});
static InheritedDetailPageState of(BuildContext context) =>
@@ -107,5 +109,7 @@ class InheritedDetailPageState extends InheritedWidget {
oldWidget.showingThumbnailFallbackNotifier !=
showingThumbnailFallbackNotifier ||
oldWidget.isZoomedNotifier != isZoomedNotifier ||
- oldWidget.zoomTransformNotifier != zoomTransformNotifier;
+ oldWidget.zoomTransformNotifier != zoomTransformNotifier ||
+ oldWidget.bottomControlsAdditionalInsetNotifier !=
+ bottomControlsAdditionalInsetNotifier;
}
diff --git a/mobile/apps/photos/lib/ui/viewer/file/detail_page.dart b/mobile/apps/photos/lib/ui/viewer/file/detail_page.dart
index 90b5cc9ff7..f5e141feb1 100644
--- a/mobile/apps/photos/lib/ui/viewer/file/detail_page.dart
+++ b/mobile/apps/photos/lib/ui/viewer/file/detail_page.dart
@@ -12,10 +12,12 @@ 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";
import "package:photos/events/guest_view_event.dart";
+import "package:photos/events/pause_video_event.dart";
import "package:photos/models/file/extensions/file_props.dart";
import 'package:photos/models/file/file.dart';
import "package:photos/models/file/file_type.dart";
@@ -35,11 +37,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_widget.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';
@@ -60,6 +64,7 @@ class DetailPageConfiguration {
final DetailPageMode mode;
final bool isLocalOnlyContext;
final bool showEditAction;
+ final bool showGalleryFilmstrip;
final GalleryType? galleryType;
final FutureOr<void> Function(BuildContext context)? onBackPressed;
@@ -72,6 +77,7 @@ class DetailPageConfiguration {
this.mode = DetailPageMode.full,
this.isLocalOnlyContext = false,
this.showEditAction = true,
+ this.showGalleryFilmstrip = false,
this.galleryType,
this.onBackPressed,
this.onPageReady,
@@ -85,6 +91,7 @@ class DetailPageConfiguration {
DetailPageMode? mode,
bool? isLocalOnlyContext,
bool? showEditAction,
+ bool? showGalleryFilmstrip,
GalleryType? galleryType,
FutureOr<void> Function(BuildContext context)? onBackPressed,
void Function(BuildContext context)? onPageReady,
@@ -96,6 +103,7 @@ class DetailPageConfiguration {
mode: mode ?? this.mode,
isLocalOnlyContext: isLocalOnlyContext ?? this.isLocalOnlyContext,
showEditAction: showEditAction ?? this.showEditAction,
+ showGalleryFilmstrip: showGalleryFilmstrip ?? this.showGalleryFilmstrip,
galleryType: galleryType ?? this.galleryType,
onBackPressed: onBackPressed ?? this.onBackPressed,
onPageReady: onPageReady ?? this.onPageReady,
@@ -118,6 +126,16 @@ class _DetailPageState extends State<DetailPage> {
final _showingThumbnailFallbackNotifier = ValueNotifier<String?>(null);
final _isZoomedNotifier = ValueNotifier(false);
final _zoomTransformNotifier = ValueNotifier(ZoomTransform.identity);
+ final _bottomControlsAdditionalInsetNotifier = ValueNotifier(0.0);
+
+ @override
+ void initState() {
+ super.initState();
+ _bottomControlsAdditionalInsetNotifier.value =
+ widget.config.showGalleryFilmstrip && widget.config.files.length > 1
+ ? kFileViewerFilmstripAdditionalBottomInset
+ : 0;
+ }
@override
void dispose() {
@@ -126,6 +144,7 @@ class _DetailPageState extends State<DetailPage> {
_showingThumbnailFallbackNotifier.dispose();
_isZoomedNotifier.dispose();
_zoomTransformNotifier.dispose();
+ _bottomControlsAdditionalInsetNotifier.dispose();
super.dispose();
}
@@ -139,6 +158,8 @@ class _DetailPageState extends State<DetailPage> {
showingThumbnailFallbackNotifier: _showingThumbnailFallbackNotifier,
isZoomedNotifier: _isZoomedNotifier,
zoomTransformNotifier: _zoomTransformNotifier,
+ bottomControlsAdditionalInsetNotifier:
+ _bottomControlsAdditionalInsetNotifier,
child: _Body(widget.config),
);
}
@@ -159,6 +180,7 @@ class _BodyState extends State<_Body> {
List<EnteFile>? _files;
late PageController _pageController;
final _selectedIndexNotifier = ValueNotifier(0);
+ final _filmstripPreviewIndexNotifier = ValueNotifier<int?>(null);
final _inlineTextDetectionController = InlineTextDetectionController();
bool _isFirstOpened = true;
bool isGuestView = false;
@@ -169,11 +191,17 @@ class _BodyState extends State<_Body> {
QrCodeDetectionHelper? _qrHelper;
final Map<String, File> _renderedFiles = {};
final _playbackSpeed = ValueNotifier<double>(1.0);
+ final Map<EnteFile, int> _fileIndexByIdentity = Map.identity();
+ ValueNotifier<double>? _bottomControlsAdditionalInsetNotifier;
+ bool _isFilmstripScrubbing = false;
+ bool _didPauseVideoForFilmstripScrub = false;
+ int? _pendingFilmstripCommitIndex;
@override
void initState() {
super.initState();
_files = widget.config.files;
+ _rebuildFileIndex();
final configuredIndex = widget.config.selectedIndex;
final selectedIndex = _fileAt(configuredIndex) == null
@@ -184,10 +212,15 @@ class _BodyState extends State<_Body> {
_guestViewEventSubscription = Bus.instance.on<GuestViewEvent>().listen((
event,
) {
+ if (isGuestView == event.isGuestView &&
+ swipeLocked == event.swipeLocked) {
+ return;
+ }
setState(() {
isGuestView = event.isGuestView;
swipeLocked = event.swipeLocked;
});
+ _syncBottomControlsInset();
});
_captionUpdatedSubscription = Bus.instance
.on<FileCaptionUpdatedEvent>()
@@ -214,12 +247,22 @@ class _BodyState extends State<_Body> {
});
}
+ @override
+ void didChangeDependencies() {
+ super.didChangeDependencies();
+ _bottomControlsAdditionalInsetNotifier = InheritedDetailPageState.of(
+ context,
+ ).bottomControlsAdditionalInsetNotifier;
+ _syncBottomControlsInset();
+ }
+
@override
void dispose() {
_guestViewEventSubscription.cancel();
_captionUpdatedSubscription.cancel();
_pageController.dispose();
_selectedIndexNotifier.dispose();
+ _filmstripPreviewIndexNotifier.dispose();
_qrHelper?.dispose();
_playbackSpeed.dispose();
super.dispose();
@@ -266,23 +309,28 @@ class _BodyState extends State<_Body> {
child: Scaffold(
appBar: PreferredSize(
preferredSize: const Size.fromHeight(80),
- child: ValueListenableBuilder(
- builder: (BuildContext context, int selectedIndex, _) {
- return FileAppBar(
- _files![selectedIndex],
- _onFileRemoved,
- _onEditFileRequested,
- enableFullScreenNotifier: InheritedDetailPageState.of(
- context,
- ).enableFullScreenNotifier,
- galleryType: widget.config.galleryType,
- mode: widget.config.mode,
- showEditAction: widget.config.showEditAction,
- onBackPressed: widget.config.onBackPressed,
- playbackSpeed: _playbackSpeed,
- );
- },
- valueListenable: _selectedIndexNotifier,
+ child: ValueListenableBuilder<int?>(
+ valueListenable: _filmstripPreviewIndexNotifier,
+ builder: (context, previewIndex, child) =>
+ AbsorbPointer(absorbing: previewIndex != null, child: child),
+ child: ValueListenableBuilder(
+ builder: (BuildContext context, int selectedIndex, _) {
+ return FileAppBar(
+ _files![selectedIndex],
+ _onFileRemoved,
+ _onEditFileRequested,
+ enableFullScreenNotifier: InheritedDetailPageState.of(
+ context,
+ ).enableFullScreenNotifier,
+ galleryType: widget.config.galleryType,
+ mode: widget.config.mode,
+ showEditAction: widget.config.showEditAction,
+ onBackPressed: widget.config.onBackPressed,
+ playbackSpeed: _playbackSpeed,
+ );
+ },
+ valueListenable: _selectedIndexNotifier,
+ ),
),
),
extendBodyBehindAppBar: true,
@@ -316,23 +364,12 @@ class _BodyState extends State<_Body> {
final fullScreenNotifier = InheritedDetailPageState.of(
context,
).enableFullScreenNotifier;
- return Stack(
- children: [
- _GalleryFileViewerBottomOverlay(
- file: file,
- mode: widget.config.mode,
- isGuestView: isGuestView,
- enableFullScreenNotifier: fullScreenNotifier,
- ),
- if (widget.config.mode != DetailPageMode.minimalistic)
- FileBottomBar(
- file,
- onFileRemoved: _onFileRemoved,
- userID: Configuration.instance.getUserID(),
- enableFullScreenNotifier: fullScreenNotifier,
- isLocalOnlyContext: widget.config.isLocalOnlyContext,
- ),
- ],
+ return _GalleryFileViewerBottomOverlay(
+ file: file,
+ mode: widget.config.mode,
+ isGuestView: isGuestView,
+ hasFilmstrip: _shouldShowFilmstrip,
+ enableFullScreenNotifier: fullScreenNotifier,
);
},
valueListenable: _selectedIndexNotifier,
@@ -344,6 +381,7 @@ class _BodyState extends State<_Body> {
file: _files![selectedIndex],
mode: widget.config.mode,
isGuestView: isGuestView,
+ hasFilmstrip: _shouldShowFilmstrip,
);
},
),
@@ -416,6 +454,75 @@ class _BodyState extends State<_Body> {
return const SizedBox();
},
),
+ if (_shouldShowFilmstrip)
+ ValueListenableBuilder<int?>(
+ valueListenable: _filmstripPreviewIndexNotifier,
+ 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: ThumbnailWidget(
+ previewFile,
+ key: ObjectKey(previewFile),
+ rawThumbnail: true,
+ shouldShowSyncStatus: false,
+ shouldShowFavoriteIcon: false,
+ shouldShowVideoOverlayIcon: false,
+ shouldShowLivePhotoOverlay: false,
+ fit: BoxFit.contain,
+ ),
+ ),
+ ),
+ );
+ },
+ ),
+ if (widget.config.mode != DetailPageMode.minimalistic)
+ ValueListenableBuilder<int?>(
+ valueListenable: _filmstripPreviewIndexNotifier,
+ builder: (context, previewIndex, child) => AbsorbPointer(
+ // The toolbar stays visible, but must not act on the old
+ // committed file while another file is being previewed.
+ absorbing: previewIndex != null,
+ child: child,
+ ),
+ child: ValueListenableBuilder(
+ valueListenable: _selectedIndexNotifier,
+ builder: (BuildContext context, int selectedIndex, _) {
+ return FileBottomBar(
+ _files![selectedIndex],
+ onFileRemoved: _onFileRemoved,
+ userID: Configuration.instance.getUserID(),
+ enableFullScreenNotifier: InheritedDetailPageState.of(
+ context,
+ ).enableFullScreenNotifier,
+ isLocalOnlyContext: widget.config.isLocalOnlyContext,
+ );
+ },
+ ),
+ ),
+ if (_shouldShowFilmstrip)
+ ValueListenableBuilder(
+ valueListenable: _selectedIndexNotifier,
+ builder: (BuildContext context, int selectedIndex, _) {
+ return _GalleryFileViewerFilmstripOverlay(
+ files: _files!,
+ selectedIndex: selectedIndex,
+ findChildIndexCallback: _findChildIndex,
+ enableFullScreenNotifier: InheritedDetailPageState.of(
+ context,
+ ).enableFullScreenNotifier,
+ onSelectionChanged: _onFilmstripSelectionChanged,
+ );
+ },
+ ),
],
),
),
@@ -449,7 +556,9 @@ class _BodyState extends State<_Body> {
clipBehavior: Clip.none,
itemBuilder: (context, index) {
final file = _files![index];
- _preloadFiles(index);
+ if (!_isFilmstripScrubbing) {
+ _preloadFiles(index);
+ }
final Widget fileContent = FileWidget(
file,
autoPlay: shouldAutoPlay(),
@@ -496,12 +605,16 @@ class _BodyState extends State<_Body> {
},
child: fileContent,
);
- return ValueListenableBuilder(
- valueListenable: _selectedIndexNotifier,
- builder: (context, selectedIndex, _) =>
- HeroMode(enabled: index == selectedIndex, child: page),
+ return KeyedSubtree(
+ key: ObjectKey(file),
+ child: ValueListenableBuilder(
+ valueListenable: _selectedIndexNotifier,
+ builder: (context, selectedIndex, _) =>
+ HeroMode(enabled: index == selectedIndex, child: page),
+ ),
);
},
+ findChildIndexCallback: _findChildIndex,
onPageChanged: (index) {
final file = _fileAt(index);
if (file == null) {
@@ -521,9 +634,12 @@ class _BodyState extends State<_Body> {
} else {
_selectedIndexNotifier.value = index;
}
- Bus.instance.fire(GuestViewEvent(isGuestView, swipeLocked));
- _updateSharedCollectionState(file);
- _evaluateQrIfEligible(file);
+ if (_pendingFilmstripCommitIndex == index) {
+ _clearFilmstripPreview();
+ }
+ if (!_isFilmstripScrubbing) {
+ _runSelectedFileSideEffects(file);
+ }
},
physics: _shouldDisableScroll || swipeLocked
? const NeverScrollableScrollPhysics()
@@ -559,29 +675,123 @@ 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) {
+ _filmstripPreviewIndexNotifier.value = null;
+ break;
+ }
+ if (!_didPauseVideoForFilmstripScrub) {
+ _didPauseVideoForFilmstripScrub = true;
+ final selectedFile = _selectedFile;
+ if (selectedFile?.fileType == FileType.video) {
+ Bus.instance.fire(PauseVideoEvent(fileTag: selectedFile!.tag));
+ }
+ }
+ if (_filmstripPreviewIndexNotifier.value != index) {
+ _filmstripPreviewIndexNotifier.value = index;
+ }
+ break;
+ case FileViewerFilmstripSelectionSource.scrubCommit:
+ _isFilmstripScrubbing = false;
+ if (!_pageController.hasClients) {
+ _clearFilmstripPreview();
+ return;
+ }
+ if (index == _selectedIndexNotifier.value) {
+ _clearFilmstripPreview();
+ return;
+ }
+ _pendingFilmstripCommitIndex = index;
+ if (_filmstripPreviewIndexNotifier.value != index) {
+ _filmstripPreviewIndexNotifier.value = index;
+ }
+ _pageController.jumpToPage(index);
+ break;
+ }
+ }
+
+ void _clearFilmstripPreview() {
+ _isFilmstripScrubbing = false;
+ _didPauseVideoForFilmstripScrub = false;
+ _pendingFilmstripCommitIndex = null;
+ if (_filmstripPreviewIndexNotifier.value != null) {
+ _filmstripPreviewIndexNotifier.value = null;
+ }
+ }
+
+ void _runSelectedFileSideEffects(EnteFile file) {
+ Bus.instance.fire(GuestViewEvent(isGuestView, swipeLocked));
+ _updateSharedCollectionState(file);
+ _evaluateQrIfEligible(file);
+ }
+
Future<void> _onFileRemoved(EnteFile file) async {
if (!mounted || _files == null) return;
- final totalFiles = _files!.length;
+ _clearFilmstripPreview();
+ final files = _files!;
+ final removedIndex = _indexOfFile(file);
+ if (removedIndex < 0) {
+ _logger.warning("Ignoring removal for a file outside the viewer");
+ return;
+ }
+ final totalFiles = files.length;
if (totalFiles == 1) {
Navigator.of(context).pop();
return;
}
+
+ final oldSelectedIndex = _selectedIndexNotifier.value;
+ final nextSelectedIndex = removedIndex < oldSelectedIndex
+ ? oldSelectedIndex - 1
+ : removedIndex == oldSelectedIndex
+ ? min(oldSelectedIndex, totalFiles - 2)
+ : oldSelectedIndex;
setState(() {
_shouldDisableScroll = false;
- _files!.removeAt(_selectedIndexNotifier.value);
- _selectedIndexNotifier.value = min(
- _selectedIndexNotifier.value,
- totalFiles - 2,
- );
+ files.removeAt(removedIndex);
+ _rebuildFileIndex();
+ if (_selectedIndexNotifier.value == nextSelectedIndex) {
+ // The item at this index may have changed even though the index did not.
+ // ignore: invalid_use_of_protected_member, invalid_use_of_visible_for_testing_member
+ _selectedIndexNotifier.notifyListeners();
+ } else {
+ _selectedIndexNotifier.value = nextSelectedIndex;
+ }
});
_clearZoomNotifiers();
- final currentPageIndex = _pageController.page!.round();
- final int targetPageIndex = _files!.length > currentPageIndex
- ? currentPageIndex
- : currentPageIndex - 1;
- if (_files!.isNotEmpty) {
+ _syncBottomControlsInset();
+ final selectedFile = _selectedFile;
+ if (selectedFile != null) {
+ unawaited(_updateSharedCollectionState(selectedFile));
+ _evaluateQrIfEligible(selectedFile);
+ }
+
+ await WidgetsBinding.instance.endOfFrame;
+ if (!mounted || !_pageController.hasClients) return;
+ final currentPageIndex = _pageController.page?.round() ?? oldSelectedIndex;
+ if (currentPageIndex != nextSelectedIndex) {
await _pageController.animateToPage(
- targetPageIndex,
+ nextSelectedIndex,
duration: const Duration(milliseconds: 200),
curve: Curves.easeInOut,
);
@@ -706,6 +916,22 @@ 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;
+
+ void _syncBottomControlsInset() {
+ final notifier = _bottomControlsAdditionalInsetNotifier;
+ if (notifier == null) return;
+ if (!_shouldShowFilmstrip) _clearFilmstripPreview();
+ final inset = _shouldShowFilmstrip
+ ? kFileViewerFilmstripAdditionalBottomInset
+ : 0.0;
+ if (notifier.value != inset) notifier.value = inset;
+ }
+
EnteFile? _fileAt(int index) {
final files = _files;
if (files == null || index < 0 || index >= files.length) {
@@ -713,18 +939,48 @@ class _BodyState extends State<_Body> {
}
return files[index];
}
+
+ int _indexOfFile(EnteFile file) {
+ final files = _files;
+ if (files == null) return -1;
+ final identityIndex = _fileIndexByIdentity[file];
+ if (identityIndex != null) return identityIndex;
+
+ final identifier = detailPageFileIdentifier(file);
+ if (identifier == null) return -1;
+ return files.indexWhere(
+ (item) => detailPageFileIdentifier(item) == identifier,
+ );
+ }
+
+ int? _findChildIndex(Key key) {
+ if (key is! ObjectKey) return null;
+ final value = key.value;
+ return value is EnteFile ? _fileIndexByIdentity[value] : null;
+ }
+
+ void _rebuildFileIndex() {
+ _fileIndexByIdentity.clear();
+ final files = _files;
+ if (files == null) return;
+ for (var index = 0; index < files.length; index++) {
+ _fileIndexByIdentity[files[index]] = index;
+ }
+ }
}
class _GalleryFileViewerBottomOverlay extends StatelessWidget {
final EnteFile file;
final DetailPageMode mode;
final bool isGuestView;
+ final bool hasFilmstrip;
final ValueListenable<bool> enableFullScreenNotifier;
const _GalleryFileViewerBottomOverlay({
required this.file,
required this.mode,
required this.isGuestView,
+ required this.hasFilmstrip,
required this.enableFullScreenNotifier,
});
@@ -742,6 +998,9 @@ class _GalleryFileViewerBottomOverlay extends StatelessWidget {
final captionStyle = getEnteTextTheme(
context,
).mini.copyWith(color: textBaseDark.withValues(alpha: 0.8));
+ final filmstripInset = hasFilmstrip
+ ? kFileViewerFilmstripAdditionalBottomInset
+ : 0.0;
return ValueListenableBuilder<bool>(
valueListenable: enableFullScreenNotifier,
builder: (context, isFullScreen, _) {
@@ -761,6 +1020,7 @@ class _GalleryFileViewerBottomOverlay extends StatelessWidget {
height:
safePadding.bottom +
_galleryBottomBarHeight +
+ filmstripInset +
(captionText == null
? 0
: _galleryCaptionGap +
@@ -792,8 +1052,11 @@ class _GalleryFileViewerBottomOverlay extends StatelessWidget {
(isVideo
? kVideoProgressBottomInset +
kVideoProgressHeight +
+ filmstripInset +
kVideoCaptionGap
- : _galleryBottomBarHeight + _galleryCaptionGap),
+ : _galleryBottomBarHeight +
+ filmstripInset +
+ _galleryCaptionGap),
child: Align(
alignment: Alignment.centerLeft,
child: GestureDetector(
@@ -825,16 +1088,101 @@ 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: [
+ ThumbnailWidget(
+ file,
+ key: ObjectKey(file),
+ rawThumbnail: true,
+ diskLoadDeferDuration: galleryThumbnailDiskLoadDeferDuration,
+ serverLoadDeferDuration:
+ galleryThumbnailServerLoadDeferDuration,
+ shouldShowSyncStatus: false,
+ shouldShowFavoriteIcon: false,
+ shouldShowVideoOverlayIcon: false,
+ shouldShowLivePhotoOverlay: false,
+ 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,
+ ),
+ ),
+ );
+ }
+}
+
// This widget returns Positioned, so its parent must be a Stack.
class _GallerySocialOverlay extends StatelessWidget {
final EnteFile file;
final DetailPageMode mode;
final bool isGuestView;
+ final bool hasFilmstrip;
const _GallerySocialOverlay({
required this.file,
required this.mode,
required this.isGuestView,
+ required this.hasFilmstrip,
});
@override
@@ -849,7 +1197,10 @@ class _GallerySocialOverlay extends StatelessWidget {
).enableFullScreenNotifier;
return Positioned(
right: padding.right + _socialRightInset,
- bottom: padding.bottom + _socialBottomBarClearance,
+ bottom:
+ padding.bottom +
+ _socialBottomBarClearance +
+ (hasFilmstrip ? kFileViewerFilmstripAdditionalBottomInset : 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.dart
new file mode 100644
index 0000000000..4a4cd80f6f
--- /dev/null
+++ b/mobile/apps/photos/lib/ui/viewer/file/file_viewer_filmstrip.dart
@@ -0,0 +1,358 @@
+import "dart:async";
+import "dart:math";
+
+import "package:flutter/material.dart";
+import "package:flutter/services.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;
+
+const _itemExtent = 35.0;
+const _selectedThumbnailWidth = 34.0;
+const _selectedThumbnailHeight = 43.0;
+const _thumbnailWidth = 29.0;
+const _thumbnailHeight = 35.0;
+const _cacheExtentInItems = 4;
+const _selectionAnimationDuration = Duration(milliseconds: 120);
+const _scrollAnimationDuration = Duration(milliseconds: 180);
+const _scrubThrottleDuration = Duration(milliseconds: 50);
+
+enum FileViewerFilmstripSelectionSource {
+ tap,
+ scrubStart,
+ scrubPreview,
+ scrubCommit,
+}
+
+typedef FileViewerFilmstripSelectionCallback =
+ void Function(int index, FileViewerFilmstripSelectionSource source);
+typedef FileViewerFilmstripSemanticValueBuilder =
+ String Function(int current, int total);
+
+class FileViewerFilmstrip extends StatefulWidget {
+ final int itemCount;
+ final int selectedIndex;
+ final IndexedWidgetBuilder itemBuilder;
+ final Key? Function(int index)? itemKeyBuilder;
+ final int? Function(Key key)? findChildIndexCallback;
+ final FileViewerFilmstripSelectionCallback onSelectionChanged;
+ final String? semanticLabel;
+ final FileViewerFilmstripSemanticValueBuilder semanticValueBuilder;
+
+ const FileViewerFilmstrip({
+ required this.itemCount,
+ required this.selectedIndex,
+ required this.itemBuilder,
+ required this.onSelectionChanged,
+ required this.semanticValueBuilder,
+ this.itemKeyBuilder,
+ this.findChildIndexCallback,
+ this.semanticLabel,
+ super.key = fileViewerFilmstripKey,
+ }) : assert(itemCount >= 0);
+
+ @override
+ State<FileViewerFilmstrip> createState() => _FileViewerFilmstripState();
+}
+
+class _FileViewerFilmstripState extends State<FileViewerFilmstrip> {
+ late final ScrollController _scrollController;
+ late int _visualSelectedIndex;
+ bool _isUserScrollSession = false;
+ bool _alignmentScheduled = false;
+ Timer? _scrubThrottleTimer;
+ int? _pendingScrubIndex;
+
+ @override
+ void initState() {
+ super.initState();
+ _visualSelectedIndex = _clampIndex(widget.selectedIndex);
+ _scrollController = ScrollController(
+ initialScrollOffset: _offsetForIndex(_visualSelectedIndex),
+ );
+ }
+
+ @override
+ void didUpdateWidget(covariant FileViewerFilmstrip oldWidget) {
+ super.didUpdateWidget(oldWidget);
+ final selectedIndex = _clampIndex(widget.selectedIndex);
+ if (!_isUserScrollSession) {
+ _visualSelectedIndex = selectedIndex;
+ } else if (_visualSelectedIndex >= widget.itemCount) {
+ _visualSelectedIndex = selectedIndex;
+ }
+
+ if (!_isUserScrollSession &&
+ (selectedIndex != _clampIndex(oldWidget.selectedIndex) ||
+ widget.itemCount != oldWidget.itemCount)) {
+ _scheduleAlignment(selectedIndex, animate: true);
+ }
+ }
+
+ @override
+ void dispose() {
+ _scrubThrottleTimer?.cancel();
+ _scrollController.dispose();
+ super.dispose();
+ }
+
+ @override
+ Widget build(BuildContext context) {
+ if (widget.itemCount == 0) {
+ return const SizedBox.shrink();
+ }
+
+ final selectedIndex = _clampIndex(_visualSelectedIndex);
+ return Semantics(
+ container: true,
+ label: widget.semanticLabel,
+ value: widget.semanticValueBuilder(selectedIndex + 1, widget.itemCount),
+ increasedValue: selectedIndex < widget.itemCount - 1
+ ? widget.semanticValueBuilder(selectedIndex + 2, widget.itemCount)
+ : null,
+ decreasedValue: selectedIndex > 0
+ ? widget.semanticValueBuilder(selectedIndex, widget.itemCount)
+ : null,
+ onIncrease: selectedIndex < widget.itemCount - 1
+ ? () => _select(
+ selectedIndex + 1,
+ FileViewerFilmstripSelectionSource.tap,
+ )
+ : null,
+ onDecrease: selectedIndex > 0
+ ? () => _select(
+ selectedIndex - 1,
+ FileViewerFilmstripSelectionSource.tap,
+ )
+ : null,
+ child: ExcludeSemantics(
+ child: LayoutBuilder(
+ builder: (context, constraints) {
+ final horizontalPadding = max(
+ 0.0,
+ (constraints.maxWidth - _itemExtent) / 2,
+ );
+ return NotificationListener<ScrollNotification>(
+ onNotification: _onScrollNotification,
+ child: SizedBox(
+ height: kFileViewerFilmstripHeight,
+ child: ListView.builder(
+ key: fileViewerFilmstripListKey,
+ controller: _scrollController,
+ clipBehavior: Clip.none,
+ scrollDirection: Axis.horizontal,
+ itemCount: widget.itemCount,
+ itemExtent: _itemExtent,
+ findChildIndexCallback: widget.findChildIndexCallback,
+ padding: EdgeInsets.symmetric(horizontal: horizontalPadding),
+ cacheExtent: _itemExtent * _cacheExtentInItems,
+ addAutomaticKeepAlives: false,
+ addSemanticIndexes: false,
+ itemBuilder: (context, index) => _buildItem(context, index),
+ ),
+ ),
+ );
+ },
+ ),
+ ),
+ );
+ }
+
+ Widget _buildItem(BuildContext context, int index) {
+ final isSelected = index == _visualSelectedIndex;
+ final item = GestureDetector(
+ behavior: HitTestBehavior.opaque,
+ onTap: () => _select(index, FileViewerFilmstripSelectionSource.tap),
+ child: SizedBox(
+ width: _itemExtent,
+ height: kFileViewerFilmstripHeight,
+ child: Center(
+ child: AnimatedContainer(
+ duration: _selectionAnimationDuration,
+ curve: Curves.easeOutCubic,
+ width: isSelected ? _selectedThumbnailWidth : _thumbnailWidth,
+ height: isSelected ? _selectedThumbnailHeight : _thumbnailHeight,
+ decoration: BoxDecoration(
+ borderRadius: BorderRadius.circular(2.5),
+ boxShadow: [
+ BoxShadow(
+ color: isSelected
+ ? const Color(0x33000000)
+ : const Color(0x24000000),
+ blurRadius: isSelected ? 3 : 2,
+ offset: const Offset(0, 1),
+ ),
+ ],
+ ),
+ child: ClipRRect(
+ borderRadius: BorderRadius.circular(2.5),
+ child: Stack(
+ fit: StackFit.expand,
+ children: [
+ widget.itemBuilder(context, index),
+ AnimatedContainer(
+ duration: _selectionAnimationDuration,
+ color: isSelected ? Colors.transparent : Colors.black26,
+ ),
+ ],
+ ),
+ ),
+ ),
+ ),
+ ),
+ );
+ final key = widget.itemKeyBuilder?.call(index);
+ return key == null ? item : KeyedSubtree(key: key, child: item);
+ }
+
+ bool _onScrollNotification(ScrollNotification notification) {
+ if (notification is ScrollStartNotification &&
+ notification.dragDetails != null) {
+ _isUserScrollSession = true;
+ _pendingScrubIndex = null;
+ widget.onSelectionChanged(
+ _visualSelectedIndex,
+ FileViewerFilmstripSelectionSource.scrubStart,
+ );
+ }
+
+ if (_isUserScrollSession &&
+ (notification is ScrollUpdateNotification ||
+ notification is OverscrollNotification)) {
+ _queueNearestScrolledItem();
+ }
+
+ if (notification is ScrollEndNotification && _isUserScrollSession) {
+ _scrubThrottleTimer?.cancel();
+ _scrubThrottleTimer = null;
+ _pendingScrubIndex = null;
+ final finalIndex = _nearestScrolledIndex();
+ if (finalIndex != _visualSelectedIndex) {
+ unawaited(HapticFeedback.selectionClick());
+ _select(
+ finalIndex,
+ FileViewerFilmstripSelectionSource.scrubPreview,
+ align: false,
+ notifySelection: false,
+ triggerHaptic: false,
+ );
+ }
+ _isUserScrollSession = false;
+ widget.onSelectionChanged(
+ finalIndex,
+ FileViewerFilmstripSelectionSource.scrubCommit,
+ );
+ _scheduleAlignment(_visualSelectedIndex, animate: true);
+ }
+ return false;
+ }
+
+ void _queueNearestScrolledItem() {
+ final index = _nearestScrolledIndex();
+ if (index == _visualSelectedIndex) {
+ _pendingScrubIndex = null;
+ return;
+ }
+ if (index == _pendingScrubIndex) return;
+ _pendingScrubIndex = index;
+ if (_scrubThrottleTimer != null) return;
+ _flushPendingScrubSelection();
+ _startScrubThrottleWindow();
+ }
+
+ void _startScrubThrottleWindow() {
+ _scrubThrottleTimer = Timer(_scrubThrottleDuration, () {
+ _scrubThrottleTimer = null;
+ if (!mounted || _pendingScrubIndex == null) return;
+ _flushPendingScrubSelection();
+ if (_isUserScrollSession) _startScrubThrottleWindow();
+ });
+ }
+
+ void _flushPendingScrubSelection() {
+ final index = _pendingScrubIndex;
+ _pendingScrubIndex = null;
+ if (index == null) return;
+ _select(
+ index,
+ FileViewerFilmstripSelectionSource.scrubPreview,
+ align: false,
+ );
+ }
+
+ int _nearestScrolledIndex() {
+ if (!_scrollController.hasClients || widget.itemCount == 0) return 0;
+ return _clampIndex((_scrollController.offset / _itemExtent).round());
+ }
+
+ void _select(
+ int index,
+ FileViewerFilmstripSelectionSource source, {
+ bool align = true,
+ bool notifySelection = true,
+ bool triggerHaptic = true,
+ }) {
+ final clampedIndex = _clampIndex(index);
+ if (clampedIndex == _visualSelectedIndex) {
+ if (notifySelection &&
+ clampedIndex != _clampIndex(widget.selectedIndex)) {
+ if (triggerHaptic) unawaited(HapticFeedback.selectionClick());
+ widget.onSelectionChanged(clampedIndex, source);
+ }
+ if (align) _alignToIndex(clampedIndex, animate: true);
+ return;
+ }
+ setState(() => _visualSelectedIndex = clampedIndex);
+ if (notifySelection) {
+ if (triggerHaptic) unawaited(HapticFeedback.selectionClick());
+ widget.onSelectionChanged(clampedIndex, source);
+ }
+ if (align) _alignToIndex(clampedIndex, animate: true);
+ }
+
+ void _scheduleAlignment(int index, {required bool animate}) {
+ if (widget.itemCount == 0 || _alignmentScheduled) return;
+ _alignmentScheduled = true;
+ WidgetsBinding.instance.addPostFrameCallback((_) {
+ _alignmentScheduled = false;
+ if (mounted) _alignToIndex(index, animate: animate);
+ });
+ }
+
+ void _alignToIndex(int index, {required bool animate}) {
+ if (widget.itemCount == 0 || !_scrollController.hasClients) return;
+ final position = _scrollController.position;
+ final target = _offsetForIndex(
+ _clampIndex(index),
+ ).clamp(position.minScrollExtent, position.maxScrollExtent);
+ if ((position.pixels - target).abs() < 0.5) return;
+ if (animate) {
+ unawaited(
+ _scrollController.animateTo(
+ target,
+ duration: _scrollAnimationDuration,
+ curve: Curves.easeOutCubic,
+ ),
+ );
+ } else {
+ _scrollController.jumpTo(target);
+ }
+ }
+
+ int _clampIndex(int index) {
+ if (widget.itemCount == 0) return 0;
+ return index.clamp(0, widget.itemCount - 1);
+ }
+
+ double _offsetForIndex(int index) => index * _itemExtent;
+}
diff --git a/mobile/apps/photos/lib/ui/viewer/file/video_control/gallery_video_controls.dart b/mobile/apps/photos/lib/ui/viewer/file/video_control/gallery_video_controls.dart
index b1d6affdd7..ce5ee856d3 100644
--- a/mobile/apps/photos/lib/ui/viewer/file/video_control/gallery_video_controls.dart
+++ b/mobile/apps/photos/lib/ui/viewer/file/video_control/gallery_video_controls.dart
@@ -1,4 +1,6 @@
+import "package:flutter/foundation.dart";
import "package:flutter/material.dart";
+import "package:photos/states/detail_page_state.dart";
import "package:photos/theme/colors.dart";
import "package:photos/theme/ente_theme.dart";
import "package:photos/ui/viewer/file/video_control/mute_button.dart";
@@ -11,6 +13,15 @@ const kVideoCaptionGap = 6.0;
const kVideoCaptionLineHeight = 16.0;
const kVideoScrimTopPadding = 12.0;
+ValueListenable<double> galleryBottomControlsAdditionalInsetListenable(
+ BuildContext context,
+) {
+ return InheritedDetailPageState.maybeOf(
+ context,
+ )?.bottomControlsAdditionalInsetNotifier ??
+ const AlwaysStoppedAnimation(0);
+}
+
class EqualHeightSliderTrackShape extends RoundedRectSliderTrackShape {
const EqualHeightSliderTrackShape();
@@ -51,28 +62,32 @@ class VideoBottomScrim extends StatelessWidget {
@override
Widget build(BuildContext context) {
- return IgnorePointer(
- child: Align(
- alignment: Alignment.bottomCenter,
- child: SizedBox(
- width: double.infinity,
- height:
- MediaQuery.paddingOf(context).bottom +
- kVideoProgressBottomInset +
- kVideoProgressHeight +
- (hasCaption ? kVideoCaptionGap + kVideoCaptionLineHeight : 0) +
- kVideoScrimTopPadding,
- child: DecoratedBox(
- decoration: BoxDecoration(
- gradient: LinearGradient(
- begin: Alignment.topCenter,
- end: Alignment.bottomCenter,
- colors: [
- Colors.transparent,
- Colors.black.withValues(alpha: 0.6),
- Colors.black.withValues(alpha: 0.72),
- ],
- stops: const [0, 0.8, 1],
+ return ValueListenableBuilder<double>(
+ valueListenable: galleryBottomControlsAdditionalInsetListenable(context),
+ builder: (context, additionalBottomInset, _) => IgnorePointer(
+ child: Align(
+ alignment: Alignment.bottomCenter,
+ child: SizedBox(
+ width: double.infinity,
+ height:
+ MediaQuery.paddingOf(context).bottom +
+ kVideoProgressBottomInset +
+ kVideoProgressHeight +
+ additionalBottomInset +
+ (hasCaption ? kVideoCaptionGap + kVideoCaptionLineHeight : 0) +
+ kVideoScrimTopPadding,
+ child: DecoratedBox(
+ decoration: BoxDecoration(
+ gradient: LinearGradient(
+ begin: Alignment.topCenter,
+ end: Alignment.bottomCenter,
+ colors: [
+ Colors.transparent,
+ Colors.black.withValues(alpha: 0.6),
+ Colors.black.withValues(alpha: 0.72),
+ ],
+ stops: const [0, 0.8, 1],
+ ),
),
),
),
@@ -122,9 +137,13 @@ class VideoProgressRow extends StatelessWidget {
}
}
-double videoStreamControlBottomInset(bool hasCaption) {
+double videoStreamControlBottomInset(
+ bool hasCaption, {
+ double additionalBottomInset = 0,
+}) {
return kVideoProgressBottomInset +
kVideoProgressHeight +
+ additionalBottomInset +
(hasCaption ? kVideoCaptionGap + kVideoCaptionLineHeight : 0) +
8;
}
diff --git a/mobile/apps/photos/lib/ui/viewer/file/video_widget_media_kit.dart b/mobile/apps/photos/lib/ui/viewer/file/video_widget_media_kit.dart
index d4751cddd4..db25b92548 100644
--- a/mobile/apps/photos/lib/ui/viewer/file/video_widget_media_kit.dart
+++ b/mobile/apps/photos/lib/ui/viewer/file/video_widget_media_kit.dart
@@ -97,6 +97,7 @@ class _VideoWidgetMediaKitState extends State<VideoWidgetMediaKit>
}
pauseVideoSubscription = Bus.instance.on<PauseVideoEvent>().listen((event) {
+ if (event.fileTag != null && event.fileTag != widget.file.tag) return;
player.pause();
});
resumeVideoSubscription = Bus.instance.on<ResumeVideoEvent>().listen((
diff --git a/mobile/apps/photos/lib/ui/viewer/file/video_widget_media_kit_common.dart b/mobile/apps/photos/lib/ui/viewer/file/video_widget_media_kit_common.dart
index d539641696..0f121fc23e 100644
--- a/mobile/apps/photos/lib/ui/viewer/file/video_widget_media_kit_common.dart
+++ b/mobile/apps/photos/lib/ui/viewer/file/video_widget_media_kit_common.dart
@@ -208,10 +208,20 @@ class _VideoWidgetState extends State<VideoWidget> {
),
widget.isFromMemories
? const SizedBox.shrink()
- : Positioned(
- bottom: kVideoProgressRowBottomInset,
- right: 0,
- left: 0,
+ : ValueListenableBuilder<double>(
+ valueListenable:
+ galleryBottomControlsAdditionalInsetListenable(
+ context,
+ ),
+ builder: (context, additionalBottomInset, child) =>
+ Positioned(
+ bottom:
+ kVideoProgressRowBottomInset +
+ additionalBottomInset,
+ right: 0,
+ left: 0,
+ child: child!,
+ ),
child: IgnorePointer(
ignoring: !value,
child: SafeArea(
@@ -227,12 +237,21 @@ class _VideoWidgetState extends State<VideoWidget> {
),
widget.isFromMemories
? const SizedBox.shrink()
- : Positioned(
- bottom: videoStreamControlBottomInset(
- widget.file.caption?.isNotEmpty ?? false,
- ),
- right: 0,
- left: 0,
+ : ValueListenableBuilder<double>(
+ valueListenable:
+ galleryBottomControlsAdditionalInsetListenable(
+ context,
+ ),
+ builder: (context, additionalBottomInset, child) =>
+ Positioned(
+ bottom: videoStreamControlBottomInset(
+ widget.file.caption?.isNotEmpty ?? false,
+ additionalBottomInset: additionalBottomInset,
+ ),
+ right: 0,
+ left: 0,
+ child: child!,
+ ),
child: SafeArea(
top: false,
left: false,
diff --git a/mobile/apps/photos/lib/ui/viewer/file/video_widget_native.dart b/mobile/apps/photos/lib/ui/viewer/file/video_widget_native.dart
index ae683b4418..8e23e79ee3 100644
--- a/mobile/apps/photos/lib/ui/viewer/file/video_widget_native.dart
+++ b/mobile/apps/photos/lib/ui/viewer/file/video_widget_native.dart
@@ -137,6 +137,7 @@ class _VideoWidgetNativeState extends State<VideoWidgetNative>
}
pauseVideoSubscription = Bus.instance.on<PauseVideoEvent>().listen((event) {
+ if (event.fileTag != null && event.fileTag != widget.file.tag) return;
_controller?.pause();
});
resumeVideoSubscription = Bus.instance.on<ResumeVideoEvent>().listen((
@@ -469,10 +470,21 @@ class _VideoWidgetNativeState extends State<VideoWidgetNative>
Positioned.fill(child: _getLoadingWidget()),
widget.isFromMemories
? const SizedBox.shrink()
- : Positioned(
- bottom: kVideoProgressRowBottomInset,
- right: 0,
- left: 0,
+ : ValueListenableBuilder<double>(
+ valueListenable:
+ galleryBottomControlsAdditionalInsetListenable(
+ context,
+ ),
+ builder:
+ (context, additionalBottomInset, child) =>
+ Positioned(
+ bottom:
+ kVideoProgressRowBottomInset +
+ additionalBottomInset,
+ right: 0,
+ left: 0,
+ child: child!,
+ ),
child: SafeArea(
top: false,
left: false,
@@ -489,12 +501,27 @@ class _VideoWidgetNativeState extends State<VideoWidgetNative>
),
widget.isFromMemories
? const SizedBox.shrink()
- : Positioned(
- bottom: videoStreamControlBottomInset(
- widget.file.caption?.isNotEmpty ?? false,
- ),
- right: 0,
- left: 0,
+ : ValueListenableBuilder<double>(
+ valueListenable:
+ galleryBottomControlsAdditionalInsetListenable(
+ context,
+ ),
+ builder:
+ (
+ context,
+ additionalBottomInset,
+ child,
+ ) => Positioned(
+ bottom: videoStreamControlBottomInset(
+ widget.file.caption?.isNotEmpty ??
+ false,
+ additionalBottomInset:
+ additionalBottomInset,
+ ),
+ right: 0,
+ left: 0,
+ child: child!,
+ ),
child: SafeArea(
top: false,
left: false,
diff --git a/mobile/apps/photos/lib/ui/viewer/gallery/component/gallery_file_widget.dart b/mobile/apps/photos/lib/ui/viewer/gallery/component/gallery_file_widget.dart
index 13335ac82d..112ff60581 100644
--- a/mobile/apps/photos/lib/ui/viewer/gallery/component/gallery_file_widget.dart
+++ b/mobile/apps/photos/lib/ui/viewer/gallery/component/gallery_file_widget.dart
@@ -317,6 +317,7 @@ class _GalleryFileWidgetState extends State<GalleryFileWidget> {
selectedIndex,
widget.tag,
isLocalOnlyContext: isLocalOnlyContext,
+ showGalleryFilmstrip: true,
galleryType: galleryType,
),
);
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.dart
new file mode 100644
index 0000000000..213f9def9a
--- /dev/null
+++ b/mobile/apps/photos/test/ui/viewer/file/detail_page_configuration_test.dart
@@ -0,0 +1,21 @@
+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";
+
+void main() {
+ test("gallery filmstrip defaults off and copyWith preserves opt-in", () {
+ final file = EnteFile()..fileType = FileType.image;
+
+ final genericConfig = DetailPageConfiguration([file], 0, "generic");
+ expect(genericConfig.showGalleryFilmstrip, isFalse);
+
+ final galleryConfig = DetailPageConfiguration(
+ [file],
+ 0,
+ "gallery",
+ showGalleryFilmstrip: true,
+ );
+ expect(galleryConfig.copyWith().showGalleryFilmstrip, isTrue);
+ });
+}
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.dart
new file mode 100644
index 0000000000..b7bd961e62
--- /dev/null
+++ b/mobile/apps/photos/test/ui/viewer/file/file_viewer_filmstrip_test.dart
@@ -0,0 +1,362 @@
+import "package:flutter/material.dart";
+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";
+
+void main() {
+ testWidgets("centers the selected item and exposes adjustable semantics", (
+ tester,
+ ) async {
+ final key = GlobalKey<_FilmstripHarnessState>();
+ final semantics = tester.ensureSemantics();
+
+ await tester.pumpWidget(
+ _TestApp(
+ child: _FilmstripHarness(key: key, itemCount: 20, selectedIndex: 7),
+ ),
+ );
+ await tester.pumpAndSettle();
+
+ _expectCentered(tester, 7);
+ expect(tester.getSize(find.byKey(fileViewerFilmstripListKey)).height, 45);
+ expect(
+ tester.getCenter(find.byKey(const ValueKey("filmstrip-test-item-8"))).dx -
+ tester
+ .getCenter(find.byKey(const ValueKey("filmstrip-test-item-7")))
+ .dx,
+ closeTo(35, 0.01),
+ );
+ expect(
+ tester.getSize(
+ find
+ .descendant(
+ of: find.byKey(const ValueKey("filmstrip-test-item-7")),
+ matching: find.byType(AnimatedContainer),
+ )
+ .first,
+ ),
+ const Size(34, 43),
+ );
+ expect(
+ tester.getSize(
+ find
+ .descendant(
+ of: find.byKey(const ValueKey("filmstrip-test-item-8")),
+ matching: find.byType(AnimatedContainer),
+ )
+ .first,
+ ),
+ const Size(29, 35),
+ );
+ final semanticsNode = tester.getSemantics(
+ find.byKey(fileViewerFilmstripKey),
+ );
+ final semanticsData = semanticsNode.getSemanticsData();
+ expect(semanticsData.label, "Photo chooser");
+ expect(semanticsData.value, "Photo 8 of 20");
+ expect(semanticsData.hasAction(SemanticsAction.increase), isTrue);
+ expect(semanticsData.hasAction(SemanticsAction.decrease), isTrue);
+
+ semanticsNode.owner!.performAction(
+ semanticsNode.id,
+ SemanticsAction.increase,
+ );
+ await tester.pumpAndSettle();
+ expect(key.currentState!.selections.last.index, 8);
+ _expectCentered(tester, 8);
+
+ final updatedSemanticsNode = tester.getSemantics(
+ find.byKey(fileViewerFilmstripKey),
+ );
+ updatedSemanticsNode.owner!.performAction(
+ updatedSemanticsNode.id,
+ SemanticsAction.decrease,
+ );
+ await tester.pumpAndSettle();
+ expect(key.currentState!.selections.last.index, 7);
+ _expectCentered(tester, 7);
+ semantics.dispose();
+ });
+
+ testWidgets("tapping a thumbnail selects and centers it", (tester) async {
+ final key = GlobalKey<_FilmstripHarnessState>();
+ var hapticCount = 0;
+ TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
+ .setMockMethodCallHandler(SystemChannels.platform, (call) async {
+ if (call.method == "HapticFeedback.vibrate") hapticCount++;
+ return null;
+ });
+ addTearDown(
+ () => TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
+ .setMockMethodCallHandler(SystemChannels.platform, null),
+ );
+ await tester.pumpWidget(
+ _TestApp(
+ child: _FilmstripHarness(key: key, itemCount: 20, selectedIndex: 7),
+ ),
+ );
+ await tester.pumpAndSettle();
+
+ await tester.tap(find.byKey(const ValueKey("filmstrip-test-item-8")));
+
+ expect(key.currentState!.selections.single, (
+ index: 8,
+ source: FileViewerFilmstripSelectionSource.tap,
+ ));
+ await tester.pumpAndSettle();
+
+ expect(key.currentState!.selections, [
+ (index: 8, source: FileViewerFilmstripSelectionSource.tap),
+ ]);
+ expect(hapticCount, 1);
+ _expectCentered(tester, 8);
+ });
+
+ testWidgets("scrubbing previews and ticks each newly centered thumbnail", (
+ tester,
+ ) async {
+ final key = GlobalKey<_FilmstripHarnessState>();
+ var hapticCount = 0;
+ TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
+ .setMockMethodCallHandler(SystemChannels.platform, (call) async {
+ if (call.method == "HapticFeedback.vibrate") hapticCount++;
+ return null;
+ });
+ addTearDown(
+ () => TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
+ .setMockMethodCallHandler(SystemChannels.platform, null),
+ );
+ await tester.pumpWidget(
+ _TestApp(
+ child: _FilmstripHarness(key: key, itemCount: 20, selectedIndex: 7),
+ ),
+ );
+ await tester.pumpAndSettle();
+
+ final gesture = await tester.startGesture(
+ tester.getCenter(find.byKey(fileViewerFilmstripListKey)),
+ );
+ await tester.pump(const Duration(milliseconds: 200));
+ // The first move starts Flutter's drag recognizer; the second one scrolls.
+ await gesture.moveBy(const Offset(-20, 0));
+ await tester.pump();
+ await gesture.moveBy(const Offset(-72, 0));
+ await tester.pump(const Duration(milliseconds: 100));
+
+ expect(
+ key.currentState!.selections
+ .where(
+ (event) =>
+ event.source == FileViewerFilmstripSelectionSource.scrubStart,
+ )
+ .length,
+ 1,
+ );
+ final previewsBeforeUp = key.currentState!.selections
+ .where(
+ (event) =>
+ event.source == FileViewerFilmstripSelectionSource.scrubPreview,
+ )
+ .toList();
+ expect(previewsBeforeUp, isNotEmpty);
+ expect(hapticCount, previewsBeforeUp.length);
+ final previewIndex = previewsBeforeUp.last.index;
+ _expectNearestToStripCenter(tester, previewIndex);
+
+ await tester.pump(const Duration(milliseconds: 200));
+ await gesture.up();
+ await tester.pumpAndSettle();
+
+ expect(hapticCount, previewsBeforeUp.length);
+ expect(key.currentState!.selections.last, (
+ index: previewIndex,
+ source: FileViewerFilmstripSelectionSource.scrubCommit,
+ ));
+ expect(
+ key.currentState!.selections
+ .where(
+ (event) =>
+ event.source == FileViewerFilmstripSelectionSource.scrubCommit,
+ )
+ .length,
+ 1,
+ );
+ _expectCentered(tester, previewIndex);
+ });
+
+ testWidgets("a drag that stays centered still ends its scrub session", (
+ tester,
+ ) async {
+ final key = GlobalKey<_FilmstripHarnessState>();
+ var hapticCount = 0;
+ TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
+ .setMockMethodCallHandler(SystemChannels.platform, (call) async {
+ if (call.method == "HapticFeedback.vibrate") hapticCount++;
+ return null;
+ });
+ addTearDown(
+ () => TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
+ .setMockMethodCallHandler(SystemChannels.platform, null),
+ );
+ await tester.pumpWidget(
+ _TestApp(
+ child: _FilmstripHarness(key: key, itemCount: 20, selectedIndex: 7),
+ ),
+ );
+ await tester.pumpAndSettle();
+
+ final gesture = await tester.startGesture(
+ tester.getCenter(find.byKey(fileViewerFilmstripListKey)),
+ );
+ await gesture.moveBy(const Offset(-20, 0));
+ await tester.pump(const Duration(milliseconds: 200));
+ await gesture.up();
+ await tester.pumpAndSettle();
+
+ expect(key.currentState!.selections, [
+ (index: 7, source: FileViewerFilmstripSelectionSource.scrubStart),
+ (index: 7, source: FileViewerFilmstripSelectionSource.scrubCommit),
+ ]);
+ expect(hapticCount, 0);
+ _expectCentered(tester, 7);
+ });
+
+ testWidgets("realigns safely when the selection or item count changes", (
+ tester,
+ ) async {
+ final key = GlobalKey<_FilmstripHarnessState>();
+ var hapticCount = 0;
+ TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
+ .setMockMethodCallHandler(SystemChannels.platform, (call) async {
+ if (call.method == "HapticFeedback.vibrate") hapticCount++;
+ return null;
+ });
+ addTearDown(
+ () => TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
+ .setMockMethodCallHandler(SystemChannels.platform, null),
+ );
+ await tester.pumpWidget(
+ _TestApp(
+ child: _FilmstripHarness(key: key, itemCount: 20, selectedIndex: 7),
+ ),
+ );
+ await tester.pumpAndSettle();
+
+ key.currentState!.update(selectedIndex: 19);
+ await tester.pumpAndSettle();
+ _expectCentered(tester, 19);
+ expect(key.currentState!.selections, isEmpty);
+
+ key.currentState!.update(itemCount: 4, selectedIndex: 3);
+ await tester.pumpAndSettle();
+ _expectCentered(tester, 3);
+ expect(key.currentState!.selections, isEmpty);
+
+ key.currentState!.update(itemCount: 0, selectedIndex: 0);
+ await tester.pumpAndSettle();
+ expect(find.byKey(fileViewerFilmstripListKey), findsNothing);
+
+ key.currentState!.update(itemCount: 5, selectedIndex: 2);
+ await tester.pumpAndSettle();
+ _expectCentered(tester, 2);
+ expect(tester.takeException(), isNull);
+ expect(hapticCount, 0);
+ });
+}
+
+void _expectCentered(WidgetTester tester, int index) {
+ final itemCenter = tester.getCenter(
+ find.byKey(ValueKey("filmstrip-test-item-$index")),
+ );
+ final stripCenter = tester.getCenter(find.byKey(fileViewerFilmstripListKey));
+ expect(itemCenter.dx, closeTo(stripCenter.dx, 0.5));
+}
+
+void _expectNearestToStripCenter(WidgetTester tester, int index) {
+ final stripCenter = tester.getCenter(find.byKey(fileViewerFilmstripListKey));
+ final builtItems = find.byWidgetPredicate(
+ (widget) =>
+ widget.key is ValueKey<String> &&
+ (widget.key! as ValueKey<String>).value.startsWith(
+ "filmstrip-test-item-",
+ ),
+ );
+ var nearestIndex = -1;
+ var nearestDistance = double.infinity;
+ for (final element in builtItems.evaluate()) {
+ final key = element.widget.key! as ValueKey<String>;
+ final itemIndex = int.parse(key.value.split("-").last);
+ final distance = (tester.getCenter(find.byKey(key)).dx - stripCenter.dx)
+ .abs();
+ if (distance < nearestDistance) {
+ nearestDistance = distance;
+ nearestIndex = itemIndex;
+ }
+ }
+ expect(index, nearestIndex);
+}
+
+class _TestApp extends StatelessWidget {
+ final Widget child;
+
+ const _TestApp({required this.child});
+
+ @override
+ Widget build(BuildContext context) {
+ return MaterialApp(
+ home: Scaffold(
+ backgroundColor: Colors.black,
+ body: Center(child: SizedBox(width: 380, child: child)),
+ ),
+ );
+ }
+}
+
+class _FilmstripHarness extends StatefulWidget {
+ final int itemCount;
+ final int selectedIndex;
+
+ const _FilmstripHarness({
+ required this.itemCount,
+ required this.selectedIndex,
+ super.key,
+ });
+
+ @override
+ State<_FilmstripHarness> createState() => _FilmstripHarnessState();
+}
+
+class _FilmstripHarnessState extends State<_FilmstripHarness> {
+ late int itemCount = widget.itemCount;
+ late int selectedIndex = widget.selectedIndex;
+ final selections =
+ <({int index, FileViewerFilmstripSelectionSource source})>[];
+
+ void update({int? itemCount, int? selectedIndex}) {
+ setState(() {
+ this.itemCount = itemCount ?? this.itemCount;
+ this.selectedIndex = selectedIndex ?? this.selectedIndex;
+ });
+ }
+
+ @override
+ Widget build(BuildContext context) {
+ return FileViewerFilmstrip(
+ itemCount: itemCount,
+ selectedIndex: selectedIndex,
+ semanticLabel: "Photo chooser",
+ semanticValueBuilder: (current, total) => "Photo $current of $total",
+ itemKeyBuilder: (index) => ValueKey("filmstrip-test-item-$index"),
+ itemBuilder: (context, index) =>
+ ColoredBox(color: Color(0xFF000000 + index)),
+ onSelectionChanged: (index, source) {
+ selections.add((index: index, source: source));
+ if (source == FileViewerFilmstripSelectionSource.tap ||
+ source == FileViewerFilmstripSelectionSource.scrubCommit) {
+ setState(() => selectedIndex = index);
+ }
+ },
+ );
+ }
+}
diff --git a/mobile/packages/strings/lib/l10n/arb/strings_en.arb b/mobile/packages/strings/lib/l10n/arb/strings_en.arb
index 5ad6aa7209..71d6a4c786 100644
--- a/mobile/packages/strings/lib/l10n/arb/strings_en.arb
+++ b/mobile/packages/strings/lib/l10n/arb/strings_en.arb
@@ -2980,6 +2980,22 @@
"photoLibraryAddPermissionRequired": "Ente needs permission to save photos and videos to Apple Photos. You can allow access in Settings.",
"photoLibraryAddPermissionRestricted": "Photo Library access is restricted on this device.",
"photoOrder": "Photo order",
+ "photoViewerFilmstripLabel": "Photo chooser",
+ "@photoViewerFilmstripLabel": {
+ "description": "Accessibility label for the thumbnail filmstrip in the photo viewer"
+ },
+ "photoViewerFilmstripPosition": "Photo {current} of {total}",
+ "@photoViewerFilmstripPosition": {
+ "description": "Accessibility position within the thumbnail filmstrip in the photo viewer",
+ "placeholders": {
+ "current": {
+ "type": "int"
+ },
+ "total": {
+ "type": "int"
+ }
+ }
+ },
"photos": "Photos",
"photosAddedByYouWillBeRemovedFromTheAlbum": "Photos added by you will be removed from the album",
"photosAndVideosCount": "{count, plural, one{{formattedCount} photo & video} other{{formattedCount} photos & videos}}",