Skip to content

armgit / ente

Public Imported from GitHub
0

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

Animate library sharing title on collapse

Neeraj Guptad2bec9e6acba
diff --git a/mobile/apps/photos/lib/ui/sharing/library_sharing/library_sharing_page.dart b/mobile/apps/photos/lib/ui/sharing/library_sharing/library_sharing_page.dart
index 544e995b7c..f4cf61cb71 100644
--- a/mobile/apps/photos/lib/ui/sharing/library_sharing/library_sharing_page.dart
+++ b/mobile/apps/photos/lib/ui/sharing/library_sharing/library_sharing_page.dart
@@ -126,8 +126,9 @@ class _LibrarySharingPageState extends State<LibrarySharingPage> {
Widget _content(BuildContext context) {
return AppBarComponent(
title: _recipient.label,
- titleBuilderHeight: _titleBuilderHeight(context),
- titleBuilder: _titleBuilder,
+ eyebrow: _controller.isAddingAlbums
+ ? LibrarySharingStrings.shareWith
+ : LibrarySharingStrings.sharingWith,
controller: _scrollController,
onBack: () => Navigator.of(context).maybePop(),
actions: [
@@ -150,30 +151,6 @@ class _LibrarySharingPageState extends State<LibrarySharingPage> {
bool get _showSelectionSheet =>
_controller.isSelecting && _controller.hasSelection;
- Widget _titleBuilder(BuildContext context, HeaderAppBarTitleState state) {
- final colors = context.componentColors;
- return Column(
- mainAxisAlignment: MainAxisAlignment.center,
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- Text(
- _controller.isAddingAlbums
- ? LibrarySharingStrings.shareWith
- : LibrarySharingStrings.sharingWith,
- maxLines: 1,
- overflow: TextOverflow.ellipsis,
- style: _librarySharingEyebrowStyle.copyWith(color: colors.textLight),
- ),
- Text(
- _recipient.label,
- maxLines: 1,
- overflow: TextOverflow.ellipsis,
- style: state.textStyle.copyWith(color: colors.textBase),
- ),
- ],
- );
- }
-
List<Widget> _slivers(BuildContext context) {
if (_controller.isLoading) {
return const [
@@ -393,17 +370,6 @@ class _LibrarySharingPageState extends State<LibrarySharingPage> {
});
}
- double _titleBuilderHeight(BuildContext context) {
- final textScaler = MediaQuery.textScalerOf(context);
- return _scaledLineHeight(textScaler, _librarySharingEyebrowStyle) +
- _scaledLineHeight(textScaler, TextStyles.display2);
- }
-
- double _scaledLineHeight(TextScaler textScaler, TextStyle style) {
- final fontSize = style.fontSize ?? 14;
- return textScaler.scale(fontSize) * (style.height ?? 1);
- }
-
Future<void> _applySelection() async {
await _showFailureIfNeeded(
await _controller.applySelection(),
@@ -476,12 +442,5 @@ class _LibrarySharingPageState extends State<LibrarySharingPage> {
/// Source: https://www.figma.com/design/BuBNPPytxlVnqfmCUW0mgz/Ente-Visual-Design?node-id=17186-38829&m=dev
const double _fullLibraryEmptyStateTopPadding = 131;
-/// The reference uses an Outfit Semibold 16/32 eyebrow above Display 2.
-/// Source: https://www.figma.com/design/BuBNPPytxlVnqfmCUW0mgz/Ente-Visual-Design?node-id=15782-102259&m=dev
-final TextStyle _librarySharingEyebrowStyle = TextStyles.display2.copyWith(
- fontSize: 16,
- height: 2,
-);
-
// Prevents the final grid row from jumping under the sheet before measurement.
const double _estimatedExpandedSelectionSheetHeight = 320;
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 d209e26ea5..70dc9f4426 100644
--- a/mobile/packages/ente_components/lib/components/app_bar_component.dart
+++ b/mobile/packages/ente_components/lib/components/app_bar_component.dart
@@ -36,6 +36,7 @@ class AppBarComponent extends StatefulWidget {
super.key,
required this.title,
required this.slivers,
+ this.eyebrow,
this.titleBuilder,
this.titleBuilderHeight,
this.onTitleTap,
@@ -56,9 +57,12 @@ class AppBarComponent extends StatefulWidget {
this.controller,
this.physics,
this.cacheExtent,
- });
+ }) : assert(eyebrow == null || titleBuilder == null);
final String title;
+
+ /// Context shown above [title] when expanded and inline when collapsed.
+ final String? eyebrow;
final HeaderAppBarTitleBuilder? titleBuilder;
/// Vertical space reserved for [titleBuilder] in both header states.
@@ -216,6 +220,7 @@ class _AppBarComponentState extends State<AppBarComponent> {
subtitle: widget.subtitle,
expandedHeight: widget.expandedHeight,
collapsedHeight: widget.collapsedHeight,
+ hasEyebrow: widget.eyebrow != null,
titleBuilderHeight: widget.titleBuilderHeight,
);
_collapseExtent = metrics.collapseExtent;
@@ -233,6 +238,7 @@ class _AppBarComponentState extends State<AppBarComponent> {
slivers: [
SliverAppBarComponent(
title: widget.title,
+ eyebrow: widget.eyebrow,
titleBuilder: widget.titleBuilder,
titleBuilderHeight: widget.titleBuilderHeight,
onTitleTap: widget.onTitleTap,
@@ -289,6 +295,7 @@ class SliverAppBarComponent extends StatelessWidget {
const SliverAppBarComponent({
super.key,
required this.title,
+ this.eyebrow,
this.titleBuilder,
this.titleBuilderHeight,
this.onTitleTap,
@@ -306,9 +313,10 @@ class SliverAppBarComponent extends StatelessWidget {
this.horizontalPadding = Spacing.lg,
this.backgroundColor,
this.showExpandedBackButton = true,
- });
+ }) : assert(eyebrow == null || titleBuilder == null);
final String title;
+ final String? eyebrow;
final HeaderAppBarTitleBuilder? titleBuilder;
final double? titleBuilderHeight;
final VoidCallback? onTitleTap;
@@ -330,6 +338,7 @@ class SliverAppBarComponent extends StatelessWidget {
static HeaderAppBarGeometry resolveGeometry(
BuildContext context, {
String? subtitle,
+ String? eyebrow,
double? expandedHeight,
double collapsedHeight = _defaultCollapsedHeight,
double? titleBuilderHeight,
@@ -340,6 +349,7 @@ class SliverAppBarComponent extends StatelessWidget {
subtitle: subtitle,
expandedHeight: expandedHeight,
collapsedHeight: collapsedHeight,
+ hasEyebrow: eyebrow != null,
titleBuilderHeight: titleBuilderHeight,
);
final topPadding = MediaQuery.paddingOf(context).top;
@@ -357,6 +367,7 @@ class SliverAppBarComponent extends StatelessWidget {
subtitle: subtitle,
expandedHeight: expandedHeight,
collapsedHeight: collapsedHeight,
+ hasEyebrow: eyebrow != null,
titleBuilderHeight: titleBuilderHeight,
);
@@ -364,6 +375,7 @@ class SliverAppBarComponent extends StatelessWidget {
pinned: true,
delegate: _HeaderAppBarDelegate(
title: title,
+ eyebrow: eyebrow,
titleBuilder: titleBuilder,
titleBuilderHeight: titleBuilderHeight,
onTitleTap: onTitleTap,
@@ -395,6 +407,7 @@ class SliverAppBarComponent extends StatelessWidget {
class _HeaderAppBarDelegate extends SliverPersistentHeaderDelegate {
const _HeaderAppBarDelegate({
required this.title,
+ required this.eyebrow,
required this.titleBuilder,
required this.titleBuilderHeight,
required this.onTitleTap,
@@ -421,6 +434,7 @@ class _HeaderAppBarDelegate extends SliverPersistentHeaderDelegate {
});
final String title;
+ final String? eyebrow;
final HeaderAppBarTitleBuilder? titleBuilder;
final double? titleBuilderHeight;
final VoidCallback? onTitleTap;
@@ -462,7 +476,14 @@ class _HeaderAppBarDelegate extends SliverPersistentHeaderDelegate {
? 1.0
: (shrinkOffset / scrollRange).clamp(0.0, 1.0);
final titleProgress = Curves.easeInOut.transform(progress);
- final expandedTitleHeight = titleBuilderHeight ?? expandedTitleLineHeight;
+ final eyebrowLineHeight = eyebrow == null
+ ? 0.0
+ : _scaledLineHeight(
+ MediaQuery.textScalerOf(context),
+ _expandedEyebrowStyle,
+ );
+ final expandedTitleHeight =
+ titleBuilderHeight ?? expandedTitleLineHeight + eyebrowLineHeight;
final collapsedTitleHeight = titleBuilderHeight ?? collapsedTitleLineHeight;
final titleLayoutHeight = titleBuilderHeight == null
? lerpDouble(expandedTitleHeight, collapsedTitleHeight, titleProgress)!
@@ -546,6 +567,7 @@ class _HeaderAppBarDelegate extends SliverPersistentHeaderDelegate {
),
_MovingHeaderTitle(
title: title,
+ eyebrow: eyebrow,
titleBuilder: titleBuilder,
onTap: onTitleTap,
onDoubleTap: onTitleDoubleTap,
@@ -616,6 +638,7 @@ class _HeaderAppBarDelegate extends SliverPersistentHeaderDelegate {
@override
bool shouldRebuild(covariant _HeaderAppBarDelegate oldDelegate) {
return oldDelegate.title != title ||
+ oldDelegate.eyebrow != eyebrow ||
titleBuilder != null ||
oldDelegate.titleBuilder != null ||
oldDelegate.titleBuilderHeight != titleBuilderHeight ||
@@ -771,6 +794,15 @@ const _headerSnapTolerance = 1.0;
const _headerSnapDuration = Duration(milliseconds: 160);
const _titleTooltipShowDuration = Duration(seconds: 3);
+/// Figma: https://www.figma.com/design/BuBNPPytxlVnqfmCUW0mgz/Ente-Visual-Design?node-id=21089-125212&m=dev
+const _collapsedEyebrowGap = 6.0;
+const _minimumCollapsedTitleWidth = 24.0;
+
+final _expandedEyebrowStyle = TextStyles.display2.copyWith(
+ fontSize: 16,
+ height: 30 / 16,
+);
+
class HeaderAppBarGeometry {
const HeaderAppBarGeometry({
required this.minExtent,
@@ -806,6 +838,7 @@ _HeaderAppBarMetrics _resolveHeaderAppBarMetrics(
required String? subtitle,
required double? expandedHeight,
required double collapsedHeight,
+ required bool hasEyebrow,
required double? titleBuilderHeight,
}) {
final textScaler = MediaQuery.textScalerOf(context);
@@ -817,6 +850,9 @@ _HeaderAppBarMetrics _resolveHeaderAppBarMetrics(
textScaler,
TextStyles.display3,
);
+ final eyebrowLineHeight = hasEyebrow
+ ? _scaledLineHeight(textScaler, _expandedEyebrowStyle)
+ : 0.0;
final subtitleLineHeight = _scaledLineHeight(textScaler, TextStyles.mini);
final subtitleHeight = subtitle == null
? 0.0
@@ -832,7 +868,7 @@ _HeaderAppBarMetrics _resolveHeaderAppBarMetrics(
),
);
final expandedTextBlockHeight =
- (titleBuilderHeight ?? expandedTitleLineHeight) +
+ (titleBuilderHeight ?? expandedTitleLineHeight + eyebrowLineHeight) +
(subtitle == null ? 0 : _subtitleGap + subtitleHeight);
final effectiveExpandedHeight = _maxDouble(
expandedHeight ?? defaultExpandedHeight,
@@ -882,6 +918,7 @@ double _actionsWidth(int actionCount) {
class _MovingHeaderTitle extends StatelessWidget {
const _MovingHeaderTitle({
required this.title,
+ required this.eyebrow,
required this.titleBuilder,
required this.onTap,
required this.onDoubleTap,
@@ -895,6 +932,7 @@ class _MovingHeaderTitle extends StatelessWidget {
});
final String title;
+ final String? eyebrow;
final HeaderAppBarTitleBuilder? titleBuilder;
final VoidCallback? onTap;
final VoidCallback? onDoubleTap;
@@ -935,6 +973,16 @@ class _MovingHeaderTitle extends StatelessWidget {
);
}
+ final eyebrowText = eyebrow;
+ if (eyebrowText != null) {
+ return Positioned(
+ left: left,
+ right: right,
+ top: top,
+ child: _buildEyebrowTitle(context, eyebrowText, textStyle),
+ );
+ }
+
final canShowTitleTooltip = !disableTapReveal && onTap == null;
return Positioned(
@@ -992,6 +1040,67 @@ class _MovingHeaderTitle extends StatelessWidget {
),
);
}
+
+ Widget _buildEyebrowTitle(
+ BuildContext context,
+ String eyebrow,
+ TextStyle titleStyle,
+ ) {
+ final eyebrowStyle = TextStyle.lerp(
+ _expandedEyebrowStyle,
+ TextStyles.display3,
+ progress,
+ )!.copyWith(color: context.componentColors.textLight);
+ final expandedEyebrowHeight = _scaledLineHeight(
+ MediaQuery.textScalerOf(context),
+ _expandedEyebrowStyle,
+ );
+
+ return SizedBox(
+ height: height,
+ child: LayoutBuilder(
+ builder: (context, constraints) {
+ final collapsedTitleLeft =
+ (_singleLineTextWidth(
+ context,
+ title: eyebrow,
+ style: eyebrowStyle,
+ maxWidth: constraints.maxWidth,
+ ) +
+ _collapsedEyebrowGap)
+ .clamp(
+ 0.0,
+ (constraints.maxWidth - _minimumCollapsedTitleWidth).clamp(
+ 0.0,
+ double.infinity,
+ ),
+ );
+ return Stack(
+ children: [
+ Positioned(
+ left: 0,
+ top: 0,
+ child: Text(eyebrow, maxLines: 1, style: eyebrowStyle),
+ ),
+ Positioned(
+ left: collapsedTitleLeft * Curves.easeOut.transform(progress),
+ right: 0,
+ top:
+ expandedEyebrowHeight *
+ (1 - Curves.easeIn.transform(progress)),
+ child: Text(
+ title,
+ maxLines: 1,
+ overflow: TextOverflow.ellipsis,
+ style: titleStyle,
+ ),
+ ),
+ ],
+ );
+ },
+ ),
+ );
+ }
}
double _singleLineTextWidth(
diff --git a/mobile/packages/ente_components/test/components/app_surface_widgets_test.dart b/mobile/packages/ente_components/test/components/app_surface_widgets_test.dart
index 7763f4b9c7..a031e21be3 100644
--- a/mobile/packages/ente_components/test/components/app_surface_widgets_test.dart
+++ b/mobile/packages/ente_components/test/components/app_surface_widgets_test.dart
@@ -826,7 +826,7 @@ void main() {
});
testWidgets(
- 'SliverAppBarComponent collapse progress matches reserved space',
+ 'SliverAppBarComponent collapses title content and reserved space',
(tester) async {
final scrollController = ScrollController();
addTearDown(scrollController.dispose);
@@ -837,7 +837,8 @@ void main() {
controller: scrollController,
slivers: [
const SliverAppBarComponent(
- title: 'Menu items',
+ title: 'Priyadarshini Bandopadhyay',
+ eyebrow: 'Sharing with',
subtitle: 'Scroll to collapse',
onBack: null,
actions: [Icon(Icons.add)],
@@ -854,19 +855,31 @@ void main() {
height: 600,
);
+ final eyebrow = find.text('Sharing with');
+ final titleFinder = find.text('Priyadarshini Bandopadhyay');
+ expect(
+ tester.getTopLeft(eyebrow).dy,
+ lessThan(tester.getTopLeft(titleFinder).dy),
+ );
+
scrollController.jumpTo(48);
await tester.pump();
- final title = tester.widget<Text>(find.text('Menu items'));
+ final title = tester.widget<Text>(titleFinder);
expect(title.style?.fontSize, greaterThan(16));
expect(title.style?.fontFamily, TextStyles.display2.fontFamily);
- scrollController.jumpTo(74);
+ scrollController.jumpTo(104);
await tester.pump();
- final collapsedTitle = tester.widget<Text>(find.text('Menu items'));
+ final collapsedTitle = tester.widget<Text>(titleFinder);
expect(collapsedTitle.style?.fontSize, closeTo(20, 0.01));
expect(collapsedTitle.style?.fontFamily, TextStyles.display3.fontFamily);
+ expect(collapsedTitle.overflow, TextOverflow.ellipsis);
+ expect(
+ tester.getTopLeft(eyebrow).dy,
+ closeTo(tester.getTopLeft(titleFinder).dy, 0.5),
+ );
expect(tester.getTopLeft(find.text('Item 0')).dy, closeTo(56, 1));
},
);