fix: list scroll keyboard behaviour (#304)

* fix: Keyboard now closes by clicking on space or scrolling.

* fix: Exposed system and normal message tap builders

* fmt: dartfmt
This commit is contained in:
Deven Joshi
2021-03-02 16:07:20 +01:00
committed by GitHub
parent 6474274d01
commit a14e54591d
2 changed files with 36 additions and 0 deletions
@@ -136,6 +136,8 @@ class MessageListView extends StatefulWidget {
this.messageListBuilder,
this.errorWidgetBuilder,
this.customAttachmentBuilders,
this.onMessageTap,
this.onSystemMessageTap,
}) : super(key: key);
/// Function used to build a custom message widget
@@ -216,6 +218,12 @@ class MessageListView extends StatefulWidget {
/// Please change this in the [MessageWidget] if you are using a custom implementation
final Map<String, AttachmentBuilder> customAttachmentBuilders;
/// Called when any message is tapped except a system message (use [onSystemMessageTap] instead)
final void Function(Message) onMessageTap;
/// Called when system message is tapped
final void Function(Message) onSystemMessageTap;
@override
_MessageListViewState createState() => _MessageListViewState();
}
@@ -364,6 +372,9 @@ class _MessageListViewState extends State<MessageListView> {
childAnchor: Alignment.topCenter,
message: statusString,
child: LazyLoadScrollView(
onPageScrollStart: () {
FocusScope.of(context).unfocus();
},
onStartOfPage: () async {
_inBetweenList = false;
if (!_upToDate) {
@@ -812,6 +823,12 @@ class _MessageListViewState extends State<MessageListView> {
}
},
customAttachmentBuilders: widget.customAttachmentBuilders,
onMessageTap: (message) {
if (widget.onMessageTap != null) {
widget.onMessageTap(message);
}
FocusScope.of(context).unfocus();
},
);
}
@@ -825,6 +842,12 @@ class _MessageListViewState extends State<MessageListView> {
SystemMessage(
key: ValueKey<String>('MESSAGE-${message.id}'),
message: message,
onMessageTap: (message) {
if (widget.onSystemMessageTap != null) {
widget.onSystemMessageTap(message);
}
FocusScope.of(context).unfocus();
},
);
}
@@ -974,6 +997,12 @@ class _MessageListViewState extends State<MessageListView> {
}
},
customAttachmentBuilders: widget.customAttachmentBuilders,
onMessageTap: (message) {
if (widget.onMessageTap != null) {
widget.onMessageTap(message);
}
FocusScope.of(context).unfocus();
},
);
if (!message.isDeleted &&
@@ -143,6 +143,9 @@ class MessageWidget extends StatefulWidget {
/// Function called when quotedMessage is tapped
final OnQuotedMessageTap onQuotedMessageTap;
/// Function called when message is tapped
final void Function(Message) onMessageTap;
///
MessageWidget({
Key key,
@@ -157,6 +160,7 @@ class MessageWidget extends StatefulWidget {
this.borderRadiusGeometry,
this.attachmentBorderRadiusGeometry,
this.onMentionTap,
this.onMessageTap,
this.showReactionPickerIndicator = false,
this.showUserAvatar = DisplayWidget.show,
this.showSendingIndicator = true,
@@ -311,6 +315,9 @@ class _MessageWidgetState extends State<MessageWidget>
type: MaterialType.transparency,
child: Portal(
child: InkWell(
onTap: () {
widget.onMessageTap(widget.message);
},
onLongPress: widget.message.isDeleted && !isFailedState
? null
: () => onLongPress(context),