π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
[mobile][photos] Keep album header layout and actions consistent
r4khule8b0582ac246
diff --git a/mobile/apps/photos/lib/ui/viewer/gallery/gallery_app_bar_widget.dart b/mobile/apps/photos/lib/ui/viewer/gallery/gallery_app_bar_widget.dartindex 79bad10e10..18b3ccc91a 100644--- a/mobile/apps/photos/lib/ui/viewer/gallery/gallery_app_bar_widget.dart+++ b/mobile/apps/photos/lib/ui/viewer/gallery/gallery_app_bar_widget.dart@@ -123,26 +123,31 @@ class GalleryAppBarWidget extends StatefulWidget {);final isHierarchicalSearchable =inheritedSearchFilterData?.isHierarchicalSearchable ?? false;+ final hasCustomBottom = bottomHeight != null;bottomHeight ??= isHierarchicalSearchable? AppBarFilterChips.preferredHeight(context): 0.0;final isSearching =- inheritedSearchFilterData- ?.searchFilterDataProvider- ?.isSearchingNotifier- .value ??- false;- if (hasCover && !isSearching) {+ isHierarchicalSearchable &&+ (inheritedSearchFilterData+ ?.searchFilterDataProvider+ ?.isSearchingNotifier+ .value ??+ false);+ if (_usesCoverHeader(+ hasCover: hasCover,+ hasCustomBottom: hasCustomBottom,+ isSearching: isSearching,+ )) {return AlbumCoverAppBar.resolveGeometry(context,collapsedHeight: toolbarHeight,bottomHeight: bottomHeight,);}- final collapsibleBottomHeight = AlbumDescriptionHeader.preferredHeight(- context,- description,- );+ final collapsibleBottomHeight = hasCustomBottom+ ? 0.0+ : AlbumDescriptionHeader.preferredHeight(context, description);return SliverAppBarComponent.resolveGeometry(context,subtitle: subtitle,@@ -154,6 +159,12 @@ class GalleryAppBarWidget extends StatefulWidget {);}+ static bool _usesCoverHeader({+ required bool hasCover,+ required bool hasCustomBottom,+ required bool isSearching,+ }) => hasCover && !hasCustomBottom && !isSearching;+final GalleryType type;final String? title;final String? subtitle;@@ -305,31 +316,8 @@ class _GalleryAppBarWidgetState extends State<GalleryAppBarWidget> {return const SliverToBoxAdapter(child: SizedBox.shrink());}- final descriptionHeader = AlbumDescriptionHeader.maybeOf(- context,- widget.collection?.displayDescription,- );-- if (widget.bottom != null) {- return _GallerySliverAppBar(- title: _appBarTitle,- subtitle: widget.subtitle,- actions: _getDefaultActions(context),- bottom: widget.bottom,- );- }-- if (!isHierarchicalSearchable) {- if (widget.cover != null) {- return _albumCoverAppBar();- }- return _GallerySliverAppBar(- title: _appBarTitle,- subtitle: widget.subtitle,- actions: _getDefaultActions(context),- collapsibleBottom: descriptionHeader,- bottom: widget.bottom,- );+ if (widget.bottom != null || !isHierarchicalSearchable) {+ return _buildHeader(bottom: widget.bottom);}return ValueListenableBuilder(@@ -342,18 +330,34 @@ class _GalleryAppBarWidgetState extends State<GalleryAppBarWidget> {),child: AppBarFilterChips(animateRecommendations: widget.cover != null),),- builder: (context, isSearching, child) {- if (widget.cover != null && !isSearching) {- return _albumCoverAppBar(bottom: child as PreferredSizeWidget);- }- return _GallerySliverAppBar(- title: _appBarTitle,- subtitle: widget.subtitle,- actions: isSearching ? const [] : _getDefaultActions(context),- bottom: child as PreferredSizeWidget,- collapsibleBottom: descriptionHeader,- );- },+ builder: (context, isSearching, child) => _buildHeader(+ bottom: child as PreferredSizeWidget,+ isSearching: isSearching,+ ),+ );+ }++ Widget _buildHeader({PreferredSizeWidget? bottom, bool isSearching = false}) {+ if (GalleryAppBarWidget._usesCoverHeader(+ hasCover: widget.cover != null,+ hasCustomBottom: widget.bottom != null,+ isSearching: isSearching,+ )) {+ return _albumCoverAppBar(bottom: bottom);+ }+ return _GallerySliverAppBar(+ title: _appBarTitle,+ subtitle: widget.subtitle,+ actions: isSearching+ ? const []+ : _getDefaultActions(context, onCover: false),+ bottom: bottom,+ collapsibleBottom: widget.bottom == null+ ? AlbumDescriptionHeader.maybeOf(+ context,+ widget.collection?.displayDescription,+ )+ : null,);}@@ -368,8 +372,11 @@ class _GalleryAppBarWidgetState extends State<GalleryAppBarWidget> {backgroundColor: GalleryAppBarWidget.backgroundColor(context),collapsedHeight: GalleryAppBarWidget.toolbarHeight,bottom: bottom,- actionsBuilder: (foregroundColor) =>- _getDefaultActions(context, foregroundColor: foregroundColor),+ actionsBuilder: (foregroundColor) => _getDefaultActions(+ context,+ onCover: true,+ foregroundColor: foregroundColor,+ ),coverActions: [if (widget.selectedFiles.files.isEmpty) ...[AlbumCoverActionButton(@@ -565,10 +572,10 @@ class _GalleryAppBarWidgetState extends State<GalleryAppBarWidget> {List<Widget> _getDefaultActions(BuildContext context, {+ required bool onCover,Color? foregroundColor,}) {final List<Widget> actions = <Widget>[];- final onCover = foregroundColor != null;final iconButtonVariant = onCover? IconButtonComponentVariant.unfilled: IconButtonComponentVariant.primary;@@ -690,6 +697,7 @@ class _GalleryAppBarWidgetState extends State<GalleryAppBarWidget> {userId: userId,isArchived: isArchived,isHidden: isHidden,+ onCover: onCover,),onSelected: (AlbumPopupAction value) async {if (value == AlbumPopupAction.editDetails) {@@ -823,6 +831,7 @@ class _GalleryAppBarWidgetState extends State<GalleryAppBarWidget> {required int userId,required bool isArchived,required bool isHidden,+ required bool onCover,}) async {final warningColor = context.componentColors.warning;final canAutoAdd =@@ -853,7 +862,7 @@ class _GalleryAppBarWidgetState extends State<GalleryAppBarWidget> {size: IconSizes.small,),),- if (galleryType.showMap() && widget.cover == null)+ if (galleryType.showMap() && !onCover)_menuOption(AlbumPopupAction.map,strings.map,@@ -862,7 +871,7 @@ class _GalleryAppBarWidgetState extends State<GalleryAppBarWidget> {size: IconSizes.small,),),- if (galleryType.canSort() && widget.cover == null)+ if (galleryType.canSort() && !onCover)_menuOption(AlbumPopupAction.sort,strings.sortAlbumsBy,@@ -993,8 +1002,7 @@ class _GalleryAppBarWidgetState extends State<GalleryAppBarWidget> {size: IconSizes.small,),),- if (_isAlbumSlideshowAvailable && widget.cover == null)- _slideshowMenuOption(strings),+ if (_isAlbumSlideshowAvailable && !onCover) _slideshowMenuOption(strings),if (canAutoAdd)_menuOption(AlbumPopupAction.autoAddPhotos,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 c9b254a715..522ffc8d3a 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@@ -2,6 +2,7 @@ import "dart:convert";import "dart:io";import "package:dio/dio.dart";+import "package:ente_components/ente_components.dart";import "package:ente_pure_utils/ente_pure_utils.dart";import "package:ente_strings/ente_strings.dart";import "package:figma_squircle/figma_squircle.dart";@@ -336,6 +337,66 @@ void main() {},);+ testWidgets(+ "keeps custom-bottom header geometry and menu actions consistent",+ (tester) async {+ final selectedFiles = SelectedFiles();+ final collection = _collection()+ ..pubMagicMetadata = CollectionPubMagicMetadata(+ description: "Description",+ );+ final appBar = GalleryAppBarWidget.sliverConfig(+ GalleryType.ownedCollection,+ "Album",+ selectedFiles,+ collection: collection,+ cover: _file(1),+ bottom: const PreferredSize(+ preferredSize: Size.fromHeight(40),+ child: SizedBox(height: 40, child: Text("Custom bottom")),+ ),+ );+ await tester.pumpWidget(+ MaterialApp(+ theme: lightThemeData,+ localizationsDelegates: StringsLocalizations.localizationsDelegates,+ supportedLocales: StringsLocalizations.supportedLocales,+ home: Scaffold(+ body: Builder(+ builder: (context) =>+ CustomScrollView(slivers: [appBar.buildSliver(context)]),+ ),+ ),+ ),+ );+ await tester.pumpAndSettle();+ expect(find.byType(SliverAppBarComponent), findsOneWidget);+ expect(find.text("Custom bottom"), findsOneWidget);+ final geometry = appBar.resolveGeometry(+ tester.element(find.byType(GalleryAppBarWidget)),+ );+ final header = tester.widget<SliverPersistentHeader>(+ find.byType(SliverPersistentHeader),+ );+ expect(geometry.minExtent, header.delegate.minExtent);+ expect(geometry.maxExtent, header.delegate.maxExtent);+ final menu = tester.widget<EntePopupMenuButton<AlbumPopupAction>>(+ find.byType(EntePopupMenuButton<AlbumPopupAction>),+ );+ final options = await menu.optionsBuilder();+ expect(+ options.map((option) => option.value),+ containsAll([+ AlbumPopupAction.map,+ AlbumPopupAction.sort,+ AlbumPopupAction.albumSlideshow,+ ]),+ );+ await _disposeAlbum(tester);+ selectedFiles.dispose();+ },+ );+testWidgets("animates the thumbnail into the header through reversal and cover changes",(tester) async {