Skip to content

armgit / ente

Public Imported from GitHub
0

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

Expose app bar sliver geometry

ashilkne2ca3675cc41
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 f192a2e1a2..c9198a952e 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
@@ -79,16 +79,15 @@ class GalleryAppBarWidget extends StatefulWidget {
final bottomHeight = isHierarchicalSearchable
? AppBarFilterChips.preferredHeight(context)
: 0.0;
- final metrics = resolveHeaderAppBarMetrics(
+ final geometry = SliverAppBarComponent.resolveGeometry(
context,
subtitle: null,
expandedHeight: _sliverExpandedHeight,
collapsedHeight: toolbarHeight,
titleBuilderHeight: null,
+ bottomHeight: bottomHeight,
);
- return MediaQuery.paddingOf(context).top +
- metrics.collapsedHeight +
- bottomHeight;
+ return geometry.minExtent;
}
static double sliverExpandedHeight(
@@ -98,16 +97,15 @@ class GalleryAppBarWidget extends StatefulWidget {
final bottomHeight = isHierarchicalSearchable
? AppBarFilterChips.preferredHeight(context)
: 0.0;
- final metrics = resolveHeaderAppBarMetrics(
+ final geometry = SliverAppBarComponent.resolveGeometry(
context,
subtitle: null,
expandedHeight: _sliverExpandedHeight,
collapsedHeight: toolbarHeight,
titleBuilderHeight: null,
+ bottomHeight: bottomHeight,
);
- return MediaQuery.paddingOf(context).top +
- metrics.expandedHeight +
- bottomHeight;
+ return geometry.maxExtent;
}
static GalleryAppBarConfig sliverConfig(
diff --git a/mobile/packages/ente_components/lib/components/app_bar_component.dart b/mobile/packages/ente_components/lib/components/app_bar_component.dart
index 7a6ef8f475..5fe449fcf8 100644
--- a/mobile/packages/ente_components/lib/components/app_bar_component.dart
+++ b/mobile/packages/ente_components/lib/components/app_bar_component.dart
@@ -49,7 +49,7 @@ class AppBarComponent extends StatefulWidget {
this.actions = const [],
this.bottom,
this.expandedHeight,
- this.collapsedHeight = 56,
+ this.collapsedHeight = _defaultCollapsedHeight,
this.horizontalPadding = Spacing.lg,
this.backgroundColor,
this.showExpandedBackButton = true,
@@ -209,7 +209,7 @@ class _AppBarComponentState extends State<AppBarComponent> {
@override
Widget build(BuildContext context) {
final colors = context.componentColors;
- final metrics = resolveHeaderAppBarMetrics(
+ final metrics = _resolveHeaderAppBarMetrics(
context,
subtitle: widget.subtitle,
expandedHeight: widget.expandedHeight,
@@ -300,7 +300,7 @@ class SliverAppBarComponent extends StatelessWidget {
this.actions = const [],
this.bottom,
this.expandedHeight,
- this.collapsedHeight = 56,
+ this.collapsedHeight = _defaultCollapsedHeight,
this.horizontalPadding = Spacing.lg,
this.backgroundColor,
this.showExpandedBackButton = true,
@@ -325,10 +325,32 @@ class SliverAppBarComponent extends StatelessWidget {
final Color? backgroundColor;
final bool showExpandedBackButton;
+ static HeaderAppBarGeometry resolveGeometry(
+ BuildContext context, {
+ String? subtitle,
+ double? expandedHeight,
+ double collapsedHeight = _defaultCollapsedHeight,
+ double? titleBuilderHeight,
+ double bottomHeight = 0,
+ }) {
+ final metrics = _resolveHeaderAppBarMetrics(
+ context,
+ subtitle: subtitle,
+ expandedHeight: expandedHeight,
+ collapsedHeight: collapsedHeight,
+ titleBuilderHeight: titleBuilderHeight,
+ );
+ final topPadding = MediaQuery.paddingOf(context).top;
+ return HeaderAppBarGeometry(
+ minExtent: topPadding + metrics.collapsedHeight + bottomHeight,
+ maxExtent: topPadding + metrics.expandedHeight + bottomHeight,
+ );
+ }
+
@override
Widget build(BuildContext context) {
final colors = context.componentColors;
- final metrics = resolveHeaderAppBarMetrics(
+ final metrics = _resolveHeaderAppBarMetrics(
context,
subtitle: subtitle,
expandedHeight: expandedHeight,
@@ -730,6 +752,7 @@ class _HeaderAppBarBackButton extends StatelessWidget {
const _headerControlSize = 38.0;
const _headerControlGap = Spacing.sm;
const _defaultBackIconSize = IconSizes.medium;
+const _defaultCollapsedHeight = 56.0;
const _titleOnlyExpandedHeight = 92.0;
const _subtitleExpandedHeight = 110.0;
const _expandedContentTop = 48.0;
@@ -739,8 +762,20 @@ const _headerSnapTolerance = 1.0;
const _headerSnapDuration = Duration(milliseconds: 160);
const _titleTooltipShowDuration = Duration(seconds: 3);
-class HeaderAppBarMetrics {
- const HeaderAppBarMetrics({
+class HeaderAppBarGeometry {
+ const HeaderAppBarGeometry({
+ required this.minExtent,
+ required this.maxExtent,
+ });
+
+ final double minExtent;
+ final double maxExtent;
+
+ double get collapseExtent => maxExtent - minExtent;
+}
+
+class _HeaderAppBarMetrics {
+ const _HeaderAppBarMetrics({
required this.expandedHeight,
required this.collapsedHeight,
required this.expandedTitleLineHeight,
@@ -757,7 +792,7 @@ class HeaderAppBarMetrics {
double get collapseExtent => expandedHeight - collapsedHeight;
}
-HeaderAppBarMetrics resolveHeaderAppBarMetrics(
+_HeaderAppBarMetrics _resolveHeaderAppBarMetrics(
BuildContext context, {
required String? subtitle,
required double? expandedHeight,
@@ -794,7 +829,7 @@ HeaderAppBarMetrics resolveHeaderAppBarMetrics(
_expandedContentBottomGap,
);
- return HeaderAppBarMetrics(
+ return _HeaderAppBarMetrics(
expandedHeight: effectiveExpandedHeight,
collapsedHeight: effectiveCollapsedHeight,
expandedTitleLineHeight: expandedTitleLineHeight,