π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
[mob][photos] Refine mosaic thumbnail loading
ashil-pilot9b1f3fbcca7b
diff --git a/mobile/apps/photos/lib/models/gallery/gallery_groups.dart b/mobile/apps/photos/lib/models/gallery/gallery_groups.dartindex 27cc7d9582..dea104d575 100644--- a/mobile/apps/photos/lib/models/gallery/gallery_groups.dart+++ b/mobile/apps/photos/lib/models/gallery/gallery_groups.dart@@ -428,10 +428,6 @@ class GalleryGroups {final showGroupHeader = groupType.showGroupHeader();final targetRowHeight =(widthAvailable - (crossAxisCount - 1) * spacing) / crossAxisCount;- final largeThumbnailMinExtent =- (widthAvailable - (photoGridSizeDefault - 2) * spacing) /- (photoGridSizeDefault - 1) *- 0.9;final groupLayouts = <SectionLayout>[];var currentIndex = 0;var currentOffset = 0.0;@@ -439,14 +435,12 @@ class GalleryGroups {for (final groupID in _groupIdToFilesMap.keys) {final filesInGroup = _groupIdToFilesMap[groupID]!;final rows = MosaicLayoutCalculator.computeRows(- aspectRatios: filesInGroup- .map(- (file) => MosaicLayoutCalculator.aspectRatioForDimensions(- file.width,- file.height,- ),- )- .toList(growable: false),+ aspectRatios: filesInGroup.map(+ (file) => MosaicLayoutCalculator.aspectRatioForDimensions(+ file.width,+ file.height,+ ),+ ),availableWidth: widthAvailable,targetRowHeight: targetRowHeight,spacing: spacing,@@ -493,7 +487,6 @@ class GalleryGroups {fileIndex++) {final file = filesInGroup[fileIndex];- final itemWidth = row.itemWidths[fileIndex - row.firstIndex];rowChildren.add(RepaintBoundary(key: ValueKey(tagPrefix + file.tag),@@ -503,9 +496,7 @@ class GalleryGroups {limitSelectionToOne: limitSelectionToOne,tag: tagPrefix,photoGridSize: crossAxisCount,- thumbnailSize: itemWidth >= largeThumbnailMinExtent- ? thumbnailLargeSize- : thumbnailSmallSize,+ thumbnailSize: thumbnailLargeSize,currentUserID: currentUserID,),),diff --git a/mobile/apps/photos/lib/models/gallery/mosaic_layout.dart b/mobile/apps/photos/lib/models/gallery/mosaic_layout.dartindex 5ddedebc40..4b41bbdb17 100644--- a/mobile/apps/photos/lib/models/gallery/mosaic_layout.dart+++ b/mobile/apps/photos/lib/models/gallery/mosaic_layout.dart@@ -1,3 +1,4 @@+import "dart:collection";import "dart:math" as math;import "package:photos/models/gallery/section_layout.dart";@@ -108,7 +109,7 @@ class MosaicLayoutCalculator {}static List<MosaicRowLayout> computeRows({- required List<double> aspectRatios,+ required Iterable<double> aspectRatios,required double availableWidth,required double targetRowHeight,required double spacing,@@ -124,13 +125,6 @@ class MosaicLayoutCalculator {throw ArgumentError.value(spacing, "spacing");}- final normalizedRatios = aspectRatios- .map(- (ratio) => ratio.isFinite && ratio > 0- ? ratio.clamp(_minimumAspectRatio, _maximumAspectRatio).toDouble()- : 1.0,- )- .toList(growable: false);final rows = <MosaicRowLayout>[];final pendingRatios = <double>[];final maximumRowHeight = targetRowHeight * _maximumRowHeightFactor;@@ -173,7 +167,7 @@ class MosaicLayoutCalculator {lastIndex: pendingFirstIndex + pendingRatios.length - 1,minOffset: rowOffset,height: height,- itemWidths: List.unmodifiable(widths),+ itemWidths: UnmodifiableListView(widths),),);rowOffset += height + spacing;@@ -183,7 +177,10 @@ class MosaicLayoutCalculator {pendingMinimumRatio = double.infinity;}- for (final ratio in normalizedRatios) {+ for (final rawRatio in aspectRatios) {+ final ratio = rawRatio.isFinite && rawRatio > 0+ ? rawRatio.clamp(_minimumAspectRatio, _maximumAspectRatio).toDouble()+ : 1.0;if (pendingRatios.isNotEmpty) {final candidateCount = pendingRatios.length + 1;final candidateRatioSum = pendingRatioSum + ratio;@@ -215,6 +212,6 @@ class MosaicLayoutCalculator {}addPendingRow(fillWidth: false);- return List.unmodifiable(rows);+ return UnmodifiableListView(rows);}}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.dartindex ced133b00d..f70dea8382 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@@ -125,7 +125,8 @@ class _GalleryFileWidgetState extends State<GalleryFileWidget> {diskLoadDeferDuration: galleryThumbnailDiskLoadDeferDuration,serverLoadDeferDuration: galleryThumbnailServerLoadDeferDuration,shouldShowLivePhotoOverlay: true,- // Recreate the loader when a mosaic tile crosses thumbnail tiers.+ // Recreate the loader when the effective tier changes, such as when+ // switching between Grid and Mosaic layouts.key: ValueKey((heroTag, effectiveThumbnailSize)),thumbnailSize: effectiveThumbnailSize,useRequestedThumbnailSizeForLocalCache: widget.thumbnailSize != null,diff --git a/mobile/apps/photos/test/models/gallery_groups_mosaic_test.dart b/mobile/apps/photos/test/models/gallery_groups_mosaic_test.dartindex 8b8171c640..8b781b6689 100644--- a/mobile/apps/photos/test/models/gallery_groups_mosaic_test.dart+++ b/mobile/apps/photos/test/models/gallery_groups_mosaic_test.dart@@ -1,16 +1,20 @@import "package:dio/dio.dart";+import "package:flutter/material.dart";import "package:flutter_test/flutter_test.dart";import "package:package_info_plus/package_info_plus.dart";import "package:photos/core/configuration.dart";+import "package:photos/core/constants.dart";import "package:photos/models/file/dummy_file.dart";import "package:photos/models/file/file.dart";import "package:photos/models/file/file_type.dart";import "package:photos/models/gallery/fixed_extent_section_layout.dart";import "package:photos/models/gallery/gallery_groups.dart";+import "package:photos/models/gallery/mosaic_grid_row.dart";import "package:photos/models/gallery/mosaic_layout.dart";import "package:photos/models/metadata/file_magic.dart";import "package:photos/service_locator.dart";import "package:photos/settings/local_settings.dart";+import "package:photos/ui/viewer/gallery/component/gallery_file_widget.dart";import "package:photos/ui/viewer/gallery/component/group/type.dart";import "package:shared_preferences/shared_preferences.dart";@@ -168,6 +172,47 @@ void main() {expect(groups.getFileAtScrollOffset(section.maxOffset), same(files.last));});+ testWidgets("mosaic rows request large thumbnails for every tile", (+ tester,+ ) async {+ final files = List<EnteFile>.generate(+ 2,+ (index) => _file(+ index: index,+ creationTime: DateTime(2026, 8, 19).microsecondsSinceEpoch,+ width: index.isEven ? 1 : 4,+ height: 1,+ ),+ growable: false,+ );+ final groups = _galleryGroups(+ files: files,+ groupType: GroupType.none,+ groupHeaderExtent: GalleryGroups.spacing,+ );+ final section = groups.groupLayouts.single as MosaicSectionLayout;++ await tester.pumpWidget(+ const MaterialApp(+ home: SizedBox(key: ValueKey("mosaic-builder-context")),+ ),+ );+ final context = tester.element(+ find.byKey(const ValueKey("mosaic-builder-context")),+ );+ final rowWidget =+ section.builder(context, section.bodyFirstIndex) as MosaicGridRow;+ final galleryTiles = rowWidget.children.map(+ (child) => (child as RepaintBoundary).child! as GalleryFileWidget,+ );++ expect(galleryTiles, hasLength(files.length));+ expect(+ galleryTiles.map((tile) => tile.thumbnailSize),+ everyElement(thumbnailLargeSize),+ );+ });+test("file geometry survives replacement with the same stable identity", () {final files = List<EnteFile>.generate(20,diff --git a/mobile/apps/photos/test/models/mosaic_layout_test.dart b/mobile/apps/photos/test/models/mosaic_layout_test.dartindex 46db7b65bd..59ac27e45a 100644--- a/mobile/apps/photos/test/models/mosaic_layout_test.dart+++ b/mobile/apps/photos/test/models/mosaic_layout_test.dart@@ -214,19 +214,5 @@ void main() {expect(section.getMinChildIndexForScrollOffset(139), 13);expect(section.getMinChildIndexForScrollOffset(169), 13);});-- test(- "finds the last child without including a row at its leading edge",- () {- expect(section.getMaxChildIndexForScrollOffset(100), 10);- expect(section.getMaxChildIndexForScrollOffset(105), 10);- expect(section.getMaxChildIndexForScrollOffset(105.001), 11);- expect(section.getMaxChildIndexForScrollOffset(117), 11);- expect(section.getMaxChildIndexForScrollOffset(117.001), 12);- expect(section.getMaxChildIndexForScrollOffset(139), 12);- expect(section.getMaxChildIndexForScrollOffset(139.001), 13);- expect(section.getMaxChildIndexForScrollOffset(169), 13);- },- );});}