mirror of
https://github.com/immich-app/immich.git
synced 2025-05-24 01:12:58 -04:00
feat(mobile): Focus search on doubletap nav button (#6048)
* feat(mobile): Focus search on doubletap nav button * Update mobile/lib/modules/search/ui/immich_search_bar.dart Co-authored-by: shenlong <139912620+shenlong-tanwen@users.noreply.github.com> * Move search notifier inside search bar file And fix naming to better represent type. * Remove onSearchFocusRequest and call focusSearch directly * Fix compilation error after file autosave --------- Co-authored-by: Justin van der Krieken <justin@vdkrieken.com> Co-authored-by: shenlong <139912620+shenlong-tanwen@users.noreply.github.com>
This commit is contained in:
parent
d096caccac
commit
aa8c54e248
@ -21,6 +21,25 @@ class ImmichSearchBar extends HookConsumerWidget
|
|||||||
final searchTermController = useTextEditingController(text: "");
|
final searchTermController = useTextEditingController(text: "");
|
||||||
final isSearchEnabled = ref.watch(searchPageStateProvider).isSearchEnabled;
|
final isSearchEnabled = ref.watch(searchPageStateProvider).isSearchEnabled;
|
||||||
|
|
||||||
|
focusSearch() {
|
||||||
|
searchTermController.clear();
|
||||||
|
ref.watch(searchPageStateProvider.notifier).getSuggestedSearchTerms();
|
||||||
|
ref.watch(searchPageStateProvider.notifier).enableSearch();
|
||||||
|
ref.watch(searchPageStateProvider.notifier).setSearchTerm("");
|
||||||
|
|
||||||
|
searchFocusNode.requestFocus();
|
||||||
|
}
|
||||||
|
|
||||||
|
useEffect(
|
||||||
|
() {
|
||||||
|
searchFocusNotifier.addListener(focusSearch);
|
||||||
|
return () {
|
||||||
|
searchFocusNotifier.removeListener(focusSearch);
|
||||||
|
};
|
||||||
|
},
|
||||||
|
[],
|
||||||
|
);
|
||||||
|
|
||||||
return AppBar(
|
return AppBar(
|
||||||
automaticallyImplyLeading: false,
|
automaticallyImplyLeading: false,
|
||||||
leading: isSearchEnabled
|
leading: isSearchEnabled
|
||||||
@ -40,14 +59,7 @@ class ImmichSearchBar extends HookConsumerWidget
|
|||||||
controller: searchTermController,
|
controller: searchTermController,
|
||||||
focusNode: searchFocusNode,
|
focusNode: searchFocusNode,
|
||||||
autofocus: false,
|
autofocus: false,
|
||||||
onTap: () {
|
onTap: focusSearch,
|
||||||
searchTermController.clear();
|
|
||||||
ref.watch(searchPageStateProvider.notifier).getSuggestedSearchTerms();
|
|
||||||
ref.watch(searchPageStateProvider.notifier).enableSearch();
|
|
||||||
ref.watch(searchPageStateProvider.notifier).setSearchTerm("");
|
|
||||||
|
|
||||||
searchFocusNode.requestFocus();
|
|
||||||
},
|
|
||||||
onSubmitted: (searchTerm) {
|
onSubmitted: (searchTerm) {
|
||||||
onSubmitted(searchTerm);
|
onSubmitted(searchTerm);
|
||||||
searchTermController.clear();
|
searchTermController.clear();
|
||||||
@ -75,3 +87,13 @@ class ImmichSearchBar extends HookConsumerWidget
|
|||||||
@override
|
@override
|
||||||
Size get preferredSize => const Size.fromHeight(kToolbarHeight);
|
Size get preferredSize => const Size.fromHeight(kToolbarHeight);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Used to focus search from outside this widget.
|
||||||
|
// For example when double pressing the search nav icon.
|
||||||
|
final searchFocusNotifier = SearchFocusNotifier();
|
||||||
|
|
||||||
|
class SearchFocusNotifier with ChangeNotifier {
|
||||||
|
void requestFocus() {
|
||||||
|
notifyListeners();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -6,6 +6,7 @@ import 'package:hooks_riverpod/hooks_riverpod.dart';
|
|||||||
import 'package:immich_mobile/extensions/build_context_extensions.dart';
|
import 'package:immich_mobile/extensions/build_context_extensions.dart';
|
||||||
import 'package:immich_mobile/modules/asset_viewer/providers/scroll_notifier.provider.dart';
|
import 'package:immich_mobile/modules/asset_viewer/providers/scroll_notifier.provider.dart';
|
||||||
import 'package:immich_mobile/modules/home/providers/multiselect.provider.dart';
|
import 'package:immich_mobile/modules/home/providers/multiselect.provider.dart';
|
||||||
|
import 'package:immich_mobile/modules/search/ui/immich_search_bar.dart';
|
||||||
import 'package:immich_mobile/routing/router.dart';
|
import 'package:immich_mobile/routing/router.dart';
|
||||||
import 'package:immich_mobile/shared/providers/asset.provider.dart';
|
import 'package:immich_mobile/shared/providers/asset.provider.dart';
|
||||||
import 'package:immich_mobile/shared/providers/tab.provider.dart';
|
import 'package:immich_mobile/shared/providers/tab.provider.dart';
|
||||||
@ -51,6 +52,11 @@ class TabControllerPage extends HookConsumerWidget {
|
|||||||
// Scroll to top
|
// Scroll to top
|
||||||
scrollToTopNotifierProvider.scrollToTop();
|
scrollToTopNotifierProvider.scrollToTop();
|
||||||
}
|
}
|
||||||
|
if (tabsRouter.activeIndex == 1 && index == 1) {
|
||||||
|
// Focus search
|
||||||
|
searchFocusNotifier.requestFocus();
|
||||||
|
}
|
||||||
|
|
||||||
HapticFeedback.selectionClick();
|
HapticFeedback.selectionClick();
|
||||||
tabsRouter.setActiveIndex(index);
|
tabsRouter.setActiveIndex(index);
|
||||||
ref.read(tabProvider.notifier).state = TabEnum.values[index];
|
ref.read(tabProvider.notifier).state = TabEnum.values[index];
|
||||||
@ -104,6 +110,10 @@ class TabControllerPage extends HookConsumerWidget {
|
|||||||
// Scroll to top
|
// Scroll to top
|
||||||
scrollToTopNotifierProvider.scrollToTop();
|
scrollToTopNotifierProvider.scrollToTop();
|
||||||
}
|
}
|
||||||
|
if (tabsRouter.activeIndex == 1 && index == 1) {
|
||||||
|
// Focus search
|
||||||
|
searchFocusNotifier.requestFocus();
|
||||||
|
}
|
||||||
HapticFeedback.selectionClick();
|
HapticFeedback.selectionClick();
|
||||||
tabsRouter.setActiveIndex(index);
|
tabsRouter.setActiveIndex(index);
|
||||||
ref.read(tabProvider.notifier).state = TabEnum.values[index];
|
ref.read(tabProvider.notifier).state = TabEnum.values[index];
|
||||||
|
Loading…
x
Reference in New Issue
Block a user