Skip to content

armgit / ente

Public Imported from GitHub
0

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

Support searchable app bar titles

ashilknd229793ec9bb
diff --git a/mobile/apps/photos/lib/ui/viewer/search/result/people_section_all_page.dart b/mobile/apps/photos/lib/ui/viewer/search/result/people_section_all_page.dart
index 380b943f3e..cc845210c5 100644
--- a/mobile/apps/photos/lib/ui/viewer/search/result/people_section_all_page.dart
+++ b/mobile/apps/photos/lib/ui/viewer/search/result/people_section_all_page.dart
@@ -331,6 +331,10 @@ class PeopleSectionAllWidget extends StatefulWidget {
}
class _PeopleSectionAllWidgetState extends State<PeopleSectionAllWidget> {
+ static const _titleActionSize = 36.0;
+ static const _searchTitleHeight = 52.0;
+ static const _searchTransitionDuration = Duration(milliseconds: 240);
+
late Future<List<GenericSearchResult>> sectionData;
List<GenericSearchResult> normalFaces = [];
List<GenericSearchResult> extraFaces = [];
@@ -651,9 +655,6 @@ class _PeopleSectionAllWidgetState extends State<PeopleSectionAllWidget> {
future: sectionData,
builder: (context, snapshot) {
final slivers = <Widget>[];
- if (widget.showSearchBar && _isSearchBarVisible) {
- slivers.add(_buildSearchFieldSliver(context, horizontalEdgePadding));
- }
if (!_isLoaded &&
snapshot.connectionState == ConnectionState.waiting &&
_isInitialLoad) {
@@ -870,16 +871,93 @@ class _PeopleSectionAllWidgetState extends State<PeopleSectionAllWidget> {
return AppBarComponent(
title: SectionType.face.sectionTitle(context),
physics: const BouncingScrollPhysics(),
- actions: _isSearchBarVisible
- ? const []
- : [
- _buildSearchAction(),
- _buildSortMenu(context, textTheme, colorScheme),
- ],
+ titleBuilder: (context, state) =>
+ _buildTitle(context, state, textTheme, colorScheme),
+ titleBuilderHeight: _searchTitleHeight,
slivers: slivers,
);
}
+ Widget _buildTitle(
+ BuildContext context,
+ HeaderAppBarTitleState state,
+ EnteTextTheme textTheme,
+ EnteColorScheme colorScheme,
+ ) {
+ return AnimatedSwitcher(
+ duration: _searchTransitionDuration,
+ switchInCurve: Curves.easeOutCubic,
+ switchOutCurve: Curves.easeInCubic,
+ layoutBuilder: (currentChild, previousChildren) => Stack(
+ alignment: Alignment.centerLeft,
+ clipBehavior: Clip.none,
+ children: [...previousChildren, if (currentChild != null) currentChild],
+ ),
+ transitionBuilder: (child, animation) {
+ final curvedAnimation = CurvedAnimation(
+ parent: animation,
+ curve: Curves.easeOutCubic,
+ reverseCurve: Curves.easeInCubic,
+ );
+ final beginOffset = child.key == const ValueKey("people_search_field")
+ ? const Offset(0.035, 0)
+ : const Offset(-0.035, 0);
+ return FadeTransition(
+ opacity: curvedAnimation,
+ child: SlideTransition(
+ position: Tween<Offset>(
+ begin: beginOffset,
+ end: Offset.zero,
+ ).animate(curvedAnimation),
+ child: child,
+ ),
+ );
+ },
+ child: _isSearchBarVisible
+ ? KeyedSubtree(
+ key: const ValueKey("people_search_field"),
+ child: _buildSearchField(context),
+ )
+ : KeyedSubtree(
+ key: const ValueKey("people_title_row"),
+ child: _buildTitleRow(state, textTheme, colorScheme),
+ ),
+ );
+ }
+
+ Widget _buildTitleRow(
+ HeaderAppBarTitleState state,
+ EnteTextTheme textTheme,
+ EnteColorScheme colorScheme,
+ ) {
+ return SizedBox(
+ height: state.height,
+ child: Row(
+ crossAxisAlignment: CrossAxisAlignment.center,
+ children: [
+ Expanded(
+ child: Text(
+ state.title,
+ maxLines: 1,
+ overflow: TextOverflow.ellipsis,
+ style: state.textStyle,
+ ),
+ ),
+ const SizedBox(width: Spacing.md),
+ SizedBox.square(
+ dimension: _titleActionSize,
+ child: _buildSearchAction(),
+ ),
+ const SizedBox(width: Spacing.sm),
+ SizedBox.square(
+ dimension: _titleActionSize,
+ child: _buildSortMenu(context, textTheme, colorScheme),
+ ),
+ ],
+ ),
+ );
+ }
+
Widget _buildSearchAction() {
return IconButtonComponent(
variant: IconButtonComponentVariant.primary,
@@ -889,45 +967,29 @@ class _PeopleSectionAllWidgetState extends State<PeopleSectionAllWidget> {
);
}
- Widget _buildSearchFieldSliver(
- BuildContext context,
- double horizontalEdgePadding,
- ) {
+ Widget _buildSearchField(BuildContext context) {
final colors = context.componentColors;
- return SliverPadding(
- padding: EdgeInsets.fromLTRB(
- horizontalEdgePadding,
- 0,
- horizontalEdgePadding,
- 4,
+ return TextInputComponent(
+ controller: _searchController,
+ focusNode: _searchFocusNode,
+ hintText: AppLocalizations.of(context).search,
+ autofocus: true,
+ shouldUnfocusOnClearOrSubmit: true,
+ prefix: HugeIcon(
+ icon: HugeIcons.strokeRoundedSearch01,
+ size: 18,
+ color: colors.textLight,
),
- sliver: SliverToBoxAdapter(
- child: TextInputComponent(
- controller: _searchController,
- focusNode: _searchFocusNode,
- hintText: AppLocalizations.of(context).search,
- onChanged: _updateSearchQuery,
- prefix: HugeIcon(
- icon: HugeIcons.strokeRoundedSearch01,
- size: 20,
- color: colors.textLight,
- strokeWidth: 1.6,
- ),
- suffix: GestureDetector(
- behavior: HitTestBehavior.opaque,
- onTap: _closeSearch,
- child: SizedBox.square(
- dimension: IconSizes.medium,
- child: HugeIcon(
- icon: HugeIcons.strokeRoundedCancel01,
- size: 18,
- color: colors.textLight,
- strokeWidth: 1.6,
- ),
- ),
- ),
+ suffix: GestureDetector(
+ behavior: HitTestBehavior.opaque,
+ onTap: _closeSearch,
+ child: HugeIcon(
+ icon: HugeIcons.strokeRoundedCancel01,
+ size: 18,
+ color: colors.textLight,
),
),
+ onChanged: _updateSearchQuery,
);
}
diff --git a/mobile/apps/photos/lib/ui/viewer/search/result/search_section_all_page.dart b/mobile/apps/photos/lib/ui/viewer/search/result/search_section_all_page.dart
index 16cf0af85d..2c6e7cc0a3 100644
--- a/mobile/apps/photos/lib/ui/viewer/search/result/search_section_all_page.dart
+++ b/mobile/apps/photos/lib/ui/viewer/search/result/search_section_all_page.dart
@@ -34,6 +34,10 @@ class SearchSectionAllPage extends StatefulWidget {
}
class _SearchSectionAllPageState extends State<SearchSectionAllPage> {
+ static const _titleActionSize = 36.0;
+ static const _searchTitleHeight = 52.0;
+ static const _searchTransitionDuration = Duration(milliseconds: 240);
+
late Future<List<SearchResult>> sectionData;
final streamSubscriptions = <StreamSubscription>[];
final _searchController = TextEditingController();
@@ -126,9 +130,6 @@ class _SearchSectionAllPageState extends State<SearchSectionAllPage> {
future: sectionData,
builder: (context, snapshot) {
final slivers = <Widget>[];
- if (_isSearchBarVisible) {
- slivers.add(_buildSearchFieldSliver(context));
- }
if (!snapshot.hasData) {
slivers.add(
@@ -259,11 +260,78 @@ class _SearchSectionAllPageState extends State<SearchSectionAllPage> {
title: widget.sectionType.sectionTitle(context),
physics: const BouncingScrollPhysics(),
cacheExtent: cacheExtent,
- actions: _isSearchBarVisible ? const [] : [_buildSearchAction()],
+ titleBuilder: _buildTitle,
+ titleBuilderHeight: _searchTitleHeight,
slivers: slivers,
);
}
+ Widget _buildTitle(BuildContext context, HeaderAppBarTitleState state) {
+ return AnimatedSwitcher(
+ duration: _searchTransitionDuration,
+ switchInCurve: Curves.easeOutCubic,
+ switchOutCurve: Curves.easeInCubic,
+ layoutBuilder: (currentChild, previousChildren) => Stack(
+ alignment: Alignment.centerLeft,
+ clipBehavior: Clip.none,
+ children: [...previousChildren, if (currentChild != null) currentChild],
+ ),
+ transitionBuilder: (child, animation) {
+ final curvedAnimation = CurvedAnimation(
+ parent: animation,
+ curve: Curves.easeOutCubic,
+ reverseCurve: Curves.easeInCubic,
+ );
+ final beginOffset = child.key == const ValueKey("search_field")
+ ? const Offset(0.035, 0)
+ : const Offset(-0.035, 0);
+ return FadeTransition(
+ opacity: curvedAnimation,
+ child: SlideTransition(
+ position: Tween<Offset>(
+ begin: beginOffset,
+ end: Offset.zero,
+ ).animate(curvedAnimation),
+ child: child,
+ ),
+ );
+ },
+ child: _isSearchBarVisible
+ ? KeyedSubtree(
+ key: const ValueKey("search_field"),
+ child: _buildSearchField(context),
+ )
+ : KeyedSubtree(
+ key: const ValueKey("title_row"),
+ child: _buildTitleRow(state),
+ ),
+ );
+ }
+
+ Widget _buildTitleRow(HeaderAppBarTitleState state) {
+ return SizedBox(
+ height: state.height,
+ child: Row(
+ crossAxisAlignment: CrossAxisAlignment.center,
+ children: [
+ Expanded(
+ child: Text(
+ state.title,
+ maxLines: 1,
+ overflow: TextOverflow.ellipsis,
+ style: state.textStyle,
+ ),
+ ),
+ const SizedBox(width: Spacing.md),
+ SizedBox.square(
+ dimension: _titleActionSize,
+ child: _buildSearchAction(),
+ ),
+ ],
+ ),
+ );
+ }
+
Widget _buildSearchAction() {
return IconButtonComponent(
variant: IconButtonComponentVariant.primary,
@@ -273,37 +341,29 @@ class _SearchSectionAllPageState extends State<SearchSectionAllPage> {
);
}
- Widget _buildSearchFieldSliver(BuildContext context) {
+ Widget _buildSearchField(BuildContext context) {
final colors = context.componentColors;
- return SliverPadding(
- padding: const EdgeInsets.fromLTRB(16, 0, 16, 4),
- sliver: SliverToBoxAdapter(
- child: TextInputComponent(
- controller: _searchController,
- focusNode: _searchFocusNode,
- hintText: AppLocalizations.of(context).search,
- onChanged: _updateSearchQuery,
- prefix: HugeIcon(
- icon: HugeIcons.strokeRoundedSearch01,
- size: 20,
- color: colors.textLight,
- strokeWidth: 1.6,
- ),
- suffix: GestureDetector(
- behavior: HitTestBehavior.opaque,
- onTap: _closeSearch,
- child: SizedBox.square(
- dimension: IconSizes.medium,
- child: HugeIcon(
- icon: HugeIcons.strokeRoundedCancel01,
- size: 18,
- color: colors.textLight,
- strokeWidth: 1.6,
- ),
- ),
- ),
+ return TextInputComponent(
+ controller: _searchController,
+ focusNode: _searchFocusNode,
+ hintText: AppLocalizations.of(context).search,
+ autofocus: true,
+ shouldUnfocusOnClearOrSubmit: true,
+ prefix: HugeIcon(
+ icon: HugeIcons.strokeRoundedSearch01,
+ size: 18,
+ color: colors.textLight,
+ ),
+ suffix: GestureDetector(
+ behavior: HitTestBehavior.opaque,
+ onTap: _closeSearch,
+ child: HugeIcon(
+ icon: HugeIcons.strokeRoundedCancel01,
+ size: 18,
+ color: colors.textLight,
),
),
+ onChanged: _updateSearchQuery,
);
}
}
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 32f4c1bcc0..e20380b9ab 100644
--- a/mobile/packages/ente_components/lib/components/app_bar_component.dart
+++ b/mobile/packages/ente_components/lib/components/app_bar_component.dart
@@ -8,6 +8,21 @@ import 'package:ente_components/theme/text_styles.dart';
import 'package:ente_components/theme/theme.dart';
import 'package:flutter/material.dart';
+typedef HeaderAppBarTitleBuilder =
+ Widget Function(BuildContext context, HeaderAppBarTitleState state);
+
+class HeaderAppBarTitleState {
+ const HeaderAppBarTitleState({
+ required this.title,
+ required this.textStyle,
+ required this.height,
+ });
+
+ final String title;
+ final TextStyle textStyle;
+ final double height;
+}
+
/// Figma: https://www.figma.com/design/BuBNPPytxlVnqfmCUW0mgz/Ente-Visual-Design?node-id=11439-5036&m=dev
/// Section: Appbar/header / Header v2
/// Specs: Scroll view with a pinned header app bar that animates between
@@ -20,6 +35,8 @@ class AppBarComponent extends StatefulWidget {
super.key,
required this.title,
required this.slivers,
+ this.titleBuilder,
+ this.titleBuilderHeight,
this.onTitleTap,
this.onTitleDoubleTap,
this.onTitleLongPress,
@@ -39,6 +56,8 @@ class AppBarComponent extends StatefulWidget {
});
final String title;
+ final HeaderAppBarTitleBuilder? titleBuilder;
+ final double? titleBuilderHeight;
final VoidCallback? onTitleTap;
final VoidCallback? onTitleDoubleTap;
final VoidCallback? onTitleLongPress;
@@ -190,6 +209,7 @@ class _AppBarComponentState extends State<AppBarComponent> {
subtitle: widget.subtitle,
expandedHeight: widget.expandedHeight,
collapsedHeight: widget.collapsedHeight,
+ titleBuilderHeight: widget.titleBuilderHeight,
);
_collapseExtent = metrics.collapseExtent;
if (!_controller.hasClients ||
@@ -206,6 +226,8 @@ class _AppBarComponentState extends State<AppBarComponent> {
slivers: [
SliverAppBarComponent(
title: widget.title,
+ titleBuilder: widget.titleBuilder,
+ titleBuilderHeight: widget.titleBuilderHeight,
onTitleTap: widget.onTitleTap,
onTitleDoubleTap: widget.onTitleDoubleTap,
onTitleLongPress: widget.onTitleLongPress,
@@ -258,6 +280,8 @@ class SliverAppBarComponent extends StatelessWidget {
const SliverAppBarComponent({
super.key,
required this.title,
+ this.titleBuilder,
+ this.titleBuilderHeight,
this.onTitleTap,
this.onTitleDoubleTap,
this.onTitleLongPress,
@@ -274,6 +298,8 @@ class SliverAppBarComponent extends StatelessWidget {
});
final String title;
+ final HeaderAppBarTitleBuilder? titleBuilder;
+ final double? titleBuilderHeight;
final VoidCallback? onTitleTap;
final VoidCallback? onTitleDoubleTap;
final VoidCallback? onTitleLongPress;
@@ -296,12 +322,15 @@ class SliverAppBarComponent extends StatelessWidget {
subtitle: subtitle,
expandedHeight: expandedHeight,
collapsedHeight: collapsedHeight,
+ titleBuilderHeight: titleBuilderHeight,
);
return SliverPersistentHeader(
pinned: true,
delegate: _HeaderAppBarDelegate(
title: title,
+ titleBuilder: titleBuilder,
+ titleBuilderHeight: titleBuilderHeight,
onTitleTap: onTitleTap,
onTitleDoubleTap: onTitleDoubleTap,
onTitleLongPress: onTitleLongPress,
@@ -328,6 +357,8 @@ class SliverAppBarComponent extends StatelessWidget {
class _HeaderAppBarDelegate extends SliverPersistentHeaderDelegate {
const _HeaderAppBarDelegate({
required this.title,
+ required this.titleBuilder,
+ required this.titleBuilderHeight,
required this.onTitleTap,
required this.onTitleDoubleTap,
required this.onTitleLongPress,
@@ -349,6 +380,8 @@ class _HeaderAppBarDelegate extends SliverPersistentHeaderDelegate {
});
final String title;
+ final HeaderAppBarTitleBuilder? titleBuilder;
+ final double? titleBuilderHeight;
final VoidCallback? onTitleTap;
final VoidCallback? onTitleDoubleTap;
final VoidCallback? onTitleLongPress;
@@ -385,16 +418,21 @@ class _HeaderAppBarDelegate extends SliverPersistentHeaderDelegate {
? 1.0
: (shrinkOffset / scrollRange).clamp(0.0, 1.0);
final titleProgress = Curves.easeInOut.transform(progress);
+ final expandedTitleHeight = titleBuilderHeight ?? expandedTitleLineHeight;
+ final collapsedTitleHeight = titleBuilderHeight ?? collapsedTitleLineHeight;
+ final titleLayoutHeight = titleBuilderHeight == null
+ ? lerpDouble(expandedTitleHeight, collapsedTitleHeight, titleProgress)!
+ : titleBuilderHeight!;
final collapsedControlTop = _centeredTop(
collapsedHeight,
_headerControlSize,
);
final collapsedTitleTop = _centeredTop(
collapsedHeight,
- collapsedTitleLineHeight,
+ collapsedTitleHeight,
);
final expandedTextBlockHeight =
- expandedTitleLineHeight +
+ expandedTitleHeight +
(subtitle == null ? 0 : _subtitleGap + subtitleLineHeight);
final leadingTop =
_expandedContentTop +
@@ -455,6 +493,7 @@ class _HeaderAppBarDelegate extends SliverPersistentHeaderDelegate {
),
_MovingHeaderTitle(
title: title,
+ titleBuilder: titleBuilder,
onTap: onTitleTap,
onDoubleTap: onTitleDoubleTap,
onLongPress: onTitleLongPress,
@@ -462,15 +501,13 @@ class _HeaderAppBarDelegate extends SliverPersistentHeaderDelegate {
left: titleLeft,
right: titleRight,
progress: titleProgress,
+ height: titleLayoutHeight,
),
if (subtitle != null)
Positioned(
left: titleLeft,
right: titleRight,
- top:
- _expandedContentTop +
- expandedTitleLineHeight +
- _subtitleGap,
+ top: _expandedContentTop + expandedTitleHeight + _subtitleGap,
child: IgnorePointer(
child: ExcludeSemantics(
child: Opacity(
@@ -510,6 +547,9 @@ class _HeaderAppBarDelegate extends SliverPersistentHeaderDelegate {
@override
bool shouldRebuild(covariant _HeaderAppBarDelegate oldDelegate) {
return oldDelegate.title != title ||
+ titleBuilder != null ||
+ oldDelegate.titleBuilder != null ||
+ oldDelegate.titleBuilderHeight != titleBuilderHeight ||
oldDelegate.onTitleTap != onTitleTap ||
oldDelegate.onTitleDoubleTap != onTitleDoubleTap ||
oldDelegate.onTitleLongPress != onTitleLongPress ||
@@ -679,6 +719,7 @@ _HeaderAppBarMetrics _resolveHeaderAppBarMetrics(
required String? subtitle,
required double? expandedHeight,
required double collapsedHeight,
+ required double? titleBuilderHeight,
}) {
final textScaler = MediaQuery.textScalerOf(context);
final expandedTitleLineHeight = _scaledLineHeight(
@@ -695,7 +736,10 @@ _HeaderAppBarMetrics _resolveHeaderAppBarMetrics(
: _subtitleExpandedHeight;
final effectiveCollapsedHeight = _maxDouble(
collapsedHeight,
- _maxDouble(_headerControlSize, collapsedTitleLineHeight),
+ _maxDouble(
+ _headerControlSize,
+ _maxDouble(collapsedTitleLineHeight, titleBuilderHeight ?? 0),
+ ),
);
final expandedTextBlockHeight =
expandedTitleLineHeight +
@@ -748,6 +792,7 @@ double _actionsWidth(int actionCount) {
class _MovingHeaderTitle extends StatelessWidget {
const _MovingHeaderTitle({
required this.title,
+ required this.titleBuilder,
required this.onTap,
required this.onDoubleTap,
required this.onLongPress,
@@ -755,9 +800,11 @@ class _MovingHeaderTitle extends StatelessWidget {
required this.left,
required this.right,
required this.progress,
+ required this.height,
});
final String title;
+ final HeaderAppBarTitleBuilder? titleBuilder;
final VoidCallback? onTap;
final VoidCallback? onDoubleTap;
final VoidCallback? onLongPress;
@@ -765,19 +812,39 @@ class _MovingHeaderTitle extends StatelessWidget {
final double left;
final double right;
final double progress;
+ final double height;
@override
Widget build(BuildContext context) {
final colors = context.componentColors;
+ final textStyle = TextStyle.lerp(
+ TextStyles.display2,
+ TextStyles.display3,
+ progress,
+ )!.copyWith(color: colors.textBase);
+
+ final customTitleBuilder = titleBuilder;
+ if (customTitleBuilder != null) {
+ return Positioned(
+ left: left,
+ right: right,
+ top: top,
+ child: customTitleBuilder(
+ context,
+ HeaderAppBarTitleState(
+ title: title,
+ textStyle: textStyle,
+ height: height,
+ ),
+ ),
+ );
+ }
+
final titleText = Text(
title,
maxLines: 1,
overflow: TextOverflow.ellipsis,
- style: TextStyle.lerp(
- TextStyles.display2,
- TextStyles.display3,
- progress,
- )!.copyWith(color: colors.textBase),
+ style: textStyle,
);
return Positioned(