Skip to content

Commit

Permalink
TW-1402: cannot tag user in safari
Browse files Browse the repository at this point in the history
  • Loading branch information
sherlockvn authored and hoangdat committed Feb 6, 2024
1 parent aa49ffa commit d0ddef0
Show file tree
Hide file tree
Showing 6 changed files with 107 additions and 65 deletions.
5 changes: 5 additions & 0 deletions lib/pages/chat/chat.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'dart:io';
import 'package:fluffychat/pages/chat/chat_view_style.dart';
import 'package:fluffychat/presentation/mixins/handle_clipboard_action_mixin.dart';
import 'package:fluffychat/presentation/mixins/paste_image_mixin.dart';
import 'package:flutter_typeahead/flutter_typeahead.dart';
import 'package:universal_html/html.dart' as html;

import 'package:adaptive_dialog/adaptive_dialog.dart';
Expand Down Expand Up @@ -213,6 +214,9 @@ class ChatController extends State<Chat>

AutoScrollController suggestionScrollController = AutoScrollController();

SuggestionsController<Map<String, String?>> suggestionsController =
SuggestionsController();

bool isUnpinEvent(Event event) =>
room?.pinnedEventIds
.firstWhereOrNull((eventId) => eventId == event.eventId) !=
Expand Down Expand Up @@ -1587,6 +1591,7 @@ class ChatController extends State<Chat>
suggestionScrollController.dispose();
sendController.removeListener(updateInputTextNotifier);
sendController.dispose();
suggestionsController.dispose();
super.dispose();
}

