Skip to content

armgit / ente

Public Imported from GitHub
0

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

Collapse search tab header while searching

ashilkn424becb65afc
diff --git a/mobile/apps/photos/changes/search-tab-collapsed-header.md b/mobile/apps/photos/changes/search-tab-collapsed-header.md
new file mode 100644
index 0000000000..c5dd962dac
--- /dev/null
+++ b/mobile/apps/photos/changes/search-tab-collapsed-header.md
@@ -0,0 +1 @@
+- Made the search tab header collapse quickly while searching.
diff --git a/mobile/apps/photos/lib/ui/viewer/search/search_widget.dart b/mobile/apps/photos/lib/ui/viewer/search/search_widget.dart
index fac4016884..dfb1b2398e 100644
--- a/mobile/apps/photos/lib/ui/viewer/search/search_widget.dart
+++ b/mobile/apps/photos/lib/ui/viewer/search/search_widget.dart
@@ -16,9 +16,14 @@ import "package:photos/ui/viewer/search/search_suffix_icon_widget.dart";
import "package:photos/utils/pending_translation.dart";
class SearchWidget extends StatefulWidget {
- const SearchWidget({super.key, this.shouldConsumeBackNotifier});
+ const SearchWidget({
+ super.key,
+ this.shouldConsumeBackNotifier,
+ this.onActiveChanged,
+ });
final ValueNotifier<bool>? shouldConsumeBackNotifier;
+ final ValueChanged<bool>? onActiveChanged;
@override
State<SearchWidget> createState() => SearchWidgetState();
@@ -41,6 +46,7 @@ class SearchWidgetState extends State<SearchWidget> {
StreamSubscription<TabDoubleTapEvent>? _tabDoubleTapEvent;
TextEditingController textController = TextEditingController();
String? _lastRequestedQuery;
+ bool? _lastReportedActive;
late final StreamSubscription<ClearAndUnfocusSearchBar>
_clearAndUnfocusSearchBar;
late final Logger _logger = Logger("SearchWidgetState");
@@ -51,6 +57,7 @@ class SearchWidgetState extends State<SearchWidget> {
focusNode = FocusNode();
focusNode.addListener(() {
_syncSearchBackNotifier();
+ _notifyActiveChanged();
if (mounted) {
setState(() {});
}
@@ -85,6 +92,7 @@ class SearchWidgetState extends State<SearchWidget> {
textController.clear();
focusNode.unfocus();
_syncSearchBackNotifier(false);
+ _notifyActiveChanged();
});
}
@@ -127,6 +135,7 @@ class SearchWidgetState extends State<SearchWidget> {
Future<void> textControllerListener() async {
_syncSearchBackNotifier();
+ _notifyActiveChanged();
final nextQuery = textController.text.trim();
if (nextQuery == _lastRequestedQuery) {
return;
@@ -145,6 +154,15 @@ class SearchWidgetState extends State<SearchWidget> {
});
}
+ void _notifyActiveChanged() {
+ final active = focusNode.hasFocus || textController.text.trim().isNotEmpty;
+ if (_lastReportedActive == active) {
+ return;
+ }
+ _lastReportedActive = active;
+ widget.onActiveChanged?.call(active);
+ }
+
@override
Widget build(BuildContext context) {
final componentColors = context.componentColors;
diff --git a/mobile/apps/photos/lib/ui/viewer/search_tab/search_tab.dart b/mobile/apps/photos/lib/ui/viewer/search_tab/search_tab.dart
index ab167743f0..5cec503d63 100644
--- a/mobile/apps/photos/lib/ui/viewer/search_tab/search_tab.dart
+++ b/mobile/apps/photos/lib/ui/viewer/search_tab/search_tab.dart
@@ -1,3 +1,5 @@
+import "dart:ui" show lerpDouble;
+
import "package:ente_components/theme/text_styles.dart";
import "package:fade_indexed_stack/fade_indexed_stack.dart";
import "package:flutter/foundation.dart";
@@ -40,6 +42,7 @@ class SearchTab extends StatefulWidget {
class _SearchTabState extends State<SearchTab> {
late int index;
final indexOfStackNotifier = IndexOfStackNotifier();
+ bool _isSearchHeaderCollapsed = SearchWidgetState.query.trim().isNotEmpty;
@override
void initState() {
@@ -54,6 +57,15 @@ class _SearchTabState extends State<SearchTab> {
});
}
+ void _setSearchHeaderCollapsed(bool isCollapsed) {
+ if (_isSearchHeaderCollapsed == isCollapsed) {
+ return;
+ }
+ setState(() {
+ _isSearchHeaderCollapsed = isCollapsed;
+ });
+ }
+
@override
void dispose() {
indexOfStackNotifier.removeListener(indexNotifierListener);
@@ -71,28 +83,12 @@ class _SearchTabState extends State<SearchTab> {
: colorScheme.backgroundColour;
return Column(
children: [
- ColoredBox(
- color: headerColor,
- child: SafeArea(
- bottom: false,
- child: Padding(
- padding: const EdgeInsets.fromLTRB(15, 12, 15, 8),
- child: Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- Text(
- AppLocalizations.of(context).search,
- style: TextStyles.display1.copyWith(
- color: colorScheme.textBase,
- ),
- ),
- const SizedBox(height: 16),
- SearchWidget(
- shouldConsumeBackNotifier: widget.shouldConsumeBackNotifier,
- ),
- ],
- ),
- ),
+ _SearchHeader(
+ backgroundColor: headerColor,
+ isCollapsed: _isSearchHeaderCollapsed,
+ searchField: SearchWidget(
+ shouldConsumeBackNotifier: widget.shouldConsumeBackNotifier,
+ onActiveChanged: _setSearchHeaderCollapsed,
),
),
Expanded(
@@ -114,6 +110,89 @@ class _SearchTabState extends State<SearchTab> {
}
}
+class _SearchHeader extends StatelessWidget {
+ const _SearchHeader({
+ required this.backgroundColor,
+ required this.isCollapsed,
+ required this.searchField,
+ });
+
+ static const _horizontalPadding = 15.0;
+ static const _expandedTopPadding = 12.0;
+ static const _collapsedTopPadding = 8.0;
+ static const _bottomPadding = 8.0;
+ static const _expandedTitleGap = 16.0;
+ static const _transitionDuration = Duration(milliseconds: 150);
+
+ final Color backgroundColor;
+ final bool isCollapsed;
+ final Widget searchField;
+
+ @override
+ Widget build(BuildContext context) {
+ final colorScheme = getEnteColorScheme(context);
+ final titleStyle = TextStyles.display1.copyWith(
+ color: colorScheme.textBase,
+ );
+ return ColoredBox(
+ color: backgroundColor,
+ child: SafeArea(
+ bottom: false,
+ child: TweenAnimationBuilder<double>(
+ tween: Tween(end: isCollapsed ? 1 : 0),
+ duration: _transitionDuration,
+ curve: Curves.easeOut,
+ child: searchField,
+ builder: (context, progress, child) {
+ final topPadding = lerpDouble(
+ _expandedTopPadding,
+ _collapsedTopPadding,
+ progress,
+ )!;
+ return Padding(
+ padding: EdgeInsets.fromLTRB(
+ _horizontalPadding,
+ topPadding,
+ _horizontalPadding,
+ _bottomPadding,
+ ),
+ child: Column(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ _SearchHeaderTitle(progress: progress, style: titleStyle),
+ SizedBox(height: _expandedTitleGap * (1 - progress)),
+ child!,
+ ],
+ ),
+ );
+ },
+ ),
+ ),
+ );
+ }
+}
+
+class _SearchHeaderTitle extends StatelessWidget {
+ const _SearchHeaderTitle({required this.progress, required this.style});
+
+ final double progress;
+ final TextStyle style;
+
+ @override
+ Widget build(BuildContext context) {
+ return ClipRect(
+ child: Align(
+ alignment: Alignment.topLeft,
+ heightFactor: (1 - (progress * 1.35)).clamp(0.0, 1.0),
+ child: Opacity(
+ opacity: progress < 0.08 ? 1 : 0,
+ child: Text(AppLocalizations.of(context).search, style: style),
+ ),
+ ),
+ );
+ }
+}
+
class AllSearchSections extends StatefulWidget {
const AllSearchSections({super.key});