Skip to content

armgit / ente

Public Imported from GitHub
0

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

refactor(photos): tighten image zoom viewer

ashil-pilot5bffeeb06ea6
diff --git a/mobile/apps/photos/lib/ui/viewer/actions/file_viewer.dart b/mobile/apps/photos/lib/ui/viewer/actions/file_viewer.dart
index d6fefe9fce..7998c77567 100644
--- a/mobile/apps/photos/lib/ui/viewer/actions/file_viewer.dart
+++ b/mobile/apps/photos/lib/ui/viewer/actions/file_viewer.dart
@@ -54,7 +54,6 @@ class FileViewerState extends State<FileViewer> {
Widget _boundedImageViewer(ImageProvider imageProvider) {
return ImageZoomViewer(
imageProvider: imageProvider,
- filterQuality: FilterQuality.high,
maxScaleOverCover: 3.0,
);
}
diff --git a/mobile/apps/photos/lib/ui/viewer/file/image_zoom_viewer.dart b/mobile/apps/photos/lib/ui/viewer/file/image_zoom_viewer.dart
index eaabc8b156..d94c91f09f 100644
--- a/mobile/apps/photos/lib/ui/viewer/file/image_zoom_viewer.dart
+++ b/mobile/apps/photos/lib/ui/viewer/file/image_zoom_viewer.dart
@@ -303,16 +303,8 @@ class _ImageZoomViewerState extends State<ImageZoomViewer>
});
}
- Size? _validSize(Size? size) {
- if (size == null ||
- !size.width.isFinite ||
- !size.height.isFinite ||
- size.width <= 0 ||
- size.height <= 0) {
- return null;
- }
- return size;
- }
+ Size? _validSize(Size? size) =>
+ size != null && size.isFinite && !size.isEmpty ? size : null;
void _updateGeometry(Size viewportSize, Size imageSize) {
final nextGeometry = ImageZoomGeometry.calculate(
@@ -632,7 +624,6 @@ class _ImageZoomViewerState extends State<ImageZoomViewer>
_publishTransform();
_animationCompleter?.complete();
_animationCompleter = null;
- _updateInteractionLock();
}
void _stopProgrammaticAnimation() {
@@ -697,24 +688,13 @@ class _ImageZoomViewerState extends State<ImageZoomViewer>
image = Hero(tag: widget.heroTag!, child: image);
}
- final transformedChild = SizedBox.expand(
- child: Center(
- child: SizedBox(
- width: fittedSize.width,
- height: fittedSize.height,
- child: image,
- ),
- ),
- );
+ final transformedChild = SizedBox.expand(child: Center(child: image));
final interactiveViewer = InteractiveViewer(
key: ValueKey(_interactiveViewerGeneration),
transformationController: _transformationController,
alignment: null,
minScale: geometry.initialScale,
maxScale: geometry.maxScale,
- panEnabled: true,
- scaleEnabled: true,
- clipBehavior: Clip.hardEdge,
onInteractionStart: _onInteractionStart,
onInteractionUpdate: _onInteractionUpdate,
onInteractionEnd: _onInteractionEnd,
diff --git a/mobile/apps/photos/lib/ui/viewer/file/zoomable_image.dart b/mobile/apps/photos/lib/ui/viewer/file/zoomable_image.dart
index d7d1ad1bbf..a5221d758c 100644
--- a/mobile/apps/photos/lib/ui/viewer/file/zoomable_image.dart
+++ b/mobile/apps/photos/lib/ui/viewer/file/zoomable_image.dart
@@ -76,7 +76,6 @@ class _ZoomableImageState extends State<ZoomableImage> {
// Start the memory slideshow timer when any image is ready, without waiting
// for the original.
bool _firedOnReady = false;
- bool _isZooming = false;
bool _interactionLocked = false;
final _imageZoomController = ImageZoomController();
late final StreamSubscription<ResetZoomOfPhotoView> _resetZoomSubscription;
@@ -141,10 +140,10 @@ class _ZoomableImageState extends State<ZoomableImage> {
void _onZoomChanged() {
if (!mounted) return;
final transform = _imageZoomController.transform;
- _isZooming = _imageZoomController.isZoomed;
+ final isZooming = _imageZoomController.isZoomed;
final state = InheritedDetailPageState.maybeOf(context);
- state?.isZoomedNotifier.value = _isZooming;
- state?.zoomTransformNotifier.value = _isZooming
+ state?.isZoomedNotifier.value = isZooming;
+ state?.zoomTransformNotifier.value = isZooming
? ZoomTransform(scale: transform.scale, offset: transform.offset)
: ZoomTransform.identity;
}
@@ -155,6 +154,15 @@ class _ZoomableImageState extends State<ZoomableImage> {
setState(() => _interactionLocked = isLocked);
}
+ void _onVerticalDragUpdate(DragUpdateDetails details) {
+ if (_imageZoomController.isZoomed) return;
+ if (details.delta.dy > dragSensitivity) {
+ unawaited(Navigator.maybePop(context));
+ } else if (details.delta.dy < -dragSensitivity) {
+ showDetailsSheet(context, widget.photo);
+ }
+ }
+
@override
void dispose() {
_imageZoomController
@@ -186,36 +194,23 @@ class _ZoomableImageState extends State<ZoomableImage> {
initialFit: widget.shouldCover ? BoxFit.cover : BoxFit.contain,
// Collage already owns its transform with an outer InteractiveViewer.
gesturesEnabled: !widget.shouldCover,
- filterQuality: FilterQuality.high,
- gaplessPlayback: true,
onInteractionLockChanged: _onInteractionLockChanged,
loadingBuilder: (context, event) {
// Match the loading state to the image's on-screen size during the
// hero animation.
- final screenDimensions = MediaQuery.sizeOf(context);
- late final double screenRelativeImageWidth;
- late final double screenRelativeImageHeight;
- final screenWidth = screenDimensions.width;
- final screenHeight = screenDimensions.height;
-
- final aspectRatioOfScreen = screenWidth / screenHeight;
- final aspectRatioOfImage = _photo.width / _photo.height;
-
- if (aspectRatioOfImage > aspectRatioOfScreen) {
- screenRelativeImageWidth = screenWidth;
- screenRelativeImageHeight = screenWidth / aspectRatioOfImage;
- } else if (aspectRatioOfImage < aspectRatioOfScreen) {
- screenRelativeImageHeight = screenHeight;
- screenRelativeImageWidth = screenHeight * aspectRatioOfImage;
- } else {
- screenRelativeImageWidth = screenWidth;
- screenRelativeImageHeight = screenHeight;
- }
+ final screenSize = MediaQuery.sizeOf(context);
+ final fittedSize = _photo.width > 0 && _photo.height > 0
+ ? applyBoxFit(
+ BoxFit.contain,
+ Size(_photo.width.toDouble(), _photo.height.toDouble()),
+ screenSize,
+ ).destination
+ : screenSize;
return Center(
child: SizedBox(
- width: screenRelativeImageWidth,
- height: screenRelativeImageHeight,
+ width: fittedSize.width,
+ height: fittedSize.height,
child: widget.isFromMemories
? const _DelayedLoadingIndicator()
: const EnteLoadingWidget(color: Colors.white),
@@ -243,17 +238,7 @@ class _ZoomableImageState extends State<ZoomableImage> {
widget.isGuestView ||
!widget.enableVerticalSwipeActions
? null
- : (d) => {
- if (!_isZooming)
- {
- if (d.delta.dy > dragSensitivity)
- {
- {unawaited(Navigator.maybePop(context))},
- }
- else if (d.delta.dy < (dragSensitivity * -1))
- {showDetailsSheet(context, widget.photo)},
- },
- };
+ : _onVerticalDragUpdate;
return GestureDetector(
onVerticalDragUpdate: verticalDragCallback,
child: content,