Skip to content

armgit / ente

Public Imported from GitHub
0

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

[mob][package] Add header app bar component (#10462)

aman-pilot7d89c6def368
diff --git a/mobile/packages/ente_components/example/lib/main.dart b/mobile/packages/ente_components/example/lib/main.dart
index ba20dc1b2c..ff680187a2 100644
--- a/mobile/packages/ente_components/example/lib/main.dart
+++ b/mobile/packages/ente_components/example/lib/main.dart
@@ -102,43 +102,71 @@ class CatalogHome extends StatefulWidget {
}
class _CatalogHomeState extends State<CatalogHome> {
+ late ThemeMode _themeMode = widget.themeMode;
+
+ @override
+ void didUpdateWidget(covariant CatalogHome oldWidget) {
+ super.didUpdateWidget(oldWidget);
+ if (oldWidget.themeMode != widget.themeMode) {
+ _themeMode = widget.themeMode;
+ }
+ }
+
+ void _setThemeMode(ThemeMode mode) {
+ setState(() => _themeMode = mode);
+ widget.onThemeModeChanged(mode);
+ }
+
@override
Widget build(BuildContext context) {
final colors = context.componentColors;
final sections = _sections();
return Scaffold(
- appBar: AppBarComponent(
- title: 'Components',
- leading: Builder(
- builder: (context) {
- return IconButtonComponent(
- tooltip: 'Settings',
- variant: IconButtonComponentVariant.unfilled,
- onTap: () => Scaffold.of(context).openDrawer(),
- icon: const _CatalogHugeIcon(HugeIcons.strokeRoundedMenu01),
- );
- },
- ),
- actions: [
- _CatalogThemeCycleButton(
- themeMode: widget.themeMode,
- onChanged: widget.onThemeModeChanged,
- ),
- ],
- ),
drawer: const CatalogSettingsDrawer(),
- body: ListView(
- padding: const EdgeInsets.all(Spacing.lg),
- children: [
- for (final section in sections) ...[
- _CatalogSectionTile(
- section: section,
- themeMode: widget.themeMode,
- onThemeModeChanged: widget.onThemeModeChanged,
+ body: CustomScrollView(
+ slivers: [
+ HeaderAppBarComponent(
+ title: 'Components',
+ subtitle: 'Design system catalog',
+ backButton: Builder(
+ builder: (context) {
+ return IconButtonComponent(
+ tooltip: 'Settings',
+ variant: IconButtonComponentVariant.unfilled,
+ onTap: () => Scaffold.of(context).openDrawer(),
+ icon: const _CatalogHugeIcon(HugeIcons.strokeRoundedMenu01),
+ );
+ },
),
- if (section != sections.last) const SizedBox(height: Spacing.lg),
- ],
+ actions: [
+ _CatalogThemeCycleButton(
+ themeMode: _themeMode,
+ onChanged: _setThemeMode,
+ ),
+ ],
+ ),
+ SliverPadding(
+ padding: const EdgeInsets.fromLTRB(
+ Spacing.lg,
+ Spacing.xs,
+ Spacing.lg,
+ Spacing.lg,
+ ),
+ sliver: SliverList.builder(
+ itemCount: sections.length * 2 - 1,
+ itemBuilder: (context, index) {
+ if (index.isOdd) {
+ return const SizedBox(height: Spacing.lg);
+ }
+ return _CatalogSectionTile(
+ section: sections[index ~/ 2],
+ themeMode: _themeMode,
+ onThemeModeChanged: widget.onThemeModeChanged,
+ );
+ },
+ ),
+ ),
],
),
backgroundColor: colors.backgroundBase,
@@ -219,36 +247,16 @@ class _CatalogHomeState extends State<CatalogHome> {
previewBuilder: (_) => const _TextInputPreview(),
),
CatalogSection(
- title: 'Title bar',
- icon: HugeIcons.strokeRoundedMenu01,
- components: const [
- 'Default',
- 'Home',
- 'Preserving',
- 'Partially preserved',
- 'Preserved',
- 'Syncing',
- 'Video processing',
- 'Back',
- 'Onboarding',
- 'Settings',
- 'Title topbar',
- 'Title topbar no icon',
- 'Onboarding title',
- ],
- previewBuilder: (_) => const TitleBarPreview(),
- ),
- CatalogSection(
- title: 'Header',
+ title: 'Header app bar',
icon: HugeIcons.strokeRoundedHeading,
components: const [
- 'Title',
- 'Subtitle',
- 'Image',
- 'One action',
- 'Two actions',
+ 'Expanded header',
+ 'Collapsed app bar',
+ 'Scroll animation',
+ 'Long list',
],
- previewBuilder: (_) => const _HeaderPreview(),
+ previewBuilder: (_) => const _HeaderAppBarEntryPreview(),
+ routeBuilder: _buildHeaderAppBarDemo,
),
CatalogSection(
title: 'Avatar',
@@ -266,18 +274,38 @@ class _CatalogHomeState extends State<CatalogHome> {
}
}
+typedef CatalogSectionRouteBuilder =
+ Widget Function(
+ BuildContext context,
+ ThemeMode themeMode,
+ ValueChanged<ThemeMode> onThemeModeChanged,
+ );
+
+Widget _buildHeaderAppBarDemo(
+ BuildContext context,
+ ThemeMode themeMode,
+ ValueChanged<ThemeMode> onThemeModeChanged,
+) {
+ return HeaderAppBarDemoPage(
+ themeMode: themeMode,
+ onThemeModeChanged: onThemeModeChanged,
+ );
+}
+
class CatalogSection {
const CatalogSection({
required this.title,
required this.icon,
required this.components,
required this.previewBuilder,
+ this.routeBuilder,
});
final String title;
final HugeIconData icon;
final List<String> components;
final WidgetBuilder previewBuilder;
+ final CatalogSectionRouteBuilder? routeBuilder;
}
class CatalogSettingsDrawer extends StatelessWidget {
@@ -406,7 +434,7 @@ class _CatalogThemeCycleButton extends StatelessWidget {
Widget build(BuildContext context) {
return IconButtonComponent(
tooltip: 'Theme: $_currentLabel. Tap for $_nextLabel',
- variant: IconButtonComponentVariant.unfilled,
+ variant: IconButtonComponentVariant.primary,
icon: _CatalogHugeIcon(_icon),
onTap: () => onChanged(_nextMode),
);
@@ -437,13 +465,16 @@ class _CatalogSectionTile extends StatelessWidget {
size: 18,
),
onTap: () {
+ final routeBuilder = section.routeBuilder;
Navigator.of(context).push(
MaterialPageRoute<void>(
- builder: (_) => CatalogDetailPage(
- section: section,
- themeMode: themeMode,
- onThemeModeChanged: onThemeModeChanged,
- ),
+ builder: (context) => routeBuilder == null
+ ? CatalogDetailPage(
+ section: section,
+ themeMode: themeMode,
+ onThemeModeChanged: onThemeModeChanged,
+ )
+ : routeBuilder(context, themeMode, onThemeModeChanged),
),
);
},
@@ -479,24 +510,32 @@ class _CatalogDetailPageState extends State<CatalogDetailPage> {
Widget build(BuildContext context) {
final colors = context.componentColors;
return Scaffold(
- appBar: AppBarComponent(
- title: widget.section.title,
- leading: IconButtonComponent(
- tooltip: 'Back',
- icon: const _CatalogHugeIcon(HugeIcons.strokeRoundedArrowLeft02),
- onTap: () => Navigator.of(context).pop(),
- ),
- actions: [
- _CatalogThemeCycleButton(
- themeMode: _themeMode,
- onChanged: _setThemeMode,
+ body: CustomScrollView(
+ slivers: [
+ HeaderAppBarComponent(
+ title: widget.section.title,
+ subtitle: widget.section.components.join(', '),
+ onBack: () => Navigator.of(context).pop(),
+ actions: [
+ _CatalogThemeCycleButton(
+ themeMode: _themeMode,
+ onChanged: _setThemeMode,
+ ),
+ ],
+ ),
+ SliverPadding(
+ padding: const EdgeInsets.fromLTRB(
+ Spacing.lg,
+ Spacing.xs,
+ Spacing.lg,
+ Spacing.lg,
+ ),
+ sliver: SliverToBoxAdapter(
+ child: widget.section.previewBuilder(context),
+ ),
),
],
),
- body: ListView(
- padding: const EdgeInsets.all(Spacing.lg),
- children: [widget.section.previewBuilder(context)],
- ),
backgroundColor: colors.backgroundBase,
);
}
@@ -667,22 +706,30 @@ class _SettingsExampleShell extends StatelessWidget {
Widget build(BuildContext context) {
final colors = context.componentColors;
return Scaffold(
- appBar: AppBarComponent(
- title: title,
- leading: IconButtonComponent(
- tooltip: 'Back',
- icon: const _CatalogHugeIcon(HugeIcons.strokeRoundedArrowLeft02),
- onTap: () => Navigator.of(context).pop(),
- ),
- ),
- body: ListView(
- padding: const EdgeInsets.all(Spacing.lg),
- children: [
- for (var index = 0; index < children.length; index++) ...[
- children[index],
- if (index != children.length - 1)
- const SizedBox(height: Spacing.md),
- ],
+ body: CustomScrollView(
+ slivers: [
+ HeaderAppBarComponent(
+ title: title,
+ subtitle: 'Settings',
+ onBack: () => Navigator.of(context).pop(),
+ ),
+ SliverPadding(
+ padding: const EdgeInsets.fromLTRB(
+ Spacing.lg,
+ Spacing.xs,
+ Spacing.lg,
+ Spacing.lg,
+ ),
+ sliver: SliverList.builder(
+ itemCount: children.length * 2 - 1,
+ itemBuilder: (context, index) {
+ if (index.isOdd) {
+ return const SizedBox(height: Spacing.md);
+ }
+ return children[index ~/ 2];
+ },
+ ),
+ ),
],
),
backgroundColor: colors.backgroundBase,
@@ -2138,251 +2185,127 @@ class _TextInputPreviewIcon extends StatelessWidget {
}
}
-class TitleBarPreview extends StatelessWidget {
- const TitleBarPreview({super.key});
+class _HeaderImage extends StatelessWidget {
+ const _HeaderImage();
@override
Widget build(BuildContext context) {
- return const _CatalogPreviewList(
- children: [
- _CatalogPreviewGroup(
- title: 'Default',
- child: _TitleBarSample(variant: TitleBarComponentVariant.brand),
- ),
- _CatalogPreviewGroup(
- title: 'Home',
- child: _TitleBarSample(variant: TitleBarComponentVariant.home),
- ),
- _CatalogPreviewGroup(
- title: 'Preserving',
- child: _TitleBarSample(variant: TitleBarComponentVariant.preserving),
- ),
- _CatalogPreviewGroup(
- title: 'Partially preserved',
- child: _TitleBarSample(
- variant: TitleBarComponentVariant.partiallyPreserved,
- ),
- ),
- _CatalogPreviewGroup(
- title: 'Preserved',
- child: _TitleBarSample(variant: TitleBarComponentVariant.preserved),
- ),
- _CatalogPreviewGroup(
- title: 'Syncing',
- child: _TitleBarSample(variant: TitleBarComponentVariant.syncing),
- ),
- _CatalogPreviewGroup(
- title: 'Video processing',
- child: _TitleBarSample(
- variant: TitleBarComponentVariant.videoProcessing,
- ),
- ),
- _CatalogPreviewGroup(
- title: 'Back',
- child: _TitleBarSample(variant: TitleBarComponentVariant.back),
- ),
- _CatalogPreviewGroup(
- title: 'Onboarding',
- child: _TitleBarSample(variant: TitleBarComponentVariant.onboarding),
- ),
- _CatalogPreviewGroup(
- title: 'Settings',
- child: _TitleBarSample(variant: TitleBarComponentVariant.settings),
- ),
- _CatalogPreviewGroup(
- title: 'Title topbar',
- child: _TitleBarSample(variant: TitleBarComponentVariant.titleTopbar),
- ),
- _CatalogPreviewGroup(
- title: 'Title topbar no icon',
- child: _TitleBarSample(
- variant: TitleBarComponentVariant.titleTopbarNoIcon,
- ),
- ),
- _CatalogPreviewGroup(
- title: 'Onboarding title',
- child: _TitleBarSample(
- variant: TitleBarComponentVariant.onboardingTitle,
- ),
+ final colors = context.componentColors;
+ return ColoredBox(
+ color: colors.fillDark,
+ child: Center(
+ child: _CatalogHugeIcon(
+ HugeIcons.strokeRoundedUser,
+ color: colors.textLight,
+ size: 20,
),
- ],
+ ),
);
}
}
-class _TitleBarSample extends StatelessWidget {
- const _TitleBarSample({required this.variant});
-
- final TitleBarComponentVariant variant;
+class _HeaderAppBarEntryPreview extends StatelessWidget {
+ const _HeaderAppBarEntryPreview();
@override
Widget build(BuildContext context) {
- return SizedBox(
- width: double.infinity,
- child: TitleBarComponent(
- variant: variant,
- title: _title,
- leading: _leading,
- trailing: _trailing,
- statusIcon: _statusIcon,
- ),
+ final colors = context.componentColors;
+ return Text(
+ 'Open this section from the catalog list to test the pinned animated '
+ 'header app bar with a long scrollable list.',
+ style: TextStyles.body.copyWith(color: colors.textLight),
);
}
+}
- String? get _title {
- return switch (variant) {
- TitleBarComponentVariant.brand => 'Photos',
- TitleBarComponentVariant.home => 'Home',
- TitleBarComponentVariant.onboarding => 'Create account',
- TitleBarComponentVariant.titleTopbar => 'Albums',
- TitleBarComponentVariant.titleTopbarNoIcon => 'Albums',
- TitleBarComponentVariant.onboardingTitle => 'Secure backup',
- _ => null,
- };
- }
-
- Widget? get _leading {
- return switch (variant) {
- TitleBarComponentVariant.onboarding => null,
- _ => const _CatalogHugeIcon(HugeIcons.strokeRoundedArrowLeft02),
- };
- }
+class HeaderAppBarDemoPage extends StatefulWidget {
+ const HeaderAppBarDemoPage({
+ super.key,
+ required this.themeMode,
+ required this.onThemeModeChanged,
+ });
- Widget? get _trailing {
- return switch (variant) {
- TitleBarComponentVariant.home ||
- TitleBarComponentVariant.preserving ||
- TitleBarComponentVariant.partiallyPreserved ||
- TitleBarComponentVariant.preserved ||
- TitleBarComponentVariant.syncing ||
- TitleBarComponentVariant.videoProcessing => const _CatalogHugeIcon(
- HugeIcons.strokeRoundedMoreHorizontal,
- ),
- TitleBarComponentVariant.settings ||
- TitleBarComponentVariant.titleTopbar => const _CatalogHugeIcon(
- HugeIcons.strokeRoundedSearch01,
- ),
- _ => null,
- };
- }
+ final ThemeMode themeMode;
+ final ValueChanged<ThemeMode> onThemeModeChanged;
- Widget? get _statusIcon {
- return switch (variant) {
- TitleBarComponentVariant.preserving ||
- TitleBarComponentVariant.partiallyPreserved ||
- TitleBarComponentVariant.preserved => const _CatalogHugeIcon(
- HugeIcons.strokeRoundedCheckmarkCircle01,
- ),
- TitleBarComponentVariant.syncing => const _CatalogHugeIcon(
- HugeIcons.strokeRoundedRefresh,
- ),
- TitleBarComponentVariant.videoProcessing => const _CatalogHugeIcon(
- HugeIcons.strokeRoundedVideo01,
- ),
- _ => null,
- };
- }
+ @override
+ State<HeaderAppBarDemoPage> createState() => _HeaderAppBarDemoPageState();
}
-class _HeaderPreview extends StatelessWidget {
- const _HeaderPreview();
+class _HeaderAppBarDemoPageState extends State<HeaderAppBarDemoPage> {
+ static const _itemCount = 48;
- @override
- Widget build(BuildContext context) {
- return const _CatalogPreviewList(
- children: [
- _CatalogPreviewGroup(
- title: 'Title + subtitle + two actions',
- child: _HeaderSample(subtitle: true, actionCount: 2),
- ),
- _CatalogPreviewGroup(
- title: 'Title + two actions',
- child: _HeaderSample(actionCount: 2),
- ),
- _CatalogPreviewGroup(
- title: 'Title + one action',
- child: _HeaderSample(actionCount: 1),
- ),
- _CatalogPreviewGroup(
- title: 'Title + subtitle',
- child: _HeaderSample(subtitle: true),
- ),
- _CatalogPreviewGroup(title: 'Title only', child: _HeaderSample()),
- _CatalogPreviewGroup(
- title: 'Title + subtitle + one action',
- child: _HeaderSample(subtitle: true, actionCount: 1),
- ),
- _CatalogPreviewGroup(
- title: 'Image + subtitle + two actions',
- child: _HeaderSample(image: true, subtitle: true, actionCount: 2),
- ),
- _CatalogPreviewGroup(
- title: 'Image + two actions',
- child: _HeaderSample(image: true, actionCount: 2),
- ),
- _CatalogPreviewGroup(
- title: 'Image + one action',
- child: _HeaderSample(image: true, actionCount: 1),
- ),
- _CatalogPreviewGroup(
- title: 'Image + subtitle',
- child: _HeaderSample(image: true, subtitle: true),
- ),
- _CatalogPreviewGroup(
- title: 'Image only',
- child: _HeaderSample(image: true),
- ),
- _CatalogPreviewGroup(
- title: 'Image + subtitle + one action',
- child: _HeaderSample(image: true, subtitle: true, actionCount: 1),
- ),
- ],
- );
- }
-}
+ late ThemeMode _themeMode = widget.themeMode;
-class _HeaderSample extends StatelessWidget {
- const _HeaderSample({
- this.image = false,
- this.subtitle = false,
- this.actionCount = 0,
- });
+ void _setThemeMode(ThemeMode mode) {
+ setState(() => _themeMode = mode);
+ widget.onThemeModeChanged(mode);
+ }
- final bool image;
- final bool subtitle;
- final int actionCount;
+ void _showAction(String label) {
+ ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text(label)));
+ }
@override
Widget build(BuildContext context) {
- return HeaderComponent(
- title: 'Title',
- subtitle: subtitle ? 'Subtitle' : null,
- leading: image ? const _HeaderImage() : null,
- actions: [
- for (var index = 0; index < actionCount; index++)
- IconButtonComponent(
- tooltip: index == 0 ? 'Add' : 'Create',
- variant: IconButtonComponentVariant.primary,
- icon: const _CatalogHugeIcon(HugeIcons.strokeRoundedAdd01),
- onTap: () {},
+ final colors = context.componentColors;
+ return Scaffold(
+ backgroundColor: colors.backgroundBase,
+ body: CustomScrollView(
+ slivers: [
+ HeaderAppBarComponent(
+ title: 'Menu items',
+ subtitle: 'Scroll to collapse into a single app bar row',
+ onBack: () => Navigator.of(context).pop(),
+ leading: const _HeaderAppBarDemoLeading(),
+ actions: [
+ IconButtonComponent(
+ tooltip: 'Add item',
+ variant: IconButtonComponentVariant.primary,
+ icon: const _CatalogHugeIcon(HugeIcons.strokeRoundedAdd01),
+ onTap: () => _showAction('Add tapped'),
+ ),
+ _CatalogThemeCycleButton(
+ themeMode: _themeMode,
+ onChanged: _setThemeMode,
+ ),
+ ],
),
- ],
+ SliverPadding(
+ padding: const EdgeInsets.fromLTRB(
+ Spacing.lg,
+ Spacing.xs,
+ Spacing.lg,
+ Spacing.xxl,
+ ),
+ sliver: SliverList.builder(
+ itemCount: _itemCount * 2 - 1,
+ itemBuilder: (context, index) {
+ if (index.isOdd) {
+ return const SizedBox(height: Spacing.md);
+ }
+ return _HeaderAppBarDemoListItem(index: index ~/ 2);
+ },
+ ),
+ ),
+ ],
+ ),
);
}
}
-class _HeaderImage extends StatelessWidget {
- const _HeaderImage();
+class _HeaderAppBarDemoLeading extends StatelessWidget {
+ const _HeaderAppBarDemoLeading();
@override
Widget build(BuildContext context) {
final colors = context.componentColors;
- return ColoredBox(
- color: colors.fillDark,
+ return DecoratedBox(
+ decoration: BoxDecoration(color: colors.primary),
child: Center(
child: _CatalogHugeIcon(
- HugeIcons.strokeRoundedUser,
- color: colors.textLight,
+ HugeIcons.strokeRoundedMenuCircle,
+ color: colors.specialWhite,
size: 20,
),
),
@@ -2390,6 +2313,63 @@ class _HeaderImage extends StatelessWidget {
}
}
+class _HeaderAppBarDemoListItem extends StatelessWidget {
+ const _HeaderAppBarDemoListItem({required this.index});
+
+ final int index;
+
+ static const _titles = [
+ 'Camera uploads',
+ 'Private albums',
+ 'Recovery key',
+ 'Shared links',
+ 'Device folders',
+ 'Storage plan',
+ 'Notifications',
+ 'Hidden items',
+ 'Trash cleanup',
+ 'Export data',
+ ];
+
+ static const _subtitles = [
+ 'Enabled on Wi-Fi',
+ 'Only visible to you',
+ 'Last checked today',
+ 'Manage public access',
+ 'Choose folders to sync',
+ 'Family plan active',
+ 'Activity and reminders',
+ 'Protected by device lock',
+ 'Auto-delete in 30 days',
+ 'Prepare local archive',
+ ];
+
+ @override
+ Widget build(BuildContext context) {
+ final colors = context.componentColors;
+ final hasSubtitle = index % 3 != 1;
+ final hasImage = index % 4 == 0 || index % 4 == 3;
+ final hasAction = index % 5 != 2;
+ final title = _titles[index % _titles.length];
+ final subtitle = _subtitles[index % _subtitles.length];
+
+ return MenuComponent(
+ title: '$title ${index + 1}',
+ subtitle: hasSubtitle ? subtitle : null,
+ leading: hasImage ? const _HeaderImage() : null,
+ trailing: hasAction
+ ? IconButtonComponent(
+ tooltip: 'Add $title',
+ variant: IconButtonComponentVariant.primary,
+ icon: const _CatalogHugeIcon(HugeIcons.strokeRoundedAdd01),
+ onTap: () {},
+ )
+ : const _CatalogTrailingIcon(HugeIcons.strokeRoundedArrowRight02),
+ titleColor: index % 7 == 0 ? colors.primary : null,
+ );
+ }
+}
+
class _SelectionPreview extends StatefulWidget {
const _SelectionPreview();
@@ -2563,14 +2543,15 @@ class _MenuItemPreviewState extends State<_MenuItemPreview> {
return MenuComponent(
title: 'Delete account',
subtitle: 'Warning color title and icon',
- leading: const _CatalogHugeIcon(
+ leading: _CatalogHugeIcon(
HugeIcons.strokeRoundedDelete02,
+ color: colors.warning,
+ size: 18,
),
trailing: const _CatalogTrailingIcon(
HugeIcons.strokeRoundedArrowRight01,
),
titleColor: colors.warning,
- iconColor: colors.warning,
onTap: () {},
);
},
diff --git a/mobile/packages/ente_components/example/test/smoke_test.dart b/mobile/packages/ente_components/example/test/smoke_test.dart
index 3f57fe2859..8df8a5a0b7 100644
--- a/mobile/packages/ente_components/example/test/smoke_test.dart
+++ b/mobile/packages/ente_components/example/test/smoke_test.dart
@@ -10,15 +10,24 @@ void main() {
expect(find.text('Components'), findsOneWidget);
});
+ testWidgets('catalog header theme button toggles theme mode', (tester) async {
+ await tester.pumpWidget(const ComponentsCatalogApp());
+
+ expect(find.byTooltip('Theme: Light. Tap for Dark'), findsOneWidget);
+
+ await tester.tap(find.byTooltip('Theme: Light. Tap for Dark'));
+ await tester.pump();
+
+ expect(find.byTooltip('Theme: Dark. Tap for Light'), findsOneWidget);
+ });
+
testWidgets('button transition preview surfaces loading and success', (
tester,
) async {
await tester.pumpWidget(
MaterialApp(
theme: ComponentTheme.lightTheme(),
- home: const Scaffold(
- body: ButtonStateCyclePreview(),
- ),
+ home: const Scaffold(body: ButtonStateCyclePreview()),
),
);
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 9702840639..99ccc7cd5b 100644
--- a/mobile/packages/ente_components/lib/components/app_bar_component.dart
+++ b/mobile/packages/ente_components/lib/components/app_bar_component.dart
@@ -1,327 +1,461 @@
-import 'package:ente_components/theme/colors.dart';
+import 'dart:ui';
+
import 'package:ente_components/theme/spacing.dart';
import 'package:ente_components/theme/text_styles.dart';
import 'package:ente_components/theme/theme.dart';
import 'package:flutter/material.dart';
-enum TitleBarComponentVariant {
- brand,
- home,
- preserving,
- partiallyPreserved,
- preserved,
- syncing,
- videoProcessing,
- back,
- onboarding,
- settings,
- titleTopbar,
- titleTopbarNoIcon,
- onboardingTitle,
-}
-
-/// Figma: https://www.figma.com/design/BuBNPPytxlVnqfmCUW0mgz/Ente-Visual-Design?node-id=2472-5809&m=dev
-/// Section: Title Bar
-/// Specs: 327px design width, 42px title/status row, centered or leading title layouts.
-class TitleBarComponent extends StatelessWidget implements PreferredSizeWidget {
- const TitleBarComponent({
+/// Figma: https://www.figma.com/design/BuBNPPytxlVnqfmCUW0mgz/Ente-Visual-Design?node-id=11439-5036&m=dev
+/// Section: Appbar/header / Header v2
+/// Specs: Pinned sliver app bar that animates between expanded and collapsed
+/// states as the surrounding scroll view collapses it.
+class HeaderAppBarComponent extends StatelessWidget {
+ const HeaderAppBarComponent({
super.key,
- this.variant = TitleBarComponentVariant.brand,
- this.title,
- this.statusText,
+ required this.title,
+ this.subtitle,
this.leading,
- this.trailing,
- this.statusIcon,
- this.height = 42,
- this.leadingWidth = 44,
- this.trailingWidth = 44,
+ this.backButton,
+ this.onBack,
+ this.actions = const [],
+ this.expandedHeight = 116,
+ this.collapsedHeight = 56,
+ this.horizontalPadding = Spacing.lg,
+ this.backgroundColor,
+ this.showExpandedBackButton = true,
});
- final TitleBarComponentVariant variant;
- final String? title;
- final String? statusText;
+ final String title;
+ final String? subtitle;
final Widget? leading;
- final Widget? trailing;
- final Widget? statusIcon;
- final double height;
- final double leadingWidth;
- final double trailingWidth;
-
- @override
- Size get preferredSize => Size.fromHeight(height);
+ final Widget? backButton;
+ final VoidCallback? onBack;
+ final List<Widget> actions;
+ final double expandedHeight;
+ final double collapsedHeight;
+ final double horizontalPadding;
+ final Color? backgroundColor;
+ final bool showExpandedBackButton;
@override
Widget build(BuildContext context) {
- final colors = context.componentColors;
- final child = variant == TitleBarComponentVariant.titleTopbarNoIcon
- ? _buildLeadingTitleBar(colors)
- : _buildCenteredTitleBar(colors);
-
- return IconTheme(
- data: IconThemeData(color: colors.textBase, size: 24),
- child: SizedBox(height: height, child: child),
+ final textScaler = MediaQuery.textScalerOf(context);
+ final expandedTitleLineHeight = _scaledLineHeight(
+ textScaler,
+ TextStyles.h1Bold,
);
- }
-
- Widget _buildCenteredTitleBar(ColorTokens colors) {
- return Stack(
- alignment: Alignment.center,
- children: [
- Padding(
- padding: EdgeInsets.symmetric(
- horizontal: _centerContentHorizontalPadding,
- ),
- child: ColoredBox(
- color: colors.specialScrim.withAlpha(0),
- child: Center(
- child: _centerContent(colors),
- ),
- ),
- ),
- Positioned(
- left: 0,
- top: 0,
- bottom: 0,
- child: _TitleBarSlot(
- width: leadingWidth,
- visible: _leadingVisible,
- child: leading,
- ),
- ),
- Positioned(
- right: 0,
- top: 0,
- bottom: 0,
- child: _TitleBarSlot(
- width: trailingWidth,
- visible: _trailingVisible,
- alignment: Alignment.centerRight,
- child: trailing,
- ),
- ),
- ],
+ final collapsedTitleLineHeight = _scaledLineHeight(
+ textScaler,
+ TextStyles.h2,
+ );
+ final subtitleLineHeight = _scaledLineHeight(textScaler, TextStyles.mini);
+ final effectiveCollapsedHeight = _maxDouble(
+ collapsedHeight,
+ _maxDouble(_headerControlSize, collapsedTitleLineHeight),
+ );
+ final effectiveExpandedHeight = _maxDouble(
+ expandedHeight,
+ _expandedContentTop +
+ expandedTitleLineHeight +
+ (subtitle == null ? 0 : _subtitleGap + subtitleLineHeight),
);
- }
- Widget _buildLeadingTitleBar(ColorTokens colors) {
- return Row(
- children: [
- _TitleBarSlot(
- width: leadingWidth,
- visible: _leadingVisible,
- child: leading,
- ),
- const SizedBox(width: Spacing.md),
- Expanded(
- child: Text(
- _effectiveTitle,
- maxLines: 1,
- overflow: TextOverflow.ellipsis,
- style: TextStyles.h1Bold.copyWith(color: colors.textBase),
- ),
- ),
- _TitleBarSlot(
- width: trailingWidth,
- visible: _trailingVisible,
- alignment: Alignment.centerRight,
- child: trailing,
- ),
- ],
+ return SliverPersistentHeader(
+ pinned: true,
+ delegate: _HeaderAppBarDelegate(
+ title: title,
+ subtitle: subtitle,
+ leading: leading,
+ backButton: backButton,
+ onBack: onBack,
+ actions: actions,
+ expandedHeight: effectiveExpandedHeight,
+ collapsedHeight: effectiveCollapsedHeight,
+ horizontalPadding: horizontalPadding,
+ topPadding: MediaQuery.paddingOf(context).top,
+ backgroundColor: backgroundColor,
+ showExpandedBackButton: showExpandedBackButton,
+ expandedTitleLineHeight: expandedTitleLineHeight,
+ collapsedTitleLineHeight: collapsedTitleLineHeight,
+ subtitleLineHeight: subtitleLineHeight,
+ ),
);
}
+}
- Widget _centerContent(ColorTokens colors) {
- if (_usesStatus) {
- return Row(
- mainAxisSize: MainAxisSize.min,
- children: [
- if (statusIcon != null) ...[
- IconTheme(
- data: IconThemeData(color: colors.primary, size: 20),
- child: SizedBox.square(dimension: 20, child: statusIcon),
- ),
- const SizedBox(width: Spacing.sm),
- ],
- Flexible(
- child: Text(
- _effectiveStatusText,
- maxLines: 1,
- overflow: TextOverflow.ellipsis,
- style: TextStyles.body.copyWith(color: colors.textBase),
- ),
- ),
- ],
- );
- }
-
- if (!_titleVisible) {
- return const SizedBox.shrink();
- }
+class _HeaderAppBarDelegate extends SliverPersistentHeaderDelegate {
+ const _HeaderAppBarDelegate({
+ required this.title,
+ required this.subtitle,
+ required this.leading,
+ required this.backButton,
+ required this.onBack,
+ required this.actions,
+ required this.expandedHeight,
+ required this.collapsedHeight,
+ required this.horizontalPadding,
+ required this.topPadding,
+ required this.backgroundColor,
+ required this.showExpandedBackButton,
+ required this.expandedTitleLineHeight,
+ required this.collapsedTitleLineHeight,
+ required this.subtitleLineHeight,
+ });
- return Text(
- _effectiveTitle,
- maxLines: 1,
- overflow: TextOverflow.ellipsis,
- style: _usesHeadingStyle
- ? TextStyles.h1Bold.copyWith(color: colors.textBase)
- : TextStyles.h1.copyWith(color: colors.textBase),
- );
- }
+ final String title;
+ final String? subtitle;
+ final Widget? leading;
+ final Widget? backButton;
+ final VoidCallback? onBack;
+ final List<Widget> actions;
+ final double expandedHeight;
+ final double collapsedHeight;
+ final double horizontalPadding;
+ final double topPadding;
+ final Color? backgroundColor;
+ final bool showExpandedBackButton;
+ final double expandedTitleLineHeight;
+ final double collapsedTitleLineHeight;
+ final double subtitleLineHeight;
- bool get _usesStatus {
- return switch (variant) {
- TitleBarComponentVariant.preserving ||
- TitleBarComponentVariant.partiallyPreserved ||
- TitleBarComponentVariant.preserved ||
- TitleBarComponentVariant.syncing ||
- TitleBarComponentVariant.videoProcessing =>
- true,
- _ => false,
- };
- }
+ @override
+ double get maxExtent => topPadding + expandedHeight;
- bool get _usesHeadingStyle {
- return switch (variant) {
- TitleBarComponentVariant.titleTopbar ||
- TitleBarComponentVariant.titleTopbarNoIcon ||
- TitleBarComponentVariant.onboardingTitle =>
- true,
- _ => false,
- };
- }
+ @override
+ double get minExtent => topPadding + collapsedHeight;
- bool get _titleVisible {
- return switch (variant) {
- TitleBarComponentVariant.back ||
- TitleBarComponentVariant.settings =>
- false,
- _ => true,
- };
- }
+ @override
+ Widget build(
+ BuildContext context,
+ double shrinkOffset,
+ bool overlapsContent,
+ ) {
+ final colors = context.componentColors;
+ final scrollRange = maxExtent - minExtent;
+ final progress = scrollRange == 0
+ ? 1.0
+ : (shrinkOffset / scrollRange).clamp(0.0, 1.0);
+ final titleProgress = Curves.easeInOut.transform(
+ (progress / 0.85).clamp(0.0, 1.0),
+ );
+ final collapsedControlTop = _centeredTop(
+ collapsedHeight,
+ _headerControlSize,
+ );
+ final collapsedTitleTop = _centeredTop(
+ collapsedHeight,
+ collapsedTitleLineHeight,
+ );
+ final expandedTextBlockHeight =
+ expandedTitleLineHeight +
+ (subtitle == null ? 0 : _subtitleGap + subtitleLineHeight);
+ final leadingTop =
+ _expandedContentTop +
+ _centerOffset(expandedTextBlockHeight, _headerControlSize);
+ final actionsTop = lerpDouble(
+ _expandedContentTop,
+ collapsedControlTop,
+ titleProgress,
+ )!;
+ final collapsedTitleLeft = _collapsedLeadingWidth(backButton) + Spacing.md;
+ final titleLeft = lerpDouble(
+ leading == null ? 0 : _headerControlSize + Spacing.md,
+ showExpandedBackButton ? collapsedTitleLeft : 0,
+ titleProgress,
+ )!;
+ final titleTop = lerpDouble(
+ _expandedContentTop,
+ collapsedTitleTop,
+ titleProgress,
+ )!;
+ final titleRight = actions.isEmpty
+ ? 0.0
+ : _actionsWidth(actions.length) + Spacing.md;
+ final leadingOpacity = 1 - titleProgress;
+ final isLeadingHidden = leadingOpacity <= 0.01;
- bool get _leadingVisible {
- return switch (variant) {
- TitleBarComponentVariant.onboarding => false,
- _ => true,
- };
+ return ColoredBox(
+ color: backgroundColor ?? colors.backgroundBase,
+ child: Padding(
+ padding: EdgeInsets.only(
+ top: topPadding,
+ left: horizontalPadding,
+ right: horizontalPadding,
+ ),
+ child: Stack(
+ fit: StackFit.expand,
+ children: [
+ if (leading != null)
+ Positioned(
+ left: 0,
+ top: leadingTop,
+ child: IgnorePointer(
+ ignoring: isLeadingHidden,
+ child: ExcludeSemantics(
+ excluding: isLeadingHidden,
+ child: Opacity(
+ opacity: leadingOpacity,
+ child: ClipRRect(
+ borderRadius: BorderRadius.circular(12),
+ child: SizedBox.square(
+ dimension: _headerControlSize,
+ child: leading,
+ ),
+ ),
+ ),
+ ),
+ ),
+ ),
+ _MovingHeaderTitle(
+ title: title,
+ top: titleTop,
+ left: titleLeft,
+ right: titleRight,
+ progress: titleProgress,
+ ),
+ if (subtitle != null)
+ Positioned(
+ left: titleLeft,
+ right: titleRight,
+ top:
+ _expandedContentTop +
+ expandedTitleLineHeight +
+ _subtitleGap,
+ child: IgnorePointer(
+ child: ExcludeSemantics(
+ child: Opacity(
+ opacity: 1 - titleProgress,
+ child: Text(
+ subtitle!,
+ maxLines: 1,
+ overflow: TextOverflow.ellipsis,
+ style: TextStyles.mini.copyWith(
+ color: colors.textLight,
+ ),
+ ),
+ ),
+ ),
+ ),
+ ),
+ Positioned(
+ top: 0,
+ left: 0,
+ right: 0,
+ bottom: 0,
+ child: _PinnedHeaderChrome(
+ backButton: backButton,
+ onBack: onBack,
+ actions: actions,
+ actionsTop: actionsTop,
+ chromeHeight: collapsedHeight,
+ showBackButton: showExpandedBackButton,
+ ),
+ ),
+ ],
+ ),
+ ),
+ );
}
- bool get _trailingVisible {
- return switch (variant) {
- TitleBarComponentVariant.home ||
- TitleBarComponentVariant.preserving ||
- TitleBarComponentVariant.partiallyPreserved ||
- TitleBarComponentVariant.preserved ||
- TitleBarComponentVariant.syncing ||
- TitleBarComponentVariant.videoProcessing ||
- TitleBarComponentVariant.settings ||
- TitleBarComponentVariant.titleTopbar ||
- TitleBarComponentVariant.titleTopbarNoIcon =>
- true,
- _ => false,
- };
+ @override
+ bool shouldRebuild(covariant _HeaderAppBarDelegate oldDelegate) {
+ return oldDelegate.title != title ||
+ oldDelegate.subtitle != subtitle ||
+ oldDelegate.leading != leading ||
+ oldDelegate.backButton != backButton ||
+ oldDelegate.onBack != onBack ||
+ oldDelegate.actions != actions ||
+ oldDelegate.expandedHeight != expandedHeight ||
+ oldDelegate.collapsedHeight != collapsedHeight ||
+ oldDelegate.horizontalPadding != horizontalPadding ||
+ oldDelegate.topPadding != topPadding ||
+ oldDelegate.backgroundColor != backgroundColor ||
+ oldDelegate.showExpandedBackButton != showExpandedBackButton ||
+ oldDelegate.expandedTitleLineHeight != expandedTitleLineHeight ||
+ oldDelegate.collapsedTitleLineHeight != collapsedTitleLineHeight ||
+ oldDelegate.subtitleLineHeight != subtitleLineHeight;
}
+}
- String get _effectiveTitle {
- if (title != null) {
- return title!;
- }
- return _usesHeadingStyle ? 'Heading' : 'ente';
- }
+class _PinnedHeaderChrome extends StatelessWidget {
+ const _PinnedHeaderChrome({
+ required this.backButton,
+ required this.onBack,
+ required this.actions,
+ required this.actionsTop,
+ required this.chromeHeight,
+ required this.showBackButton,
+ });
- String get _effectiveStatusText {
- if (statusText != null) {
- return statusText!;
- }
- return switch (variant) {
- TitleBarComponentVariant.preserving => 'Preserving 3 memories',
- TitleBarComponentVariant.partiallyPreserved => '1/3 memories preserved',
- TitleBarComponentVariant.preserved => 'All memories preserved',
- TitleBarComponentVariant.syncing => 'Syncing...',
- TitleBarComponentVariant.videoProcessing => 'Video processing',
- _ => '',
- };
- }
+ final Widget? backButton;
+ final VoidCallback? onBack;
+ final List<Widget> actions;
+ final double actionsTop;
+ final double chromeHeight;
+ final bool showBackButton;
- double get _centerContentHorizontalPadding {
- return _trailingVisible
- ? leadingWidth > trailingWidth
- ? leadingWidth
- : trailingWidth
- : leadingWidth;
+ @override
+ Widget build(BuildContext context) {
+ return Stack(
+ fit: StackFit.expand,
+ children: [
+ if (showBackButton)
+ Align(
+ alignment: Alignment.topLeft,
+ child: Row(
+ mainAxisSize: MainAxisSize.min,
+ children: [
+ _HeaderAppBarBackButton(
+ backButton: backButton,
+ onBack: onBack,
+ height: chromeHeight,
+ ),
+ const SizedBox(width: Spacing.md),
+ ],
+ ),
+ ),
+ if (actions.isNotEmpty)
+ Align(
+ alignment: Alignment.topRight,
+ child: Padding(
+ padding: EdgeInsets.only(top: actionsTop),
+ child: ConstrainedBox(
+ constraints: const BoxConstraints(
+ minHeight: _headerControlSize,
+ ),
+ child: Row(
+ mainAxisSize: MainAxisSize.min,
+ children: [
+ for (var index = 0; index < actions.length; index++) ...[
+ actions[index],
+ if (index != actions.length - 1)
+ const SizedBox(width: _headerControlGap),
+ ],
+ ],
+ ),
+ ),
+ ),
+ ),
+ ],
+ );
}
}
-class _TitleBarSlot extends StatelessWidget {
- const _TitleBarSlot({
- required this.width,
- required this.visible,
- required this.child,
- this.alignment = Alignment.center,
+class _HeaderAppBarBackButton extends StatelessWidget {
+ const _HeaderAppBarBackButton({
+ required this.backButton,
+ required this.onBack,
+ required this.height,
});
- final double width;
- final bool visible;
- final Widget? child;
- final Alignment alignment;
+ final Widget? backButton;
+ final VoidCallback? onBack;
+ final double height;
@override
Widget build(BuildContext context) {
+ final colors = context.componentColors;
+ final tooltip = MaterialLocalizations.of(context).backButtonTooltip;
+
+ if (backButton != null) {
+ return backButton!;
+ }
+
return SizedBox(
- width: width,
+ width: _defaultBackIconSize,
+ height: height,
child: Align(
- alignment: alignment,
- child: Visibility(
- visible: visible && child != null,
- maintainAnimation: true,
- maintainSize: true,
- maintainState: true,
- child: child ?? const SizedBox.square(dimension: 24),
+ alignment: Alignment.centerLeft,
+ child: Semantics(
+ button: true,
+ label: tooltip,
+ child: GestureDetector(
+ behavior: HitTestBehavior.opaque,
+ onTap: onBack ?? () => Navigator.maybePop(context),
+ child: SizedBox.square(
+ dimension: _defaultBackIconSize,
+ child: Icon(
+ Icons.arrow_back,
+ color: colors.textBase,
+ size: _defaultBackIconSize,
+ ),
+ ),
+ ),
),
),
);
}
}
-/// Figma: https://www.figma.com/design/BuBNPPytxlVnqfmCUW0mgz/Ente-Visual-Design?node-id=2513-47854&m=dev
-/// Section: Appbar/header / Title Bar
-/// Specs: Compact mobile title bar with leading slot, centered title, and trailing actions.
-class AppBarComponent extends StatelessWidget implements PreferredSizeWidget {
- const AppBarComponent({
- super.key,
+const _headerControlSize = 38.0;
+const _headerControlGap = Spacing.sm;
+const _defaultBackIconSize = 24.0;
+const _expandedContentTop = 48.0;
+const _subtitleGap = 2.0;
+
+double _collapsedLeadingWidth(Widget? backButton) {
+ return backButton == null ? _defaultBackIconSize : _headerControlSize;
+}
+
+double _centeredTop(double containerHeight, double childHeight) {
+ return ((containerHeight - childHeight) / 2)
+ .clamp(0.0, double.infinity)
+ .toDouble();
+}
+
+double _centerOffset(double containerHeight, double childHeight) {
+ return (containerHeight - childHeight) / 2;
+}
+
+double _maxDouble(double first, double second) {
+ return first > second ? first : second;
+}
+
+double _scaledLineHeight(TextScaler textScaler, TextStyle style) {
+ final fontSize = style.fontSize ?? 14;
+ final height = style.height ?? 1;
+ return textScaler.scale(fontSize) * height;
+}
+
+double _actionsWidth(int actionCount) {
+ return (actionCount * _headerControlSize) +
+ ((actionCount - 1) * _headerControlGap).clamp(0, double.infinity);
+}
+
+class _MovingHeaderTitle extends StatelessWidget {
+ const _MovingHeaderTitle({
required this.title,
- this.leading,
- this.actions = const [],
- this.height = 56,
+ required this.top,
+ required this.left,
+ required this.right,
+ required this.progress,
});
final String title;
- final Widget? leading;
- final List<Widget> actions;
- final double height;
-
- @override
- Size get preferredSize => Size.fromHeight(height);
+ final double top;
+ final double left;
+ final double right;
+ final double progress;
@override
Widget build(BuildContext context) {
- return SafeArea(
- bottom: false,
- child: TitleBarComponent(
- variant: TitleBarComponentVariant.titleTopbar,
- title: title,
- height: height,
- leading: leading,
- trailingWidth: actions.isEmpty ? 44 : actions.length * 44,
- trailing: actions.isEmpty
- ? null
- : Row(
- mainAxisSize: MainAxisSize.min,
- mainAxisAlignment: MainAxisAlignment.end,
- children: [
- for (final action in actions) action,
- ],
- ),
+ final colors = context.componentColors;
+
+ return Positioned(
+ left: left,
+ right: right,
+ top: top,
+ child: IgnorePointer(
+ child: Text(
+ title,
+ maxLines: 1,
+ overflow: TextOverflow.ellipsis,
+ style: TextStyle.lerp(
+ TextStyles.h1Bold,
+ TextStyles.h2,
+ progress,
+ )!.copyWith(color: colors.textBase),
+ ),
),
);
}
diff --git a/mobile/packages/ente_components/lib/components/header_component.dart b/mobile/packages/ente_components/lib/components/header_component.dart
deleted file mode 100644
index 1dc8a92b69..0000000000
--- a/mobile/packages/ente_components/lib/components/header_component.dart
+++ /dev/null
@@ -1,91 +0,0 @@
-import 'package:ente_components/theme/radii.dart';
-import 'package:ente_components/theme/spacing.dart';
-import 'package:ente_components/theme/text_styles.dart';
-import 'package:ente_components/theme/theme.dart';
-import 'package:flutter/material.dart';
-
-/// Figma: https://www.figma.com/design/BuBNPPytxlVnqfmCUW0mgz/Ente-Visual-Design?node-id=2475-5968&m=dev
-/// Section: Appbar/header / HeaderComponent
-/// Specs: 327px design width, optional 36px image slot, optional subtitle, and up to two trailing icon actions.
-class HeaderComponent extends StatelessWidget {
- const HeaderComponent({
- super.key,
- required this.title,
- this.subtitle,
- this.leading,
- this.action,
- this.actions = const [],
- });
-
- final String title;
- final String? subtitle;
- final Widget? leading;
- final Widget? action;
- final List<Widget> actions;
-
- @override
- Widget build(BuildContext context) {
- final colors = context.componentColors;
- final effectiveActions = [
- ...actions,
- if (action != null) action!,
- ];
-
- return ConstrainedBox(
- constraints: const BoxConstraints(minHeight: 40),
- child: Row(
- crossAxisAlignment: CrossAxisAlignment.center,
- children: [
- if (leading != null) ...[
- ClipRRect(
- borderRadius: BorderRadius.circular(Radii.md),
- child: SizedBox.square(
- dimension: 36,
- child: leading,
- ),
- ),
- const SizedBox(width: Spacing.md),
- ],
- Expanded(
- child: Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- mainAxisSize: MainAxisSize.min,
- children: [
- Text(
- title,
- maxLines: 1,
- overflow: TextOverflow.ellipsis,
- style: TextStyles.h1Bold.copyWith(color: colors.textBase),
- ),
- if (subtitle != null) ...[
- const SizedBox(height: 2),
- Text(
- subtitle!,
- maxLines: 1,
- overflow: TextOverflow.ellipsis,
- style: TextStyles.mini.copyWith(color: colors.textLight),
- ),
- ],
- ],
- ),
- ),
- if (effectiveActions.isNotEmpty) ...[
- const SizedBox(width: Spacing.md),
- Row(
- mainAxisSize: MainAxisSize.min,
- children: [
- for (var index = 0;
- index < effectiveActions.length;
- index++) ...[
- effectiveActions[index],
- if (index != effectiveActions.length - 1)
- const SizedBox(width: 6),
- ],
- ],
- ),
- ],
- ],
- ),
- );
- }
-}
diff --git a/mobile/packages/ente_components/lib/ente_components.dart b/mobile/packages/ente_components/lib/ente_components.dart
index b2e752bc77..10e6dfa12b 100644
--- a/mobile/packages/ente_components/lib/ente_components.dart
+++ b/mobile/packages/ente_components/lib/ente_components.dart
@@ -3,7 +3,6 @@ export 'components/avatar_component.dart';
export 'components/buttons/button_component.dart';
export 'components/buttons/icon_button_component.dart';
export 'components/filter_chip_component.dart';
-export 'components/header_component.dart';
export 'components/menu_component.dart';
export 'components/selection_control_components.dart';
export 'components/slider_component.dart';
diff --git a/mobile/packages/ente_components/lib/theme/spacing.dart b/mobile/packages/ente_components/lib/theme/spacing.dart
index 50bab5448b..281b406906 100644
--- a/mobile/packages/ente_components/lib/theme/spacing.dart
+++ b/mobile/packages/ente_components/lib/theme/spacing.dart
@@ -9,4 +9,5 @@ class Spacing {
static const double md = 12;
static const double lg = 16;
static const double xl = 20;
+ static const double xxl = 24;
}
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 54367eeac8..931f4fee47 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
@@ -1,7 +1,6 @@
import 'dart:async';
import 'package:ente_components/components/app_bar_component.dart';
-import 'package:ente_components/components/header_component.dart';
import 'package:ente_components/components/menu_component.dart';
import 'package:ente_components/theme/colors.dart';
import 'package:ente_components/theme/theme.dart';
@@ -13,14 +12,18 @@ Future<void> pumpComponent(
Widget child, {
double width = 420,
double? height,
+ TextScaler textScaler = TextScaler.noScaling,
}) async {
await tester.pumpWidget(
MaterialApp(
theme: ComponentTheme.lightTheme(),
- home: Scaffold(
- body: Align(
- alignment: Alignment.topLeft,
- child: SizedBox(width: width, height: height, child: child),
+ home: MediaQuery(
+ data: MediaQueryData(textScaler: textScaler),
+ child: Scaffold(
+ body: Align(
+ alignment: Alignment.topLeft,
+ child: SizedBox(width: width, height: height, child: child),
+ ),
),
),
),
@@ -311,104 +314,130 @@ void main() {
expect(tester.getSize(find.byType(MenuComponent)).height, greaterThan(60));
});
- testWidgets('TitleBarComponent renders heading and status variants', (
+ testWidgets('HeaderAppBarComponent scrolls without narrow width overflow', (
tester,
) async {
+ var addTapped = false;
+ var leadingTapped = false;
+
await pumpComponent(
tester,
- const TitleBarComponent(
- variant: TitleBarComponentVariant.titleTopbar,
- title: 'Heading',
- leading: Icon(Icons.arrow_back),
- trailing: Icon(Icons.search),
+ CustomScrollView(
+ slivers: [
+ HeaderAppBarComponent(
+ title: 'Menu items',
+ subtitle: 'Scroll to collapse',
+ onBack: () {},
+ leading: GestureDetector(
+ key: const ValueKey('header-leading'),
+ behavior: HitTestBehavior.opaque,
+ onTap: () => leadingTapped = true,
+ child: const ColoredBox(color: Colors.blue),
+ ),
+ actions: [
+ GestureDetector(
+ key: const ValueKey('header-add-action'),
+ behavior: HitTestBehavior.opaque,
+ onTap: () => addTapped = true,
+ child: const Icon(Icons.add),
+ ),
+ const Icon(Icons.dark_mode),
+ ],
+ ),
+ SliverList.builder(
+ itemCount: 24,
+ itemBuilder: (context, index) {
+ return SizedBox(height: 60, child: Text('Item $index'));
+ },
+ ),
+ ],
),
- width: 327,
- height: 42,
+ width: 390,
+ height: 600,
);
- expect(find.text('Heading'), findsOneWidget);
- expect(find.byIcon(Icons.arrow_back), findsOneWidget);
- expect(find.byIcon(Icons.search), findsOneWidget);
- expect(tester.getSize(find.byType(TitleBarComponent)), const Size(327, 42));
+ expect(tester.takeException(), isNull);
+ expect(tester.getCenter(find.byIcon(Icons.arrow_back)).dy, closeTo(28, 1));
+ expect(tester.getSize(find.byIcon(Icons.arrow_back)).width, 24);
+ expect(
+ tester.getSize(find.byKey(const ValueKey('header-leading'))),
+ const Size(38, 38),
+ );
expect(
- tester.getTopRight(find.byIcon(Icons.search)).dx,
- tester.getTopRight(find.byType(TitleBarComponent)).dx,
+ tester.getCenter(find.byKey(const ValueKey('header-leading'))).dy,
+ closeTo(71, 1),
);
+ expect(tester.getCenter(find.byIcon(Icons.add)).dy, closeTo(67, 1));
- await pumpComponent(
- tester,
- const TitleBarComponent(
- variant: TitleBarComponentVariant.preserving,
- leading: Icon(Icons.menu),
- trailing: Icon(Icons.upload),
- statusIcon: Icon(Icons.sync),
- ),
- width: 327,
- height: 42,
+ await tester.tap(find.byKey(const ValueKey('header-leading')));
+ await tester.pump();
+ expect(leadingTapped, isTrue);
+
+ await tester.tap(find.byKey(const ValueKey('header-add-action')));
+ await tester.pump();
+ expect(addTapped, isTrue);
+
+ for (var index = 0; index < 8; index++) {
+ await tester.drag(find.byType(CustomScrollView), const Offset(0, -24));
+ await tester.pump();
+ expect(tester.takeException(), isNull);
+ }
+
+ await tester.drag(find.byType(CustomScrollView), const Offset(0, -180));
+ await tester.pump();
+
+ leadingTapped = false;
+ await tester.tap(
+ find.byKey(const ValueKey('header-leading')),
+ warnIfMissed: false,
);
+ await tester.pump();
- expect(find.text('Preserving 3 memories'), findsOneWidget);
- expect(find.text('ente'), findsNothing);
- expect(find.byIcon(Icons.menu), findsOneWidget);
- expect(find.byIcon(Icons.upload), findsOneWidget);
+ expect(tester.takeException(), isNull);
+ expect(leadingTapped, isFalse);
expect(
- tester.getTopRight(find.byIcon(Icons.upload)).dx,
- tester.getTopRight(find.byType(TitleBarComponent)).dx,
+ tester.getCenter(find.byIcon(Icons.add)).dy,
+ closeTo(tester.getCenter(find.byIcon(Icons.arrow_back)).dy, 1),
);
+ expect(find.text('Menu items'), findsWidgets);
});
- testWidgets(
- 'TitleBarComponent keeps title centered with multiple trailing actions',
- (tester) async {
- await pumpComponent(
- tester,
- const TitleBarComponent(
- variant: TitleBarComponentVariant.titleTopbar,
- title: 'Buttons',
- leadingWidth: 44,
- trailingWidth: 88,
- leading: Icon(Icons.arrow_back),
- trailing: Row(
- mainAxisSize: MainAxisSize.min,
- children: [Icon(Icons.text_fields), Icon(Icons.dark_mode)],
- ),
- ),
- width: 327,
- height: 42,
- );
-
- final titleCenter = tester.getCenter(find.text('Buttons')).dx;
- final barCenter = tester.getCenter(find.byType(TitleBarComponent)).dx;
-
- expect((titleCenter - barCenter).abs(), lessThan(1));
- expect(find.byIcon(Icons.text_fields), findsOneWidget);
- expect(find.byIcon(Icons.dark_mode), findsOneWidget);
- },
- );
-
- testWidgets('HeaderComponent renders image, subtitle, and multiple actions', (
+ testWidgets('HeaderAppBarComponent adapts vertical space for large text', (
tester,
) async {
+ const title = 'A very large header title that should stay constrained';
+
await pumpComponent(
tester,
- const HeaderComponent(
- title: 'Title',
- subtitle: 'Subtitle',
- leading: ColoredBox(key: ValueKey('header-image'), color: Colors.blue),
- actions: [Icon(Icons.add), Icon(Icons.more_horiz)],
+ CustomScrollView(
+ slivers: [
+ const HeaderAppBarComponent(
+ title: title,
+ subtitle: 'Large text subtitle',
+ onBack: null,
+ actions: [Icon(Icons.add)],
+ ),
+ SliverList.builder(
+ itemCount: 12,
+ itemBuilder: (context, index) {
+ return SizedBox(height: 60, child: Text('Scaled item $index'));
+ },
+ ),
+ ],
),
- width: 327,
+ width: 390,
+ height: 600,
+ textScaler: const TextScaler.linear(2.5),
);
- expect(find.text('Title'), findsOneWidget);
- expect(find.text('Subtitle'), findsOneWidget);
- expect(find.byKey(const ValueKey('header-image')), findsOneWidget);
- expect(find.byIcon(Icons.add), findsOneWidget);
- expect(find.byIcon(Icons.more_horiz), findsOneWidget);
+ expect(tester.takeException(), isNull);
+ expect(find.text(title), findsOneWidget);
+ expect(tester.getBottomLeft(find.text(title)).dy, lessThanOrEqualTo(118));
- final imageSize = tester.getSize(
- find.byKey(const ValueKey('header-image')),
- );
- expect(imageSize, const Size(36, 36));
+ await tester.drag(find.byType(CustomScrollView), const Offset(0, -240));
+ await tester.pump();
+
+ expect(tester.takeException(), isNull);
+ expect(find.text(title), findsOneWidget);
});
}
diff --git a/mobile/packages/ente_components/test/theme/theme_tokens_test.dart b/mobile/packages/ente_components/test/theme/theme_tokens_test.dart
index 81f1f56bdc..e7ebcfc73d 100644
--- a/mobile/packages/ente_components/test/theme/theme_tokens_test.dart
+++ b/mobile/packages/ente_components/test/theme/theme_tokens_test.dart
@@ -7,7 +7,8 @@ void main() {
test("expose expected spacing, radii, motion, and shadow values", () {
expect(2, 2);
expect(Spacing.sm, 8);
- expect(Spacing.xl, 24);
+ expect(Spacing.xl, 20);
+ expect(Spacing.xxl, 24);
expect(40, 40);
expect(Radii.xs, 4);