Skip to content

Commit

Permalink
fixup! TW-1621: searchable app bar implemented in forward screen
Browse files Browse the repository at this point in the history
  • Loading branch information
Te-Z committed Apr 9, 2024
1 parent 40d9921 commit 5be0e93
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 32 deletions.
36 changes: 5 additions & 31 deletions lib/pages/forward/forward.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import 'package:fluffychat/pages/chat/send_file_dialog/send_file_dialog.dart';
import 'package:fluffychat/pages/forward/forward_view.dart';
import 'package:fluffychat/presentation/enum/chat_list/chat_list_enum.dart';
import 'package:fluffychat/presentation/extensions/client_extension.dart';
import 'package:fluffychat/presentation/mixins/contacts_view_controller_mixin.dart';
import 'package:fluffychat/presentation/mixins/search_recent_chat_mixin.dart';
import 'package:fluffychat/presentation/model/pop_result_from_forward.dart';
import 'package:fluffychat/utils/platform_infos.dart';
Expand All @@ -34,13 +35,11 @@ class Forward extends StatefulWidget {
ForwardController createState() => ForwardController();
}

class ForwardController extends State<Forward> with SearchRecentChat {
class ForwardController extends State<Forward> with SearchRecentChat, ContactsViewControllerMixin {
final _forwardMessageInteractor = getIt.get<ForwardMessageInteractor>();

final forwardMessageNotifier = ValueNotifier<Either<Failure, Success>?>(null);

final isSearchBarShowNotifier = ValueNotifier(false);

StreamSubscription? forwardMessageInteractorStreamSubscription;

List<Room>? rooms;
Expand All @@ -51,33 +50,15 @@ class ForwardController extends State<Forward> with SearchRecentChat {

bool get isFullScreen => widget.isFullScreen == true;

final FocusNode searchFocusNode = FocusNode();

final AutoScrollController recentChatScrollController =
AutoScrollController();

final ValueNotifier<String> selectedRoomIdNotifier = ValueNotifier('');

final KeyboardVisibilityController keyboardVisibilityController =
KeyboardVisibilityController();

void openSearchBar() {
isSearchBarShowNotifier.value = true;
searchFocusNode.requestFocus();
}

void onSelectedContact() {
searchFocusNode.requestFocus();
searchTextEditingController.selection = TextSelection(
baseOffset: 0,
extentOffset: searchTextEditingController.text.length,
);
}

@override
void closeSearchBar() {
searchTextEditingController.clear();
searchFocusNode.unfocus();
isSearchBarShowNotifier.value = false;
super.closeSearchBar();
}

@override
Expand All @@ -91,19 +72,12 @@ class ForwardController extends State<Forward> with SearchRecentChat {
);
recentlyChatsNotifier.value = filteredRoomsForAll;
});
if (PlatformInfos.isMobile) {
keyboardVisibilityController.onChange.listen((visible) {
if (!visible) {
isSearchBarShowNotifier.value = false;
}
});
}
}

@override
void dispose() {
forwardMessageNotifier.dispose();
isSearchBarShowNotifier.dispose();
disposeContactsMixin();
recentChatScrollController.dispose();
forwardMessageInteractorStreamSubscription?.cancel();
disposeSearchRecentChat();
Expand Down
2 changes: 1 addition & 1 deletion lib/pages/forward/forward_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class ForwardView extends StatelessWidget {
toolbarHeight: ForwardViewStyle.maxToolbarHeight(context),
focusNode: controller.searchFocusNode,
title: L10n.of(context)!.forwardTo,
searchModeNotifier: controller.isSearchBarShowNotifier,
searchModeNotifier: controller.isSearchModeNotifier,
hintText: L10n.of(context)!.searchContacts,
textEditingController: controller.searchTextEditingController,
openSearchBar: controller.openSearchBar,
Expand Down

0 comments on commit 5be0e93

Please sign in to comment.