Skip to content

armgit / ente

Public Imported from GitHub
0

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

Clean up gallery app bar widget helpers

ashilkn2d1d20420c1c
diff --git a/mobile/apps/photos/lib/ui/viewer/gallery/gallery.dart b/mobile/apps/photos/lib/ui/viewer/gallery/gallery.dart
index 2b49caae9c..5f0c7a97e8 100644
--- a/mobile/apps/photos/lib/ui/viewer/gallery/gallery.dart
+++ b/mobile/apps/photos/lib/ui/viewer/gallery/gallery.dart
@@ -621,21 +621,6 @@ class GalleryState extends State<Gallery> {
? const NeverScrollableScrollPhysics()
: const ExponentialBouncingScrollPhysics();
- Widget _buildWithAppBar(BuildContext context, Widget child) {
- final appBar = widget.appBar;
- if (appBar == null) {
- return child;
- }
-
- return CustomScrollView(
- physics: _scrollPhysics,
- slivers: [
- appBar.buildSliver(context),
- SliverFillRemaining(hasScrollBody: false, child: child),
- ],
- );
- }
-
@override
Widget build(BuildContext context) {
_logger.info("Building Gallery ${widget.tagPrefix}");
@@ -722,12 +707,20 @@ class GalleryState extends State<Gallery> {
],
)
: const SizedBox.shrink();
- return _buildWithAppBar(context, placeholder);
+ return _GalleryAppBarScrollBody(
+ appBar: widget.appBar,
+ physics: _scrollPhysics,
+ child: placeholder,
+ );
}
GalleryFilesState.of(context).setGalleryFiles = _allGalleryFiles;
if (!_hasLoadedFiles) {
- return _buildWithAppBar(context, widget.loadingWidget);
+ return _GalleryAppBarScrollBody(
+ appBar: widget.appBar,
+ physics: _scrollPhysics,
+ child: widget.loadingWidget,
+ );
}
if (galleryGroups == null) {
@@ -735,7 +728,11 @@ class GalleryState extends State<Gallery> {
}
final groups = galleryGroups;
if (groups == null) {
- return _buildWithAppBar(context, widget.loadingWidget);
+ return _GalleryAppBarScrollBody(
+ appBar: widget.appBar,
+ physics: _scrollPhysics,
+ child: widget.loadingWidget,
+ );
}
// Check if width changed due to orientation change and update gallery groups
@@ -768,7 +765,20 @@ class GalleryState extends State<Gallery> {
type: _groupType,
galleryType: widget.galleryType,
child: _allGalleryFiles.isEmpty
- ? _buildEmptyGalleryContent()
+ ? _GalleryAppBarScrollBody(
+ appBar: widget.appBar,
+ physics: _scrollPhysics,
+ child: Column(
+ mainAxisAlignment: MainAxisAlignment.spaceBetween,
+ children: [
+ if (widget.addHeaderOrFooterEmptyState)
+ widget.header ?? const SizedBox.shrink(),
+ Expanded(child: widget.emptyState),
+ if (widget.addHeaderOrFooterEmptyState)
+ widget.footer ?? const SizedBox.shrink(),
+ ],
+ ),
+ )
: CustomScrollBar(
scrollController: _scrollController,
galleryGroups: groups,
@@ -851,20 +861,33 @@ class GalleryState extends State<Gallery> {
),
);
}
+}
+
+class _GalleryAppBarScrollBody extends StatelessWidget {
+ const _GalleryAppBarScrollBody({
+ required this.appBar,
+ required this.physics,
+ required this.child,
+ });
+
+ final GalleryAppBarConfig? appBar;
+ final ScrollPhysics physics;
+ final Widget child;
+
+ @override
+ Widget build(BuildContext context) {
+ final appBarConfig = appBar;
+ if (appBarConfig == null) {
+ return child;
+ }
- Widget _buildEmptyGalleryContent() {
- final emptyColumn = Column(
- mainAxisAlignment: MainAxisAlignment.spaceBetween,
- children: [
- if (widget.addHeaderOrFooterEmptyState)
- widget.header ?? const SizedBox.shrink(),
- Expanded(child: widget.emptyState),
- if (widget.addHeaderOrFooterEmptyState)
- widget.footer ?? const SizedBox.shrink(),
+ return CustomScrollView(
+ physics: physics,
+ slivers: [
+ appBarConfig.buildSliver(context),
+ SliverFillRemaining(hasScrollBody: false, child: child),
],
);
-
- return _buildWithAppBar(context, emptyColumn);
}
}
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.dart
index 088726c302..d2a2e3ad48 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
@@ -264,15 +264,15 @@ class _GalleryAppBarWidgetState extends State<GalleryAppBarWidget> {
),
builder: (context, isSearching, child) {
return widget.asSliver
- ? _buildSliverAppBar(
- context,
+ ? _GallerySliverAppBar(
+ title: _appBarTitle,
actions: isSearching
? const []
: _getDefaultActions(context),
bottom: child as PreferredSizeWidget,
)
- : _buildAppBar(
- context,
+ : _GalleryFixedAppBar(
+ title: _appBarTitle,
actions: isSearching
? const []
: _getDefaultActions(context),
@@ -281,85 +281,14 @@ class _GalleryAppBarWidgetState extends State<GalleryAppBarWidget> {
},
)
: widget.asSliver
- ? _buildSliverAppBar(context, actions: _getDefaultActions(context))
- : _buildAppBar(context, actions: _getDefaultActions(context));
- }
-
- Widget _buildSliverAppBar(
- BuildContext context, {
- required List<Widget> actions,
- PreferredSizeWidget? bottom,
- }) {
- return SliverAppBarComponent(
- title: _appBarTitle,
- actions: actions,
- bottom: bottom,
- expandedHeight: GalleryAppBarWidget._sliverExpandedHeight,
- collapsedHeight: GalleryAppBarWidget.toolbarHeight,
- backgroundColor: getEnteColorScheme(context).backgroundColour,
- );
- }
-
- AppBar _buildAppBar(
- BuildContext context, {
- required List<Widget> actions,
- PreferredSizeWidget? bottom,
- }) {
- final colors = context.componentColors;
-
- return AppBar(
- elevation: 0,
- centerTitle: false,
- automaticallyImplyLeading: false,
- toolbarHeight: GalleryAppBarWidget.toolbarHeight,
- titleSpacing: 0,
- title: Padding(
- padding: const EdgeInsets.symmetric(horizontal: Spacing.lg),
- child: SizedBox(
- height: GalleryAppBarWidget._controlRowHeight,
- child: Row(
- children: [
- const _GalleryAppBarBackButton(),
- const SizedBox(width: Spacing.sm),
- Expanded(
- child: Align(
- alignment: Alignment.centerLeft,
- child: TooltipComponent(
- message: _appBarTitle,
- child: Text(
- _appBarTitle,
- style: TextStyles.h2.copyWith(color: colors.textBase),
- maxLines: 1,
- overflow: TextOverflow.ellipsis,
- ),
- ),
- ),
- ),
- if (actions.isNotEmpty) ...[
- const SizedBox(width: Spacing.md),
- ..._actionsWithSpacing(actions),
- ],
- ],
- ),
- ),
- ),
- bottom: bottom,
- surfaceTintColor: Colors.transparent,
- backgroundColor: getEnteColorScheme(context).backgroundColour,
- );
- }
-
- List<Widget> _actionsWithSpacing(List<Widget> actions) {
- return [
- for (var index = 0; index < actions.length; index++) ...[
- SizedBox.square(
- dimension: GalleryAppBarWidget._controlRowHeight,
- child: Center(child: actions[index]),
- ),
- if (index != actions.length - 1)
- const SizedBox(width: GalleryAppBarWidget._actionGap),
- ],
- ];
+ ? _GallerySliverAppBar(
+ title: _appBarTitle,
+ actions: _getDefaultActions(context),
+ )
+ : _GalleryFixedAppBar(
+ title: _appBarTitle,
+ actions: _getDefaultActions(context),
+ );
}
Widget _buildPopupMenuAction<T>({
@@ -1425,6 +1354,95 @@ class _GalleryAppBarWidgetState extends State<GalleryAppBarWidget> {
}
}
+class _GallerySliverAppBar extends StatelessWidget {
+ const _GallerySliverAppBar({
+ required this.title,
+ required this.actions,
+ this.bottom,
+ });
+
+ final String title;
+ final List<Widget> actions;
+ final PreferredSizeWidget? bottom;
+
+ @override
+ Widget build(BuildContext context) {
+ return SliverAppBarComponent(
+ title: title,
+ actions: actions,
+ bottom: bottom,
+ expandedHeight: GalleryAppBarWidget._sliverExpandedHeight,
+ collapsedHeight: GalleryAppBarWidget.toolbarHeight,
+ backgroundColor: getEnteColorScheme(context).backgroundColour,
+ );
+ }
+}
+
+class _GalleryFixedAppBar extends StatelessWidget {
+ const _GalleryFixedAppBar({
+ required this.title,
+ required this.actions,
+ this.bottom,
+ });
+
+ final String title;
+ final List<Widget> actions;
+ final PreferredSizeWidget? bottom;
+
+ @override
+ Widget build(BuildContext context) {
+ final colors = context.componentColors;
+
+ return AppBar(
+ elevation: 0,
+ centerTitle: false,
+ automaticallyImplyLeading: false,
+ toolbarHeight: GalleryAppBarWidget.toolbarHeight,
+ titleSpacing: 0,
+ title: Padding(
+ padding: const EdgeInsets.symmetric(horizontal: Spacing.lg),
+ child: SizedBox(
+ height: GalleryAppBarWidget._controlRowHeight,
+ child: Row(
+ children: [
+ const _GalleryAppBarBackButton(),
+ const SizedBox(width: Spacing.sm),
+ Expanded(
+ child: Align(
+ alignment: Alignment.centerLeft,
+ child: TooltipComponent(
+ message: title,
+ child: Text(
+ title,
+ style: TextStyles.h2.copyWith(color: colors.textBase),
+ maxLines: 1,
+ overflow: TextOverflow.ellipsis,
+ ),
+ ),
+ ),
+ ),
+ if (actions.isNotEmpty) ...[
+ const SizedBox(width: Spacing.md),
+ for (var index = 0; index < actions.length; index++) ...[
+ SizedBox.square(
+ dimension: GalleryAppBarWidget._controlRowHeight,
+ child: Center(child: actions[index]),
+ ),
+ if (index != actions.length - 1)
+ const SizedBox(width: GalleryAppBarWidget._actionGap),
+ ],
+ ],
+ ],
+ ),
+ ),
+ ),
+ bottom: bottom,
+ surfaceTintColor: Colors.transparent,
+ backgroundColor: getEnteColorScheme(context).backgroundColour,
+ );
+ }
+}
+
class _GalleryAppBarBackButton extends StatelessWidget {
const _GalleryAppBarBackButton();