Expand Down
1 change: 1 addition & 0 deletions lib/pages/chat/chat_input_row.dart
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ class ChatInputRow extends StatelessWidget {
keyboardType: TextInputType.multiline,
textInputAction: null,
onSubmitted: controller.onInputBarSubmitted,
suggestionsController: controller.suggestionsController,
typeAheadFocusNode: controller.inputFocus,
controller: controller.sendController,
focusSuggestionController: controller.focusSuggestionController,
Expand Down
41 changes: 23 additions & 18 deletions lib/pages/chat/input_bar/input_bar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class InputBar extends StatelessWidget with PasteImageMixin {
final ValueChanged<String>? onChanged;
final bool autofocus;
final ValueKey? typeAheadKey;
final SuggestionsController<Map<String, String?>>? suggestionsController;

InputBar({
this.room,
Expand All @@ -53,6 +54,7 @@ class InputBar extends StatelessWidget with PasteImageMixin {
required this.focusSuggestionController,
this.typeAheadKey,
this.rawKeyboardFocusNode,
this.suggestionsController,
Key? key,
}) : super(key: key);

Expand Down Expand Up @@ -375,14 +377,18 @@ class InputBar extends StatelessWidget with PasteImageMixin {
onRawKeyEvent(event);
},
child: TypeAheadField<Map<String, String?>>(
direction: AxisDirection.up,
direction: VerticalDirection.up,
hideOnEmpty: true,
hideOnLoading: true,
keepSuggestionsOnSuggestionSelected: true,
hideOnSelect: false,
debounceDuration: debounceDuration,
autoFlipDirection: true,
scrollController: suggestionScrollController,
textFieldConfiguration: TextFieldConfiguration(
suggestionsController: suggestionsController,
controller: controller,
focusNode: typeAheadFocusNode,
// show suggestions after 50ms idle time (default is 300)
builder: (context, controller, focusNode) => TextField(
minLines: minLines,
maxLines: maxLines,
keyboardType: keyboardType,
Expand All @@ -391,15 +397,15 @@ class InputBar extends StatelessWidget with PasteImageMixin {
style: InputBarStyle.getTypeAheadTextStyle(context),
controller: controller,
decoration: decoration,
focusNode: typeAheadFocusNode,
focusNode: focusNode,
onChanged: (text) {
if (onChanged != null) {
onChanged!(text);
}
},
onTap: () async {
await Future.delayed(debounceDurationTap);
FocusScope.of(context).requestFocus(typeAheadFocusNode);
FocusScope.of(context).requestFocus(focusNode);
},
onSubmitted: PlatformInfos.isMobile
? (text) {
Expand All @@ -411,29 +417,28 @@ class InputBar extends StatelessWidget with PasteImageMixin {
textCapitalization: TextCapitalization.sentences,
),
suggestionsCallback: (text) {
if (room!.isDirectChat) return {};
final suggestions = getSuggestions(text);
if (suggestions.isNotEmpty) {
suggestionsController?.open();
} else {
suggestionsController?.close();
typeAheadFocusNode?.requestFocus();
}
focusSuggestionController.suggestions = suggestions;
return suggestions;
},
itemBuilder: (context, suggestion) => SuggestionTile(
suggestion: suggestion,
client: Matrix.of(context).client,
),
suggestionsBoxDecoration: const SuggestionsBoxDecoration(
borderRadius: BorderRadius.all(
Radius.circular(InputBarStyle.suggestionBorderRadius),
),
),
onSuggestionSelected: insertSuggestion,
onSelected: insertSuggestion,
errorBuilder: (BuildContext context, Object? error) =>
const SizedBox(),
const SizedBox.shrink(),
loadingBuilder: (BuildContext context) => const SizedBox.shrink(),
// fix loading briefly flickering a dark box
noItemsFoundBuilder: (BuildContext context) =>
const SizedBox.shrink(),
// fix loading briefly showing no suggestions
layoutArchitecture: (widgets, _) => FocusSuggestionList(
emptyBuilder: (BuildContext context) => const SizedBox
.shrink(), // fix loading briefly showing no suggestions
listBuilder: (context, widgets) => FocusSuggestionList(
items: widgets,
scrollController: suggestionScrollController,
focusSuggestionController: focusSuggestionController,
Expand Down Expand Up @@ -598,6 +603,6 @@ class SuggestionTile extends StatelessWidget {
),
);
}
return Container();
return const SizedBox.shrink();
}
}
81 changes: 44 additions & 37 deletions lib/pages/homeserver_picker/homeserver_picker_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -144,39 +144,40 @@ class HomeserverTextField extends StatelessWidget {
BuildContext context,
) {
return TypeAheadField(
textFieldConfiguration: TextFieldConfiguration(
onEditingComplete: () => controller.loginButtonPressed(),
autofocus: controller.state != HomeserverState.ssoLoginServer,
focusNode: controller.homeserverFocusNode,
autocorrect: false,
enabled: true,
controller: controller.homeserverController,
decoration: InputDecoration(
border: OutlineInputBorder(
borderSide:
BorderSide(color: Theme.of(context).colorScheme.outline),
builder: (context, value, focusNode) {
return TextField(
onEditingComplete: () => controller.loginButtonPressed(),
autofocus: controller.state != HomeserverState.ssoLoginServer,
focusNode: controller.homeserverFocusNode,
autocorrect: false,
enabled: true,
controller: controller.homeserverController,
decoration: InputDecoration(
border: OutlineInputBorder(
borderSide:
BorderSide(color: Theme.of(context).colorScheme.outline),
),
focusedBorder: controller.state == HomeserverState.wrongServerName
? OutlineInputBorder(
borderSide: BorderSide(
color: Theme.of(context).colorScheme.error,
width: 2.0,
),
)
: null,
labelText: controller.state != HomeserverState.wrongServerName
? L10n.of(context)!.homeserver
: L10n.of(context)!.wrongServerName,
labelStyle: Theme.of(context).textTheme.bodySmall?.copyWith(
color: controller.state != HomeserverState.wrongServerName
? Theme.of(context).colorScheme.onSurface
: Theme.of(context).colorScheme.error,
),
hintText: L10n.of(context)!.enterYourHomeserver,
contentPadding: const EdgeInsets.all(16.0),
),
focusedBorder: controller.state == HomeserverState.wrongServerName
? OutlineInputBorder(
borderSide: BorderSide(
color: Theme.of(context).colorScheme.error,
width: 2.0,
),
)
: null,
labelText: controller.state != HomeserverState.wrongServerName
? L10n.of(context)!.homeserver
: L10n.of(context)!.wrongServerName,
labelStyle: Theme.of(context).textTheme.bodySmall?.copyWith(
letterSpacing: 0.4,
color: controller.state != HomeserverState.wrongServerName
? Theme.of(context).colorScheme.onSurface
: Theme.of(context).colorScheme.error,
),
hintText: L10n.of(context)!.enterYourHomeserver,
contentPadding: const EdgeInsets.all(16.0),
),
),
);
},
itemBuilder: (BuildContext context, HomeserverBenchmarkResult server) {
return ListTile(
trailing: IconButton(
Expand All @@ -200,12 +201,18 @@ class HomeserverTextField extends StatelessWidget {
),
);
},
suggestionsBoxDecoration: const SuggestionsBoxDecoration(
borderRadius: BorderRadius.all(Radius.circular(16)),
constraints: BoxConstraints(maxHeight: 200),
),
decorationBuilder: ((context, child) {
return Container(
constraints: const BoxConstraints(maxHeight: 200),
decoration: const BoxDecoration(
borderRadius: BorderRadius.all(Radius.circular(16)),
),
child: child,
);
}),
debounceDuration: const Duration(milliseconds: 300),
onSuggestionSelected: (HomeserverBenchmarkResult suggestion) {
direction: VerticalDirection.up,
onSelected: (HomeserverBenchmarkResult suggestion) {
controller.setServer(suggestion.homeserver.baseUrl.host);
},
suggestionsCallback: (String searchTerm) async {
Expand Down
40 changes: 32 additions & 8 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -808,10 +808,10 @@ packages:
dependency: "direct main"
description:
name: flutter_keyboard_visibility
sha256: "4983655c26ab5b959252ee204c2fffa4afeb4413cd030455194ec0caa3b8e7cb"
sha256: "98664be7be0e3ffca00de50f7f6a287ab62c763fc8c762e0a21584584a3ff4f8"
url: "https://pub.dev"
source: hosted
version: "5.4.1"
version: "6.0.0"
flutter_keyboard_visibility_linux:
dependency: transitive
description:
Expand Down Expand Up @@ -1044,10 +1044,10 @@ packages:
dependency: "direct main"
description:
name: flutter_typeahead
sha256: b9942bd5b7611a6ec3f0730c477146cffa4cd4b051077983ba67ddfc9e7ee818
sha256: e2070dea278f09ae30885872138ccae75292b33b7af2c241fec5ceafd980c374
url: "https://pub.dev"
source: hosted
version: "4.8.0"
version: "5.1.0"
flutter_web_auth_2:
dependency: "direct main"
description:
Expand Down Expand Up @@ -1935,18 +1935,42 @@ packages:
dependency: transitive
description:
name: plugin_platform_interface
sha256: da3fdfeccc4d4ff2da8f8c556704c08f912542c5fb3cf2233ed75372384a034d
sha256: "4820fbfdb9478b1ebae27888254d445073732dae3d6ea81f0b7e06d5dedc3f02"
url: "https://pub.dev"
source: hosted
version: "2.1.6"
version: "2.1.8"
pointer_interceptor:
dependency: transitive
description:
name: pointer_interceptor
sha256: adf7a637f97c077041d36801b43be08559fd4322d2127b3f20bb7be1b9eebc22
sha256: bd18321519718678d5fa98ad3a3359cbc7a31f018554eab80b73d08a7f0c165a
url: "https://pub.dev"
source: hosted
version: "0.10.1"
pointer_interceptor_ios:
dependency: transitive
description:
name: pointer_interceptor_ios
sha256: "2e73c39452830adc4695757130676a39412a3b7f3c34e3f752791b5384770877"
url: "https://pub.dev"
source: hosted
version: "0.10.0+2"
pointer_interceptor_platform_interface:
dependency: transitive
description:
name: pointer_interceptor_platform_interface
sha256: "0597b0560e14354baeb23f8375cd612e8bd4841bf8306ecb71fcd0bb78552506"
url: "https://pub.dev"
source: hosted
version: "0.10.0+1"
pointer_interceptor_web:
dependency: transitive
description:
name: pointer_interceptor_web
sha256: "9386e064097fd16419e935c23f08f35b58e6aaec155dd39bd6a003b88f9c14b4"
url: "https://pub.dev"
source: hosted
version: "0.9.3+7"
version: "0.10.1+2"
pointycastle:
dependency: transitive
description:
Expand Down
4 changes: 2 additions & 2 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ dependencies:
flutter_ringtone_player: ^3.1.1
flutter_secure_storage: ^7.0.1
flutter_svg: ^0.22.0
flutter_typeahead: 4.8.0
flutter_typeahead: ^5.1.0
flutter_web_auth_2: ^3.1.1
# flutter_webrtc: # Until https://github.com/flutter-webrtc/flutter-webrtc/issues/1212 is fixed
# git: https://github.com/radzio-it/flutter-webrtc.git
Expand Down Expand Up @@ -135,7 +135,7 @@ dependencies:
flutter_image_compress: ^2.0.4
image_gallery_saver: ^2.0.3
file_saver: ^0.1.1
flutter_keyboard_visibility: ^5.4.1
flutter_keyboard_visibility: ^6.0.0
# TODO: Remove it after this PR merged
# https://github.com/justsoft/video_thumbnail/pull/135
video_thumbnail:
Expand Down

0 comments on commit d0ddef0

Please sign in to comment.