Skip to content

armgit / ente

Public Imported from GitHub
0

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

Move and stick search bar to the top of keyboard when it comes up

ashilkn228f1f672a1c
diff --git a/lib/ui/search_tab.dart b/lib/ui/search_tab.dart
index 3e5208bf71..79333e45fe 100644
--- a/lib/ui/search_tab.dart
+++ b/lib/ui/search_tab.dart
@@ -3,7 +3,6 @@ import "package:photos/models/search/search_result.dart";
import "package:photos/models/search/search_types.dart";
import "package:photos/ui/common/loading_widget.dart";
import "package:photos/ui/viewer/search/search_section.dart";
-import "package:photos/ui/viewer/search/search_widget.dart";
class SearchTab extends StatefulWidget {
const SearchTab({Key? key}) : super(key: key);
@@ -20,14 +19,18 @@ class _SearchTabState extends State<SearchTab> {
@override
Widget build(BuildContext context) {
- return const Column(
- children: [
- Align(
- alignment: Alignment.topRight,
- child: SearchIconWidget(),
- ),
- AllSearchSections(),
- ],
+ // return const Column(
+ // children: [
+ // Align(
+ // alignment: Alignment.topRight,
+ // child: SearchIconWidget(),
+ // ),
+ // AllSearchSections(),
+ // ],
+ // );
+ return const Padding(
+ padding: EdgeInsets.only(top: 8),
+ child: AllSearchSections(),
);
}
diff --git a/lib/ui/tabs/home_widget.dart b/lib/ui/tabs/home_widget.dart
index 18885670c9..2aa9e46bbe 100644
--- a/lib/ui/tabs/home_widget.dart
+++ b/lib/ui/tabs/home_widget.dart
@@ -4,7 +4,6 @@ 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';
@@ -433,26 +432,26 @@ class _HomeWidgetState extends State<HomeWidget> {
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,
- ),
- )
+ // .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!,
],
diff --git a/lib/ui/viewer/search/search_widget_new.dart b/lib/ui/viewer/search/search_widget_new.dart
index 6f439084d4..b11ae55063 100644
--- a/lib/ui/viewer/search/search_widget_new.dart
+++ b/lib/ui/viewer/search/search_widget_new.dart
@@ -1,6 +1,7 @@
import "dart:async";
import "package:flutter/material.dart";
+import "package:flutter/scheduler.dart";
import "package:logging/logging.dart";
import "package:photos/core/event_bus.dart";
import "package:photos/events/tab_changed_event.dart";
@@ -26,6 +27,10 @@ class _SearchWidgetNewState extends State<SearchWidgetNew> {
final Logger _logger = Logger((_SearchWidgetNewState).toString());
late FocusNode focusNode;
StreamSubscription<TabDoubleTapEvent>? _tabDoubleTapEvent;
+ final _bottomPaddingNotifier = ValueNotifier<double>(0);
+ double _distanceOfWidgetFromBottom = 0;
+ //Check if globalKey is necessary
+ GlobalKey widgetKey = GlobalKey();
@override
void initState() {
@@ -38,92 +43,126 @@ class _SearchWidgetNewState extends State<SearchWidgetNew> {
focusNode.requestFocus();
}
});
+ SchedulerBinding.instance.addPostFrameCallback((_) {
+ final RenderBox box =
+ widgetKey.currentContext!.findRenderObject() as RenderBox;
+ final heightOfWidget = box.size.height;
+ final offsetPosition = box.localToGlobal(Offset.zero);
+ final y = offsetPosition.dy;
+ final heightOfScreen = MediaQuery.sizeOf(context).height;
+ _distanceOfWidgetFromBottom = heightOfScreen - (y + heightOfWidget);
+ });
+ }
+
+ @override
+ void didChangeDependencies() {
+ super.didChangeDependencies();
+
+ _bottomPaddingNotifier.value =
+ (MediaQuery.viewInsetsOf(context).bottom - _distanceOfWidgetFromBottom);
+ if (_bottomPaddingNotifier.value < 0) {
+ _bottomPaddingNotifier.value = 0;
+ }
}
@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: Container(
- color: colorScheme.backgroundBase,
- 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,
- hintText: "Search",
- 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: colorScheme.strokeFaint,
+ return RepaintBoundary(
+ //Why repaint boundary?
+ key: widgetKey,
+ child: ValueListenableBuilder(
+ valueListenable: _bottomPaddingNotifier,
+ builder: (context, value, _) {
+ return Padding(
+ padding: EdgeInsets.only(bottom: value),
+ //Use the bottom widget as child for valueListenableBuilder for
+ //better perf.
+ child: Padding(
+ padding: const EdgeInsets.symmetric(vertical: 12),
+ child: Padding(
+ padding: const EdgeInsets.symmetric(vertical: 2, horizontal: 8),
+ child: Container(
+ color: colorScheme.backgroundBase,
+ 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,
+ hintText: "Search",
+ 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: colorScheme.strokeFaint,
+ ),
+ ),
+ /*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);
+ });
+ }
+ },
+ ),
),
),
- /*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);
- });
- }
- },
),
),
- ),
- ),
+ );
+ },
),
);
}