Merge pull request #141 from GetStream/hotfix/input

Hotfix/input
This commit is contained in:
Deven Joshi
2020-11-19 16:38:06 +05:30
committed by GitHub
4 changed files with 68 additions and 76 deletions
+1 -1
View File
@@ -15,7 +15,7 @@ jobs:
steps:
- uses: actions/checkout@v2
- name: Flutter action
uses: subosito/flutter-action@v1.3.2
uses: subosito/flutter-action@v1.4.0
with:
channel: 'stable'
- name: Get dependencies
+4
View File
@@ -1,3 +1,7 @@
## 0.2.13+1
- Use TextEditingController.addListener instead of TextField.onChanged
## 0.2.13
- Update llc dependency
+62 -74
View File
@@ -77,25 +77,25 @@ enum DefaultAttachmentTypes {
/// Modify it to change the widget appearance.
class MessageInput extends StatefulWidget {
/// Instantiate a new MessageInput
MessageInput(
{Key key,
this.onMessageSent,
this.preMessageSending,
this.parentMessage,
this.editMessage,
this.maxHeight = 150,
this.keyboardType = TextInputType.multiline,
this.disableAttachments = false,
this.doImageUploadRequest,
this.doFileUploadRequest,
this.initialMessage,
this.textEditingController,
this.actions,
this.actionsLocation = ActionsLocation.left,
this.attachmentThumbnailBuilders,
this.inputTextStyle,
this.attachmentIconColor})
: super(key: key);
MessageInput({
Key key,
this.onMessageSent,
this.preMessageSending,
this.parentMessage,
this.editMessage,
this.maxHeight = 150,
this.keyboardType = TextInputType.multiline,
this.disableAttachments = false,
this.doImageUploadRequest,
this.doFileUploadRequest,
this.initialMessage,
this.textEditingController,
this.actions,
this.actionsLocation = ActionsLocation.left,
this.attachmentThumbnailBuilders,
this.inputTextStyle,
this.attachmentIconColor,
}) : super(key: key);
/// Message to edit
final Message editMessage;
@@ -252,36 +252,6 @@ class MessageInputState extends State<MessageInput> {
keyboardType: widget.keyboardType,
controller: textEditingController,
focusNode: _focusNode,
onChanged: (s) {
StreamChannel.of(context).channel.keyStroke(
widget.parentMessage?.id,
);
setState(() {
_messageIsPresent = s.trim().isNotEmpty;
});
_commandsOverlay?.remove();
_commandsOverlay = null;
_mentionsOverlay?.remove();
_mentionsOverlay = null;
if (s.startsWith('/')) {
_commandsOverlay = _buildCommandsOverlayEntry();
Overlay.of(context).insert(_commandsOverlay);
}
if (textEditingController.selection.isCollapsed &&
(s[textEditingController.selection.start - 1] == '@' ||
textEditingController.text
.substring(0, textEditingController.selection.start)
.split(' ')
.last
.contains('@'))) {
_mentionsOverlay = _buildMentionsOverlayEntry();
Overlay.of(context).insert(_mentionsOverlay);
}
},
onTap: () {
setState(() {
_typingStarted = true;
@@ -403,7 +373,7 @@ class MessageInputState extends State<MessageInput> {
OverlayEntry _buildMentionsOverlayEntry() {
final splits = textEditingController.text
.substring(0, textEditingController.value.selection.start)
.substring(0, textEditingController.value.selection.baseOffset)
.split('@');
final query = splits.last.toLowerCase();
@@ -467,7 +437,7 @@ class MessageInputState extends State<MessageInput> {
text: rejoin +
textEditingController.text.substring(
textEditingController
.selection.start),
.selection.baseOffset),
selection: TextSelection.collapsed(
offset: rejoin.length,
),
@@ -962,41 +932,59 @@ class MessageInputState extends State<MessageInput> {
if (!kIsWeb) {
_keyboardListener = KeyboardVisibility.onChange.listen((visible) {
if (visible) {
if (_commandsOverlay != null) {
if (textEditingController.text.startsWith('/')) {
WidgetsBinding.instance.addPostFrameCallback((_) {
_commandsOverlay = _buildCommandsOverlayEntry();
Overlay.of(context).insert(_commandsOverlay);
});
}
}
if (_mentionsOverlay != null) {
if (textEditingController.text.contains('@')) {
WidgetsBinding.instance.addPostFrameCallback((_) {
_mentionsOverlay = _buildCommandsOverlayEntry();
Overlay.of(context).insert(_mentionsOverlay);
});
}
}
_onChange();
} else {
if (_commandsOverlay != null) {
_commandsOverlay.remove();
}
if (_mentionsOverlay != null) {
_mentionsOverlay.remove();
}
_commandsOverlay?.remove();
_commandsOverlay = null;
_mentionsOverlay?.remove();
_mentionsOverlay = null;
}
});
}
textEditingController =
widget.textEditingController ?? TextEditingController();
textEditingController.addListener(_onChange);
if (widget.editMessage != null || widget.initialMessage != null) {
_parseExistingMessage(widget.editMessage ?? widget.initialMessage);
}
}
void _onChange() {
final s = textEditingController.text;
StreamChannel.of(context).channel.keyStroke(
widget.parentMessage?.id,
);
setState(() {
_messageIsPresent = s.trim().isNotEmpty;
});
_commandsOverlay?.remove();
_commandsOverlay = null;
_mentionsOverlay?.remove();
_mentionsOverlay = null;
if (s.trim().startsWith('/')) {
_commandsOverlay = _buildCommandsOverlayEntry();
Overlay.of(context).insert(_commandsOverlay);
}
if (_messageIsPresent &&
textEditingController.selection.isCollapsed &&
textEditingController.selection.baseOffset > 0 &&
textEditingController.text
.substring(0, textEditingController.selection.baseOffset)
.split(' ')
.last
.contains('@')) {
_mentionsOverlay = _buildMentionsOverlayEntry();
Overlay.of(context).insert(_mentionsOverlay);
}
}
void _parseExistingMessage(Message message) {
textEditingController.text = message.text;
+1 -1
View File
@@ -1,7 +1,7 @@
name: stream_chat_flutter
homepage: https://github.com/GetStream/stream-chat-flutter
description: Stream Chat official Flutter SDK. Build your own chat experience using Dart and Flutter.
version: 0.2.13
version: 0.2.13+1
repository: https://github.com/GetStream/stream-chat-flutter
issue_tracker: https://github.com/GetStream/stream-chat-flutter/issues