Skip to content

armgit / ente

Public Imported from GitHub
0

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

Fix video pinch lock and detail-sheet gesture race

ashilknada499127e18
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 892f49cc58..facca5ba62 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
@@ -27,7 +27,6 @@ import "package:photos/ui/common/loading_widget.dart";
import "package:photos/ui/notification/toast.dart";
import "package:photos/ui/viewer/file/video_widget_media_kit_common.dart"
as common;
-import "package:photos/ui/viewer/file/zoomable_video_viewer.dart";
import "package:photos/utils/dialog_util.dart";
import "package:photos/utils/file_util.dart";
@@ -85,7 +84,6 @@ class _VideoWidgetMediaKitState extends State<VideoWidgetMediaKit>
);
super.initState();
WidgetsBinding.instance.addObserver(this);
- _transformationController.addListener(_onZoomChanged);
if (widget.selectedPreview) {
loadPreview();
@@ -198,7 +196,6 @@ class _VideoWidgetMediaKitState extends State<VideoWidgetMediaKit>
}
player.dispose();
_captionUpdatedSubscription.cancel();
- _transformationController.removeListener(_onZoomChanged);
_transformationController.dispose();
if (EnteWakeLockService.instance.shouldKeepAppAwakeAcrossSessions) {
EnteWakeLockService.instance.updateWakeLock(
@@ -214,32 +211,29 @@ class _VideoWidgetMediaKitState extends State<VideoWidgetMediaKit>
super.dispose();
}
- void _onZoomChanged() {
- final scale = _transformationController.value.getMaxScaleOnAxis();
- final isZoomed = scale > kZoomThreshold;
- if (_isZooming != isZoomed) {
+ void _onInteractionLockChanged(bool shouldLock) {
+ if (_isZooming != shouldLock) {
setState(() {
- _isZooming = isZoomed;
+ _isZooming = shouldLock;
});
- widget.shouldDisableScroll?.call(isZoomed);
}
+ widget.shouldDisableScroll?.call(shouldLock);
}
@override
Widget build(BuildContext context) {
return GestureDetector(
+ // Keep recognizer out of the arena during multi-touch/zoom to avoid
+ // it stealing pinch gestures with predominantly vertical movement.
onVerticalDragUpdate: _isGuestView || _isZooming
? null
- : (d) => {
- if (d.delta.dy > dragSensitivity)
- {
- Navigator.of(context).pop(),
- }
- else if (d.delta.dy < (dragSensitivity * -1))
- {
- showDetailsSheet(context, widget.file),
- },
- },
+ : (d) {
+ if (d.delta.dy > dragSensitivity) {
+ Navigator.of(context).pop();
+ } else if (d.delta.dy < (dragSensitivity * -1)) {
+ showDetailsSheet(context, widget.file);
+ }
+ },
child: Center(
child: controller != null
? common.VideoWidget(
@@ -247,7 +241,7 @@ class _VideoWidgetMediaKitState extends State<VideoWidgetMediaKit>
controller!,
widget.playbackCallback,
transformationController: _transformationController,
- shouldDisableScroll: widget.shouldDisableScroll,
+ onInteractionLockChanged: _onInteractionLockChanged,
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 5aa6fcce94..3d1b3e20a7 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
@@ -17,7 +17,7 @@ class VideoWidget extends StatefulWidget {
final VideoController controller;
final FullScreenRequestCallback? playbackCallback;
final TransformationController? transformationController;
- final Function(bool)? shouldDisableScroll;
+ final ValueChanged<bool>? onInteractionLockChanged;
final bool isFromMemories;
final void Function() onStreamChange;
final bool isPreviewPlayer;
@@ -28,7 +28,7 @@ class VideoWidget extends StatefulWidget {
this.playbackCallback, {
super.key,
this.transformationController,
- this.shouldDisableScroll,
+ this.onInteractionLockChanged,
required this.isFromMemories,
// ignore: unused_element
required this.onStreamChange,
@@ -107,7 +107,7 @@ class _VideoWidgetState extends State<VideoWidget> {
widget.transformationController != null
? ZoomableVideoViewer(
transformationController: widget.transformationController!,
- shouldDisableScroll: widget.shouldDisableScroll,
+ onInteractionLockChanged: widget.onInteractionLockChanged,
child: videoWidget,
)
: 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 1c195b15f8..f9cd0f8e67 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
@@ -103,7 +103,6 @@ class _VideoWidgetNativeState extends State<VideoWidgetNative>
);
super.initState();
WidgetsBinding.instance.addObserver(this);
- _transformationController.addListener(_onZoomChanged);
if (widget.selectedPreview) {
loadPreview();
@@ -258,22 +257,19 @@ 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 > kZoomThreshold;
- if (_isZooming != isZoomed) {
+ void _onInteractionLockChanged(bool shouldLock) {
+ if (_isZooming != shouldLock) {
setState(() {
- _isZooming = isZoomed;
+ _isZooming = shouldLock;
});
- widget.shouldDisableScroll?.call(isZoomed);
}
+ widget.shouldDisableScroll?.call(shouldLock);
}
@override
@@ -290,18 +286,17 @@ class _VideoWidgetNativeState extends State<VideoWidgetNative>
}
},
child: GestureDetector(
+ // Keep recognizer out of the arena during multi-touch/zoom to avoid
+ // it stealing pinch gestures with predominantly vertical movement.
onVerticalDragUpdate: _isGuestView || _isZooming
? null
- : (d) => {
- if (d.delta.dy > dragSensitivity)
- {
- Navigator.of(context).pop(),
- }
- else if (d.delta.dy < (dragSensitivity * -1))
- {
- showDetailsSheet(context, widget.file),
- },
- },
+ : (d) {
+ if (d.delta.dy > dragSensitivity) {
+ Navigator.of(context).pop();
+ } else if (d.delta.dy < (dragSensitivity * -1)) {
+ showDetailsSheet(context, widget.file);
+ }
+ },
child: AnimatedSwitcher(
duration: const Duration(milliseconds: 750),
switchOutCurve: Curves.easeOutExpo,
@@ -315,7 +310,7 @@ class _VideoWidgetNativeState extends State<VideoWidgetNative>
children: [
ZoomableVideoViewer(
transformationController: _transformationController,
- shouldDisableScroll: widget.shouldDisableScroll,
+ onInteractionLockChanged: _onInteractionLockChanged,
child: Center(
child: AspectRatio(
aspectRatio: aspectRatio ?? 1,
diff --git a/mobile/apps/photos/lib/ui/viewer/file/zoomable_video_viewer.dart b/mobile/apps/photos/lib/ui/viewer/file/zoomable_video_viewer.dart
index 7b62f786cc..5c85e78380 100644
--- a/mobile/apps/photos/lib/ui/viewer/file/zoomable_video_viewer.dart
+++ b/mobile/apps/photos/lib/ui/viewer/file/zoomable_video_viewer.dart
@@ -16,13 +16,13 @@ const double kZoomThreshold = 1.01;
/// parent PageView's scrolling.
class ZoomableVideoViewer extends StatefulWidget {
final TransformationController transformationController;
- final Function(bool)? shouldDisableScroll;
+ final ValueChanged<bool>? onInteractionLockChanged;
final Widget child;
const ZoomableVideoViewer({
super.key,
required this.transformationController,
- this.shouldDisableScroll,
+ this.onInteractionLockChanged,
required this.child,
});
@@ -32,31 +32,59 @@ class ZoomableVideoViewer extends StatefulWidget {
class _ZoomableVideoViewerState extends State<ZoomableVideoViewer> {
int _activePointers = 0;
+ bool _isInteractionLocked = false;
+
+ @override
+ void initState() {
+ super.initState();
+ widget.transformationController.addListener(_onTransformationChanged);
+ _updateInteractionLockState();
+ }
+
+ @override
+ void didUpdateWidget(covariant ZoomableVideoViewer oldWidget) {
+ super.didUpdateWidget(oldWidget);
+ if (oldWidget.transformationController != widget.transformationController) {
+ oldWidget.transformationController
+ .removeListener(_onTransformationChanged);
+ widget.transformationController.addListener(_onTransformationChanged);
+ _updateInteractionLockState();
+ }
+ }
+
+ @override
+ void dispose() {
+ widget.transformationController.removeListener(_onTransformationChanged);
+ super.dispose();
+ }
+
+ void _onTransformationChanged() {
+ _updateInteractionLockState();
+ }
void _onPointerDown(PointerDownEvent _) {
_activePointers++;
- if (_activePointers >= 2) {
- widget.shouldDisableScroll?.call(true);
- }
+ _updateInteractionLockState();
}
void _onPointerUp(PointerUpEvent _) {
_activePointers = (_activePointers - 1).clamp(0, 99);
- _maybeReenableScroll();
+ _updateInteractionLockState();
}
void _onPointerCancel(PointerCancelEvent _) {
_activePointers = (_activePointers - 1).clamp(0, 99);
- _maybeReenableScroll();
+ _updateInteractionLockState();
}
- void _maybeReenableScroll() {
- if (_activePointers < 2) {
- final scale = widget.transformationController.value.getMaxScaleOnAxis();
- if (scale <= kZoomThreshold) {
- widget.shouldDisableScroll?.call(false);
- }
+ void _updateInteractionLockState() {
+ final scale = widget.transformationController.value.getMaxScaleOnAxis();
+ final shouldLock = _activePointers >= 2 || scale > kZoomThreshold;
+ if (_isInteractionLocked == shouldLock) {
+ return;
}
+ _isInteractionLocked = shouldLock;
+ widget.onInteractionLockChanged?.call(shouldLock);
}
@override