π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
[mobile][photos] Restore album cover scroll geometry
r4khulb7465160dbc9
diff --git a/mobile/apps/photos/lib/ui/viewer/gallery/component/album_cover_app_bar.dart b/mobile/apps/photos/lib/ui/viewer/gallery/component/album_cover_app_bar.dartindex cc041e557e..1e8560ef49 100644--- a/mobile/apps/photos/lib/ui/viewer/gallery/component/album_cover_app_bar.dart+++ b/mobile/apps/photos/lib/ui/viewer/gallery/component/album_cover_app_bar.dart@@ -47,24 +47,6 @@ class AlbumCoverAppBar extends StatefulWidget {BuildContext context, {required double collapsedHeight,required double bottomHeight,- }) {- final geometry = _resolveCoverGeometry(- context,- collapsedHeight: collapsedHeight,- bottomHeight: bottomHeight,- );- return HeaderAppBarGeometry(- minExtent: geometry.minExtent,- maxExtent:- geometry.minExtent +- math.min(_coverCollapseScrollExtent, geometry.collapseExtent),- );- }-- static HeaderAppBarGeometry _resolveCoverGeometry(- BuildContext context, {- required double collapsedHeight,- required double bottomHeight,}) {final topPadding = MediaQuery.paddingOf(context).top;return HeaderAppBarGeometry(@@ -123,142 +105,81 @@ class _AlbumCoverAppBarState extends State<AlbumCoverAppBar> with RouteAware {final colors = context.componentColors;final bottomHeight = widget.bottom?.preferredSize.height ?? 0;final description = widget.collection.displayDescription;- final geometry = AlbumCoverAppBar._resolveCoverGeometry(+ final geometry = AlbumCoverAppBar.resolveGeometry(context,collapsedHeight: widget.collapsedHeight,bottomHeight: bottomHeight,);- return _CoverCollapseSliver(- expandedCollapseExtent: geometry.collapseExtent,- child: SliverPersistentHeader(- pinned: true,- delegate: _AlbumCoverDelegate(- geometry: geometry,- topPadding: MediaQuery.paddingOf(context).top,- collapsedHeight: widget.collapsedHeight,- bottomHeight: bottomHeight,- colors: colors,+ return SliverPersistentHeader(+ pinned: true,+ delegate: _AlbumCoverDelegate(+ geometry: geometry,+ topPadding: MediaQuery.paddingOf(context).top,+ collapsedHeight: widget.collapsedHeight,+ bottomHeight: bottomHeight,+ colors: colors,+ backgroundColor: widget.backgroundColor,+ pinnedOverlayStyle: _pinnedOverlayStyle,+ isCovered: _isCovered,+ title: widget.title,+ actionsBuilder: widget.actionsBuilder,+ bottom: widget.bottom,+ foregroundKey: _coverForegroundKey,+ photoBuilder: (foreground, collapseOffset) => _CoverPhoto(+ photoKey: _coverPhotoKey,+ foreground: foreground,+ foregroundNotifier: _coverForegroundNotifier,+ collapseOffset: collapseOffset,+ imageBottomInset: _coverBottomInset(bottomHeight) - 1,+ cover: widget.cover,backgroundColor: widget.backgroundColor,- pinnedOverlayStyle: _pinnedOverlayStyle,- isCovered: _isCovered,- title: widget.title,- actionsBuilder: widget.actionsBuilder,- bottom: widget.bottom,- foregroundKey: _coverForegroundKey,- photoBuilder: (foreground, collapseOffset) => _CoverPhoto(- photoKey: _coverPhotoKey,- foreground: foreground,- foregroundNotifier: _coverForegroundNotifier,- collapseOffset: collapseOffset,- imageBottomInset: _coverBottomInset(bottomHeight) - 1,- cover: widget.cover,- backgroundColor: widget.backgroundColor,- heroTag: widget.heroTag,- ),- content: Column(- mainAxisSize: MainAxisSize.min,- children: [- _CoverCaption(- GalleryFilesState.maybeOf(context)?.captureDateRange,+ heroTag: widget.heroTag,+ ),+ content: Column(+ mainAxisSize: MainAxisSize.min,+ children: [+ _CoverCaption(GalleryFilesState.maybeOf(context)?.captureDateRange),+ Semantics(+ header: true,+ child: Text(+ widget.title,+ maxLines: 2,+ overflow: TextOverflow.ellipsis,+ textAlign: TextAlign.center,+ style: TextStyles.display1.copyWith(color: colors.specialWhite),),- Semantics(- header: true,+ ),+ if (description != null) ...[+ const SizedBox(height: Spacing.sm),+ Padding(+ padding: const EdgeInsets.symmetric(horizontal: 18),child: Text(- widget.title,- maxLines: 2,+ description,+ maxLines: _descriptionMaxLines,overflow: TextOverflow.ellipsis,textAlign: TextAlign.center,- style: TextStyles.display1.copyWith(- color: colors.specialWhite,+ style: TextStyles.mini.copyWith(+ color: colors.specialWhite.withValues(alpha: 0.92),),),),- if (description != null) ...[- const SizedBox(height: Spacing.sm),- Padding(- padding: const EdgeInsets.symmetric(horizontal: 18),- child: Text(- description,- maxLines: _descriptionMaxLines,- overflow: TextOverflow.ellipsis,- textAlign: TextAlign.center,- style: TextStyles.mini.copyWith(- color: colors.specialWhite.withValues(alpha: 0.92),- ),- ),- ),- ],- if (widget.coverActions.isNotEmpty) ...[- const SizedBox(height: _contentSpacing),- Row(- mainAxisSize: MainAxisSize.min,- spacing: Spacing.md,- children: widget.coverActions,- ),- ],],- ),+ if (widget.coverActions.isNotEmpty) ...[+ const SizedBox(height: _contentSpacing),+ Row(+ mainAxisSize: MainAxisSize.min,+ spacing: Spacing.md,+ children: widget.coverActions,+ ),+ ],+ ],),),);}}-class _CoverCollapseSliver extends SingleChildRenderObjectWidget {- const _CoverCollapseSliver({- required this.expandedCollapseExtent,- required super.child,- });-- final double expandedCollapseExtent;-- @override- RenderObject createRenderObject(BuildContext context) =>- _RenderCoverCollapseSliver(expandedCollapseExtent);-- @override- void updateRenderObject(- BuildContext context,- covariant _RenderCoverCollapseSliver renderObject,- ) {- renderObject.expandedCollapseExtent = expandedCollapseExtent;- }-}--class _RenderCoverCollapseSliver extends RenderProxySliver {- _RenderCoverCollapseSliver(this._expandedCollapseExtent);-- double _expandedCollapseExtent;-- set expandedCollapseExtent(double value) {- if (_expandedCollapseExtent == value) return;- _expandedCollapseExtent = value;- markNeedsLayout();- }-- @override- void performLayout() {- final scrollExtent = math.min(- _coverCollapseScrollExtent,- _expandedCollapseExtent,- );- final offset = constraints.scrollOffset;- final coverOffset = offset < scrollExtent- ? offset * _expandedCollapseExtent / scrollExtent- : offset + _expandedCollapseExtent - scrollExtent;- child!.layout(- constraints.copyWith(scrollOffset: coverOffset),- parentUsesSize: true,- );- final childGeometry = child!.geometry!;- geometry = childGeometry.copyWith(- scrollExtent:- childGeometry.scrollExtent - _expandedCollapseExtent + scrollExtent,- );- }-}-class AlbumCoverActionButton extends StatelessWidget {const AlbumCoverActionButton({super.key,@@ -1031,7 +952,6 @@ double _coverBottomInset(double bottomHeight) {}const _coverHeight = 441.0;-const _coverCollapseScrollExtent = 120.0;const _coverDissolveHeight = 100.0;const _topScrimHeight = 31.0;const _bottomOverlap = 25.0;diff --git a/mobile/apps/photos/test/ui/viewer/gallery/album_cover_app_bar_test.dart b/mobile/apps/photos/test/ui/viewer/gallery/album_cover_app_bar_test.dartindex bafa5c4145..106d1525a6 100644--- a/mobile/apps/photos/test/ui/viewer/gallery/album_cover_app_bar_test.dart+++ b/mobile/apps/photos/test/ui/viewer/gallery/album_cover_app_bar_test.dart@@ -224,7 +224,12 @@ void main() {final gesture = await tester.startGesture(tester.getCenter(find.byType(CustomScrollView)),);- await gesture.moveBy(const Offset(0, -100));+ final collapseExtent = AlbumCoverAppBar.resolveGeometry(+ tester.element(find.byType(AlbumCoverAppBar)),+ collapsedHeight: kToolbarHeight,+ bottomHeight: 0,+ ).collapseExtent;+ await gesture.moveBy(Offset(0, -collapseExtent * 0.7));await tester.pump(const Duration(seconds: 1));final compactTitle = find.byWidgetPredicate((widget) =>diff --git a/mobile/apps/photos/test/ui/viewer/gallery/collection_page_cover_test.dart b/mobile/apps/photos/test/ui/viewer/gallery/collection_page_cover_test.dartindex 8da9b270a0..96694701bc 100644--- a/mobile/apps/photos/test/ui/viewer/gallery/collection_page_cover_test.dart+++ b/mobile/apps/photos/test/ui/viewer/gallery/collection_page_cover_test.dart@@ -232,64 +232,94 @@ void main() {await _disposeAlbum(tester);});- testWidgets("lets a short album fully collapse its cover", (tester) async {- tester.view.devicePixelRatio = 1;- tester.view.physicalSize = const Size(402, 874);- addTearDown(tester.view.resetDevicePixelRatio);- addTearDown(tester.view.resetPhysicalSize);- final previousLayout = localSettings.getGalleryLayoutType();- final previousGridSize = localSettings.getPhotoGridSize();- addTearDown(() async {- await localSettings.setGalleryLayoutType(previousLayout);- await localSettings.setPhotoGridSize(previousGridSize);- });- await localSettings.setGalleryLayoutType(GalleryLayoutType.justified);- await localSettings.setPhotoGridSize(5);- final collection = _collection();- final cover = _file(1)..pubMmdEncodedJson = '{"w":400,"h":600}';- await tester.runAsync(() async {- await FilesDB.instance.insertMultiple([cover]);- await CollectionsService.instance.getCover(collection);+ for (final fileCount in [1, 30]) {+ testWidgets("anchors $fileCount photos through album cover collapse", (+ tester,+ ) async {+ tester.view.devicePixelRatio = 1;+ tester.view.physicalSize = const Size(402, 874);+ addTearDown(tester.view.resetDevicePixelRatio);+ addTearDown(tester.view.resetPhysicalSize);+ final previousLayout = localSettings.getGalleryLayoutType();+ final previousGridSize = localSettings.getPhotoGridSize();+ addTearDown(() async {+ await localSettings.setGalleryLayoutType(previousLayout);+ await localSettings.setPhotoGridSize(previousGridSize);+ });+ await localSettings.setGalleryLayoutType(GalleryLayoutType.justified);+ await localSettings.setPhotoGridSize(5);+ final collection = _collection();+ final files = List.generate(+ fileCount,+ (index) => _file(index + 1)..pubMmdEncodedJson = '{"w":400,"h":600}',+ );+ await tester.runAsync(() async {+ await FilesDB.instance.insertMultiple(files);+ await CollectionsService.instance.getCover(collection);+ });+ await _pumpAlbum(tester, collection);+ await _expectCover(tester, files.last, count: fileCount);+ final boundaries = tester.state<GalleryBoundariesProviderState>(+ find.byType(GalleryBoundariesProvider),+ );+ final position = boundaries.scrollControllerNotifier.value!.position;+ final header = tester.widget<AlbumCoverAppBar>(+ find.byType(AlbumCoverAppBar),+ );+ final geometry = AlbumCoverAppBar.resolveGeometry(+ tester.element(find.byType(AlbumCoverAppBar)),+ collapsedHeight: header.collapsedHeight,+ bottomHeight: header.bottom?.preferredSize.height ?? 0,+ );+ if (fileCount == 1) {+ expect(+ position.maxScrollExtent,+ closeTo(geometry.collapseExtent, 0.01),+ );+ }+ for (final fraction in [0.0, 0.5, 1.0]) {+ final offset = geometry.collapseExtent * fraction;+ position.jumpTo(offset);+ await tester.pumpAndSettle();+ final tileRect = tester.getRect(find.byType(GalleryFileWidget).first);+ final viewport = tester.getRect(find.byType(CustomScrollView));+ final focalPoint = tileRect.intersect(viewport).center;+ final first = await tester.startGesture(+ focalPoint - const Offset(30, 0),+ pointer: 1,+ );+ final second = await tester.startGesture(+ focalPoint + const Offset(30, 0),+ pointer: 2,+ );+ await tester.pump();+ final overlayTile = find.byKey(+ const ValueKey(("gallery-grid-zoom-tile", 0)),+ );+ expect(overlayTile, findsOneWidget);+ expect(+ tester.getRect(overlayTile),+ rectMoreOrLessEquals(tileRect, epsilon: 0.01),+ );+ await second.up();+ await first.up();+ await tester.pumpAndSettle();+ expect(position.pixels, closeTo(offset, 0.01));+ }+ if (fileCount == 1) {+ position.jumpTo(0);+ await tester.pump();+ await tester.drag(+ find.byType(CustomScrollView),+ Offset(0, -geometry.collapseExtent * 1.5),+ );+ await tester.pumpAndSettle();+ expect(position.pixels, closeTo(geometry.collapseExtent, 0.01));+ }+ expect(tester.takeException(), isNull);+ await _disposeAlbum(tester);});- await _pumpAlbum(tester, collection);- await _expectCover(tester, cover, count: 1);- final boundaries = tester.state<GalleryBoundariesProviderState>(- find.byType(GalleryBoundariesProvider),- );- final position = boundaries.scrollControllerNotifier.value!.position;- final header = tester.widget<AlbumCoverAppBar>(- find.byType(AlbumCoverAppBar),- );- final geometry = AlbumCoverAppBar.resolveGeometry(- tester.element(find.byType(AlbumCoverAppBar)),- collapsedHeight: header.collapsedHeight,- bottomHeight: header.bottom?.preferredSize.height ?? 0,- );- expect(position.maxScrollExtent, closeTo(geometry.collapseExtent, 0.01));- await tester.drag(find.byType(CustomScrollView), const Offset(0, -160));- await tester.pumpAndSettle();- expect(position.pixels, closeTo(geometry.collapseExtent, 0.01));- final tileRect = tester.getRect(find.byType(GalleryFileWidget));- final first = await tester.startGesture(- tileRect.center - const Offset(30, 0),- pointer: 1,- );- final second = await tester.startGesture(- tileRect.center + const Offset(30, 0),- pointer: 2,- );- await tester.pump();- expect(- tester.getRect(find.byKey(const ValueKey(("gallery-grid-zoom-tile", 0)))),- tileRect,- );- await second.up();- await first.up();- await tester.pumpAndSettle();- expect(position.pixels, closeTo(geometry.collapseExtent, 0.01));- expect(tester.takeException(), isNull);- await _disposeAlbum(tester);- });+ }testWidgets("uses a pending local photo and excludes ignored photos", (tester,@@ -767,7 +797,7 @@ void main() {).scrollControllerNotifier.value!;- for (final offset in [120.0, 0.0]) {+ for (final offset in [galleryScroll.position.maxScrollExtent, 0.0]) {galleryScroll.jumpTo(offset);await tester.pump();expect(tester.element(face), same(faceElement));