Skip to content

armgit / ente

Public Imported from GitHub
0

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

Add pinch-to-zoom for videos using InteractiveViewer

ashilkn6f34b169a241
diff --git a/mobile/apps/photos/lib/ui/viewer/file/file_widget.dart b/mobile/apps/photos/lib/ui/viewer/file/file_widget.dart
index 9a1d2dfaa7..9c311fd4f5 100644
--- a/mobile/apps/photos/lib/ui/viewer/file/file_widget.dart
+++ b/mobile/apps/photos/lib/ui/viewer/file/file_widget.dart
@@ -61,6 +61,7 @@ class FileWidget extends StatelessWidget {
file,
tagPrefix: tagPrefix,
playbackCallback: playbackCallback,
+ shouldDisableScroll: shouldDisableScroll,
onFinalFileLoad: onFinalFileLoad,
isFromMemories: isFromMemories ?? false,
key: key ?? ValueKey(fileKey),
diff --git a/mobile/apps/photos/lib/ui/viewer/file/video_widget.dart b/mobile/apps/photos/lib/ui/viewer/file/video_widget.dart
index 7f1c530f48..1cbef49c91 100644
--- a/mobile/apps/photos/lib/ui/viewer/file/video_widget.dart
+++ b/mobile/apps/photos/lib/ui/viewer/file/video_widget.dart
@@ -25,6 +25,7 @@ class VideoWidget extends StatefulWidget {
final EnteFile file;
final String? tagPrefix;
final FullScreenRequestCallback? playbackCallback;
+ final Function(bool)? shouldDisableScroll;
final Function({required int memoryDuration})? onFinalFileLoad;
final bool isFromMemories;
@@ -32,6 +33,7 @@ class VideoWidget extends StatefulWidget {
this.file, {
this.tagPrefix,
this.playbackCallback,
+ this.shouldDisableScroll,
this.onFinalFileLoad,
this.isFromMemories = false,
super.key,
@@ -164,6 +166,7 @@ class _VideoWidgetState extends State<VideoWidget> {
key: nativePlayerKey,
tagPrefix: widget.tagPrefix,
playbackCallback: widget.playbackCallback,
+ shouldDisableScroll: widget.shouldDisableScroll,
playlistData: playlistData,
selectedPreview: playPreview,
isFromMemories: widget.isFromMemories,
@@ -188,6 +191,7 @@ class _VideoWidgetState extends State<VideoWidget> {
key: mediaKitKey,
tagPrefix: widget.tagPrefix,
playbackCallback: widget.playbackCallback,
+ shouldDisableScroll: widget.shouldDisableScroll,
preview: playlistData?.preview,
selectedPreview: playPreview,
isFromMemories: widget.isFromMemories,
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 bef4f39654..a8b731b5ed 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
@@ -33,6 +33,7 @@ class VideoWidgetMediaKit extends StatefulWidget {
final EnteFile file;
final String? tagPrefix;
final FullScreenRequestCallback? playbackCallback;
+ final Function(bool)? shouldDisableScroll;
final bool isFromMemories;
final void Function() onStreamChange;
final File? preview;
@@ -43,6 +44,7 @@ class VideoWidgetMediaKit extends StatefulWidget {
this.file, {
this.tagPrefix,
this.playbackCallback,
+ this.shouldDisableScroll,
this.isFromMemories = false,
required this.onStreamChange,
this.preview,
@@ -70,6 +72,8 @@ class _VideoWidgetMediaKitState extends State<VideoWidgetMediaKit>
StreamSubscription<DownloadTask>? _downloadTaskSubscription;
late final StreamSubscription<FileCaptionUpdatedEvent>
_captionUpdatedSubscription;
+ final _transformationController = TransformationController();
+ bool _isZooming = false;
@override
void initState() {
@@ -78,6 +82,7 @@ class _VideoWidgetMediaKitState extends State<VideoWidgetMediaKit>
);
super.initState();
WidgetsBinding.instance.addObserver(this);
+ _transformationController.addListener(_onZoomChanged);
if (widget.selectedPreview) {
loadPreview();
@@ -185,6 +190,8 @@ class _VideoWidgetMediaKitState extends State<VideoWidgetMediaKit>
}
player.dispose();
_captionUpdatedSubscription.cancel();
+ _transformationController.removeListener(_onZoomChanged);
+ _transformationController.dispose();
if (EnteWakeLockService.instance.shouldKeepAppAwakeAcrossSessions) {
EnteWakeLockService.instance.updateWakeLock(
enable: true,
@@ -199,10 +206,19 @@ class _VideoWidgetMediaKitState extends State<VideoWidgetMediaKit>
super.dispose();
}
+ void _onZoomChanged() {
+ final scale = _transformationController.value.getMaxScaleOnAxis();
+ final isZoomed = scale > 1.01;
+ if (_isZooming != isZoomed) {
+ _isZooming = isZoomed;
+ widget.shouldDisableScroll?.call(isZoomed);
+ }
+ }
+
@override
Widget build(BuildContext context) {
return GestureDetector(
- onVerticalDragUpdate: _isGuestView
+ onVerticalDragUpdate: _isGuestView || _isZooming
? null
: (d) => {
if (d.delta.dy > dragSensitivity)
@@ -220,6 +236,7 @@ class _VideoWidgetMediaKitState extends State<VideoWidgetMediaKit>
widget.file,
controller!,
widget.playbackCallback,
+ transformationController: _transformationController,
isFromMemories: widget.isFromMemories,
onStreamChange: widget.onStreamChange,
isPreviewPlayer: widget.selectedPreview,
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 d6de7f8ba7..b6a90bf72b 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
@@ -16,6 +16,7 @@ class VideoWidget extends StatefulWidget {
final EnteFile file;
final VideoController controller;
final FullScreenRequestCallback? playbackCallback;
+ final TransformationController? transformationController;
final bool isFromMemories;
final void Function() onStreamChange;
final bool isPreviewPlayer;
@@ -25,6 +26,7 @@ class VideoWidget extends StatefulWidget {
this.controller,
this.playbackCallback, {
super.key,
+ this.transformationController,
required this.isFromMemories,
// ignore: unused_element
required this.onStreamChange,
@@ -91,10 +93,25 @@ class _VideoWidgetState extends State<VideoWidget> {
@override
Widget build(BuildContext context) {
- return Video(
+ final videoWidget = Video(
controller: widget.controller,
- controls: (state) {
- return ValueListenableBuilder(
+ controls: NoVideoControls,
+ );
+
+ return Stack(
+ alignment: Alignment.center,
+ children: [
+ // Video layer with zoom support
+ widget.transformationController != null
+ ? InteractiveViewer(
+ transformationController: widget.transformationController!,
+ maxScale: 4.0,
+ minScale: 1.0,
+ child: videoWidget,
+ )
+ : videoWidget,
+ // Controls overlay (fixed position, not affected by zoom)
+ ValueListenableBuilder(
valueListenable: showControlsNotifier,
builder: (context, value, _) {
return AnimatedOpacity(
@@ -105,7 +122,7 @@ class _VideoWidgetState extends State<VideoWidget> {
alignment: Alignment.center,
children: [
GestureDetector(
- behavior: HitTestBehavior.opaque,
+ behavior: HitTestBehavior.translucent,
onTap: widget.isFromMemories
? null
: () {
@@ -190,8 +207,8 @@ class _VideoWidgetState extends State<VideoWidget> {
),
);
},
- );
- },
+ ),
+ ],
);
}
}
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 ce7ed371c3..b51148cdc6 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
@@ -41,6 +41,7 @@ class VideoWidgetNative extends StatefulWidget {
final EnteFile file;
final String? tagPrefix;
final FullScreenRequestCallback? playbackCallback;
+ final Function(bool)? shouldDisableScroll;
final bool isFromMemories;
final void Function()? onStreamChange;
final PlaylistData? playlistData;
@@ -51,6 +52,7 @@ class VideoWidgetNative extends StatefulWidget {
this.file, {
this.tagPrefix,
this.playbackCallback,
+ this.shouldDisableScroll,
this.isFromMemories = false,
required this.onStreamChange,
super.key,
@@ -89,6 +91,8 @@ class _VideoWidgetNativeState extends State<VideoWidgetNative>
late final StreamSubscription<FileCaptionUpdatedEvent>
_captionUpdatedSubscription;
int position = 0;
+ final _transformationController = TransformationController();
+ bool _isZooming = false;
@override
void initState() {
@@ -97,6 +101,7 @@ class _VideoWidgetNativeState extends State<VideoWidgetNative>
);
super.initState();
WidgetsBinding.instance.addObserver(this);
+ _transformationController.addListener(_onZoomChanged);
if (widget.selectedPreview) {
loadPreview();
@@ -246,11 +251,22 @@ class _VideoWidgetNativeState extends State<VideoWidgetNative>
_isSeeking.dispose();
_debouncer.cancelDebounceTimer();
_captionUpdatedSubscription.cancel();
+ _transformationController.removeListener(_onZoomChanged);
+ _transformationController.dispose();
EnteWakeLockService.instance
.updateWakeLock(enable: false, wakeLockFor: WakeLockFor.videoPlayback);
super.dispose();
}
+ void _onZoomChanged() {
+ final scale = _transformationController.value.getMaxScaleOnAxis();
+ final isZoomed = scale > 1.01;
+ if (_isZooming != isZoomed) {
+ _isZooming = isZoomed;
+ widget.shouldDisableScroll?.call(isZoomed);
+ }
+ }
+
@override
Widget build(BuildContext context) {
return Hero(
@@ -265,7 +281,7 @@ class _VideoWidgetNativeState extends State<VideoWidgetNative>
}
},
child: GestureDetector(
- onVerticalDragUpdate: _isGuestView
+ onVerticalDragUpdate: _isGuestView || _isZooming
? null
: (d) => {
if (d.delta.dy > dragSensitivity)
@@ -288,16 +304,21 @@ class _VideoWidgetNativeState extends State<VideoWidgetNative>
: Stack(
key: const ValueKey("video_ready"),
children: [
- Center(
- child: AspectRatio(
- aspectRatio: aspectRatio ?? 1,
- child: NativeVideoPlayerView(
- onViewReady: _initializeController,
+ InteractiveViewer(
+ transformationController: _transformationController,
+ maxScale: 4.0,
+ minScale: 1.0,
+ child: Center(
+ child: AspectRatio(
+ aspectRatio: aspectRatio ?? 1,
+ child: NativeVideoPlayerView(
+ onViewReady: _initializeController,
+ ),
),
),
),
GestureDetector(
- behavior: HitTestBehavior.opaque,
+ behavior: HitTestBehavior.translucent,
onTap: widget.isFromMemories
? null
: () {