Skip to content

armgit / ente

Public Imported from GitHub
0

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

animate search tab to just above home bottom nav bar when swiping to search tab

ashilkn5345850b1ab9
diff --git a/lib/ui/search_tab.dart b/lib/ui/search_tab.dart
index 1099ec12aa..3e5208bf71 100644
--- a/lib/ui/search_tab.dart
+++ b/lib/ui/search_tab.dart
@@ -80,29 +80,33 @@ class _AllSearchSectionsState extends State<AllSearchSections> {
searchTypes.remove(SectionType.face);
searchTypes.remove(SectionType.content);
return Expanded(
- child: FutureBuilder(
- future: allSectionsExamples,
- builder: (context, snapshot) {
- if (snapshot.hasData) {
- return ListView.builder(
- padding: const EdgeInsets.only(bottom: 120),
- physics: const BouncingScrollPhysics(),
- itemCount: searchTypes.length,
- itemBuilder: (context, index) {
- return SearchSection(
- sectionType: searchTypes[index],
- examples: snapshot.data!.elementAt(index),
- limit: _limit,
+ child: Stack(
+ children: [
+ FutureBuilder(
+ future: allSectionsExamples,
+ builder: (context, snapshot) {
+ if (snapshot.hasData) {
+ return ListView.builder(
+ padding: const EdgeInsets.only(bottom: 180),
+ physics: const BouncingScrollPhysics(),
+ itemCount: searchTypes.length,
+ itemBuilder: (context, index) {
+ return SearchSection(
+ sectionType: searchTypes[index],
+ examples: snapshot.data!.elementAt(index),
+ limit: _limit,
+ );
+ },
);
- },
- );
- } else if (snapshot.hasError) {
- //todo: Show something went wrong here
- return const EnteLoadingWidget();
- } else {
- return const EnteLoadingWidget();
- }
- },
+ } else if (snapshot.hasError) {
+ //todo: Show something went wrong here
+ return const EnteLoadingWidget();
+ } else {
+ return const EnteLoadingWidget();
+ }
+ },
+ ),
+ ],
),
);
}
diff --git a/lib/ui/tabs/home_widget.dart b/lib/ui/tabs/home_widget.dart
index 0f06c21a56..b2e2463ca5 100644
--- a/lib/ui/tabs/home_widget.dart
+++ b/lib/ui/tabs/home_widget.dart
@@ -4,6 +4,7 @@ import 'dart:io';
import 'package:flutter/material.dart';
import 'package:flutter/scheduler.dart';
import 'package:flutter/services.dart';
+import "package:flutter_animate/flutter_animate.dart";
import "package:flutter_local_notifications/flutter_local_notifications.dart";
import 'package:logging/logging.dart';
import 'package:media_extension/media_extension_action_types.dart';
@@ -52,6 +53,7 @@ import "package:photos/ui/settings_page.dart";
import "package:photos/ui/tabs/shared_collections_tab.dart";
import "package:photos/ui/tabs/user_collections_tab.dart";
import "package:photos/ui/viewer/gallery/collection_page.dart";
+import "package:photos/ui/viewer/search/search_widget_new.dart";
import 'package:photos/utils/dialog_util.dart';
import "package:photos/utils/navigation_util.dart";
import 'package:receive_sharing_intent/receive_sharing_intent.dart';
@@ -89,6 +91,7 @@ class _HomeWidgetState extends State<HomeWidget> {
List<SharedMediaFile>? _sharedFiles;
bool _shouldRenderCreateCollectionSheet = false;
bool _showShowBackupHook = false;
+ final isOnSearchTabNotifier = ValueNotifier<bool>(false);
late StreamSubscription<TabChangedEvent> _tabChangedEventSubscription;
late StreamSubscription<SubscriptionPurchasedEvent>
@@ -107,6 +110,11 @@ class _HomeWidgetState extends State<HomeWidget> {
_tabChangedEventSubscription =
Bus.instance.on<TabChangedEvent>().listen((event) {
if (event.source != TabChangedEventSource.pageView) {
+ if (event.selectedIndex == 3) {
+ isOnSearchTabNotifier.value = true;
+ } else {
+ isOnSearchTabNotifier.value = false;
+ }
debugPrint(
"TabChange going from $_selectedTabIndex to ${event.selectedIndex} souce: ${event.source}",
);
@@ -348,6 +356,7 @@ class _HomeWidgetState extends State<HomeWidget> {
}
Widget _getBody(BuildContext context) {
+ final colorScheme = getEnteColorScheme(context);
if (!Configuration.instance.hasConfiguredAccount()) {
_closeDrawerIfOpen(context);
return const LandingPageWidget();
@@ -415,9 +424,62 @@ class _HomeWidgetState extends State<HomeWidget> {
),
Align(
alignment: Alignment.bottomCenter,
- child: HomeBottomNavigationBar(
- _selectedFiles,
- selectedTabIndex: _selectedTabIndex,
+ child: ValueListenableBuilder(
+ valueListenable: isOnSearchTabNotifier,
+ builder: (context, value, child) {
+ return AnimatedContainer(
+ duration: const Duration(milliseconds: 300),
+ curve: Curves.easeInCubic,
+ // color: getEnteColorScheme(context).backgroundElevated2,
+ decoration: BoxDecoration(
+ gradient: value
+ ? null
+ // ? LinearGradient(
+ // begin: Alignment.topCenter,
+ // end: Alignment.bottomCenter,
+ // colors: [
+ // colorScheme.backgroundBase,
+ // colorScheme.backgroundElevated2,
+ // // Colors.black,
+ // ],
+ // )
+ : null,
+ ),
+ child: Column(
+ mainAxisSize: MainAxisSize.min,
+ children: [
+ value
+ ? const SearchWidgetNew()
+ .animate()
+ .fadeIn(
+ duration: const Duration(milliseconds: 175),
+ curve: Curves.easeInOutSine,
+ )
+ .scale(
+ begin: const Offset(0.6, 0.6),
+ end: const Offset(1, 1),
+ duration: const Duration(
+ milliseconds: 175,
+ ),
+ curve: Curves.easeInOutSine,
+ )
+ .slide(
+ begin: const Offset(0, 0.8),
+ curve: Curves.easeInOutSine,
+ duration: const Duration(
+ milliseconds: 175,
+ ),
+ )
+ : const SizedBox.shrink(),
+ child!,
+ ],
+ ),
+ );
+ },
+ child: HomeBottomNavigationBar(
+ _selectedFiles,
+ selectedTabIndex: _selectedTabIndex,
+ ),
),
),
],
diff --git a/lib/ui/viewer/search/search_widget_new.dart b/lib/ui/viewer/search/search_widget_new.dart
new file mode 100644
index 0000000000..90d6b68019
--- /dev/null
+++ b/lib/ui/viewer/search/search_widget_new.dart
@@ -0,0 +1,211 @@
+import "dart:async";
+
+import "package:flutter/material.dart";
+import "package:logging/logging.dart";
+import "package:photos/core/event_bus.dart";
+import "package:photos/ente_theme_data.dart";
+import "package:photos/events/tab_changed_event.dart";
+import "package:photos/generated/l10n.dart";
+import "package:photos/models/search/search_result.dart";
+import "package:photos/services/search_service.dart";
+import "package:photos/theme/ente_theme.dart";
+import "package:photos/ui/viewer/search/search_suffix_icon_widget.dart";
+import "package:photos/utils/date_time_util.dart";
+import "package:photos/utils/debouncer.dart";
+
+class SearchWidgetNew extends StatefulWidget {
+ const SearchWidgetNew({Key? key}) : super(key: key);
+
+ @override
+ State<SearchWidgetNew> createState() => _SearchWidgetNewState();
+}
+
+class _SearchWidgetNewState extends State<SearchWidgetNew> {
+ String _query = "";
+ final List<SearchResult> _results = [];
+ final _searchService = SearchService.instance;
+ final _debouncer = Debouncer(const Duration(milliseconds: 100));
+ final Logger _logger = Logger((_SearchWidgetNewState).toString());
+ late FocusNode focusNode;
+ StreamSubscription<TabDoubleTapEvent>? _tabDoubleTapEvent;
+
+ @override
+ void initState() {
+ super.initState();
+ focusNode = FocusNode();
+ _tabDoubleTapEvent =
+ Bus.instance.on<TabDoubleTapEvent>().listen((event) async {
+ debugPrint("Firing now ${event.selectedIndex}");
+ if (mounted && event.selectedIndex == 3) {
+ focusNode.requestFocus();
+ }
+ });
+ }
+
+ @override
+ Widget build(BuildContext context) {
+ final colorScheme = getEnteColorScheme(context);
+ return Padding(
+ padding: const EdgeInsets.symmetric(vertical: 12),
+ child: Padding(
+ padding: const EdgeInsets.symmetric(vertical: 2, horizontal: 8),
+ child: ClipRRect(
+ borderRadius: BorderRadius.circular(8),
+ child: Container(
+ height: 44,
+ color: colorScheme.fillFaint,
+ child: TextFormField(
+ style: Theme.of(context).textTheme.titleMedium,
+ // Below parameters are to disable auto-suggestion
+ enableSuggestions: false,
+ autocorrect: false,
+ // Above parameters are to disable auto-suggestion
+ decoration: InputDecoration(
+ hintText: S.of(context).searchHintText,
+ filled: true,
+ contentPadding: const EdgeInsets.symmetric(
+ vertical: 10,
+ ),
+ border: const UnderlineInputBorder(
+ borderSide: BorderSide.none,
+ ),
+ focusedBorder: const UnderlineInputBorder(
+ borderSide: BorderSide.none,
+ ),
+ prefixIconConstraints: const BoxConstraints(
+ maxHeight: 44,
+ maxWidth: 44,
+ minHeight: 44,
+ minWidth: 44,
+ ),
+ suffixIconConstraints: const BoxConstraints(
+ maxHeight: 44,
+ maxWidth: 44,
+ minHeight: 44,
+ minWidth: 44,
+ ),
+ prefixIcon: Hero(
+ tag: "search_icon",
+ child: Icon(
+ Icons.search,
+ color: Theme.of(context)
+ .colorScheme
+ .iconColor
+ .withOpacity(0.5),
+ ),
+ ),
+ /*Using valueListenableBuilder inside a stateful widget because this widget is only rebuild when
+ setState is called when deboucncing is over and the spinner needs to be shown while debouncing */
+ suffixIcon: ValueListenableBuilder(
+ valueListenable: _debouncer.debounceActiveNotifier,
+ builder: (
+ BuildContext context,
+ bool isDebouncing,
+ Widget? child,
+ ) {
+ return SearchSuffixIcon(
+ isDebouncing,
+ );
+ },
+ ),
+ ),
+ onChanged: (value) async {
+ _query = value;
+ final List<SearchResult> allResults =
+ await getSearchResultsForQuery(context, value);
+ /*checking if _query == value to make sure that the results are from the current query
+ and not from the previous query (race condition).*/
+ if (mounted && _query == value) {
+ setState(() {
+ _results.clear();
+ _results.addAll(allResults);
+ });
+ }
+ },
+ ),
+ ),
+ ),
+ ),
+ );
+ }
+
+ @override
+ void dispose() {
+ _debouncer.cancelDebounce();
+ focusNode.dispose();
+ _tabDoubleTapEvent?.cancel();
+ super.dispose();
+ }
+
+ Future<List<SearchResult>> getSearchResultsForQuery(
+ BuildContext context,
+ String query,
+ ) async {
+ final Completer<List<SearchResult>> completer = Completer();
+
+ _debouncer.run(
+ () {
+ return _getSearchResultsFromService(context, query, completer);
+ },
+ );
+
+ return completer.future;
+ }
+
+ Future<void> _getSearchResultsFromService(
+ BuildContext context,
+ String query,
+ Completer completer,
+ ) async {
+ final List<SearchResult> allResults = [];
+ if (query.isEmpty) {
+ completer.complete(allResults);
+ return;
+ }
+ try {
+ if (_isYearValid(query)) {
+ final yearResults = await _searchService.getYearSearchResults(query);
+ allResults.addAll(yearResults);
+ }
+
+ final holidayResults =
+ await _searchService.getHolidaySearchResults(context, query);
+ allResults.addAll(holidayResults);
+
+ final fileTypeSearchResults =
+ await _searchService.getFileTypeResults(query);
+ allResults.addAll(fileTypeSearchResults);
+
+ final captionAndDisplayNameResult =
+ await _searchService.getCaptionAndNameResults(query);
+ allResults.addAll(captionAndDisplayNameResult);
+
+ final fileExtnResult =
+ await _searchService.getFileExtensionResults(query);
+ allResults.addAll(fileExtnResult);
+
+ final locationResult = await _searchService.getLocationResults(query);
+ allResults.addAll(locationResult);
+
+ final collectionResults =
+ await _searchService.getCollectionSearchResults(query);
+ allResults.addAll(collectionResults);
+
+ final monthResults =
+ await _searchService.getMonthSearchResults(context, query);
+ allResults.addAll(monthResults);
+
+ final possibleEvents =
+ await _searchService.getDateResults(context, query);
+ allResults.addAll(possibleEvents);
+ } catch (e, s) {
+ _logger.severe("error during search", e, s);
+ }
+ completer.complete(allResults);
+ }
+
+ bool _isYearValid(String year) {
+ final yearAsInt = int.tryParse(year); //returns null if cannot be parsed
+ return yearAsInt != null && yearAsInt <= currentYear;
+ }
+}