feat: Introduce onAttachmentTap on messages attachment (#309)

* introdce onAttachmentTap on message

* correct indent

* sdfsd

Co-authored-by: Salvatore Giordano <[email protected]>
This commit is contained in:
Nelson Nunes
2021-03-08 14:30:17 +01:00
committed by GitHub
co-authored by Salvatore Giordano
parent e60294dc92
commit db04ba021a
3 changed files with 51 additions and 35 deletions
@@ -11,6 +11,7 @@ class VideoAttachment extends AttachmentWidget {
final MessageTheme messageTheme; final MessageTheme messageTheme;
final ShowMessageCallback onShowMessage; final ShowMessageCallback onShowMessage;
final ValueChanged<ReturnActionType> onReturnAction; final ValueChanged<ReturnActionType> onReturnAction;
final VoidCallback onAttachmentTap;
const VideoAttachment({ const VideoAttachment({
Key key, Key key,
@@ -20,6 +21,7 @@ class VideoAttachment extends AttachmentWidget {
this.messageTheme, this.messageTheme,
this.onShowMessage, this.onShowMessage,
this.onReturnAction, this.onReturnAction,
this.onAttachmentTap,
}) : super(key: key, message: message, attachment: attachment, size: size); }) : super(key: key, message: message, attachment: attachment, size: size);
@override @override
@@ -65,25 +67,26 @@ class VideoAttachment extends AttachmentWidget {
children: <Widget>[ children: <Widget>[
Expanded( Expanded(
child: GestureDetector( child: GestureDetector(
onTap: () async { onTap: onAttachmentTap ??
final channel = StreamChannel.of(context).channel; () async {
final res = await Navigator.push( final channel = StreamChannel.of(context).channel;
context, final res = await Navigator.push(
MaterialPageRoute( context,
builder: (_) => StreamChannel( MaterialPageRoute(
channel: channel, builder: (_) => StreamChannel(
child: FullScreenMedia( channel: channel,
mediaAttachments: [attachment], child: FullScreenMedia(
userName: message.user.name, mediaAttachments: [attachment],
sentAt: message.createdAt, userName: message.user.name,
message: message, sentAt: message.createdAt,
onShowMessage: onShowMessage, message: message,
onShowMessage: onShowMessage,
),
),
), ),
), );
), if (res != null) onReturnAction(res);
); },
if (res != null) onReturnAction(res);
},
child: Stack( child: Stack(
children: [ children: [
videoWidget, videoWidget,
@@ -139,6 +139,7 @@ class MessageListView extends StatefulWidget {
this.customAttachmentBuilders, this.customAttachmentBuilders,
this.onMessageTap, this.onMessageTap,
this.onSystemMessageTap, this.onSystemMessageTap,
this.onAttachmentTap,
}) : super(key: key); }) : super(key: key);
/// Function used to build a custom message widget /// Function used to build a custom message widget
@@ -228,6 +229,9 @@ class MessageListView extends StatefulWidget {
/// Called when system message is tapped /// Called when system message is tapped
final void Function(Message) onSystemMessageTap; final void Function(Message) onSystemMessageTap;
// Customize onTap on attachment
final void Function(Message message, Attachment attachment) onAttachmentTap;
@override @override
_MessageListViewState createState() => _MessageListViewState(); _MessageListViewState createState() => _MessageListViewState();
} }
@@ -1008,6 +1012,7 @@ class _MessageListViewState extends State<MessageListView> {
} }
FocusScope.of(context).unfocus(); FocusScope.of(context).unfocus();
}, },
onAttachmentTap: widget.onAttachmentTap,
); );
if (!message.isDeleted && if (!message.isDeleted &&
@@ -146,6 +146,9 @@ class MessageWidget extends StatefulWidget {
/// Function called when message is tapped /// Function called when message is tapped
final void Function(Message) onMessageTap; final void Function(Message) onMessageTap;
// Customize onTap on attachment
final void Function(Message message, Attachment attachment) onAttachmentTap;
/// ///
MessageWidget({ MessageWidget({
Key key, Key key,
@@ -195,6 +198,7 @@ class MessageWidget extends StatefulWidget {
this.attachmentPadding = EdgeInsets.zero, this.attachmentPadding = EdgeInsets.zero,
this.allRead = false, this.allRead = false,
this.onQuotedMessageTap, this.onQuotedMessageTap,
this.onAttachmentTap,
}) : attachmentBuilders = { }) : attachmentBuilders = {
'image': (context, message, attachment) { 'image': (context, message, attachment) {
return ImageAttachment( return ImageAttachment(
@@ -207,6 +211,9 @@ class MessageWidget extends StatefulWidget {
), ),
onShowMessage: onShowMessage, onShowMessage: onShowMessage,
onReturnAction: onReturnAction, onReturnAction: onReturnAction,
onAttachmentTap: () {
onAttachmentTap(message, attachment);
},
); );
}, },
'video': (context, message, attachment) { 'video': (context, message, attachment) {
@@ -220,30 +227,31 @@ class MessageWidget extends StatefulWidget {
message: message, message: message,
onShowMessage: onShowMessage, onShowMessage: onShowMessage,
onReturnAction: onReturnAction, onReturnAction: onReturnAction,
onAttachmentTap: () {
onAttachmentTap(message, attachment);
},
); );
}, },
'giphy': (context, message, attachment) { 'giphy': (context, message, attachment) {
return GiphyAttachment( return GiphyAttachment(
attachment: attachment, attachment: attachment,
messageTheme: messageTheme, messageTheme: messageTheme,
message: message, message: message,
size: Size( size: Size(
MediaQuery.of(context).size.width * 0.8, MediaQuery.of(context).size.width * 0.8,
MediaQuery.of(context).size.height * 0.3, MediaQuery.of(context).size.height * 0.3,
), ),
onShowMessage: onShowMessage, onShowMessage: onShowMessage,
onReturnAction: onReturnAction, onReturnAction: onReturnAction);
);
}, },
'file': (context, message, attachment) { 'file': (context, message, attachment) {
return FileAttachment( return FileAttachment(
message: message, message: message,
attachment: attachment, attachment: attachment,
size: Size( size: Size(
MediaQuery.of(context).size.width * 0.8, MediaQuery.of(context).size.width * 0.8,
MediaQuery.of(context).size.height * 0.3, MediaQuery.of(context).size.height * 0.3,
), ));
);
}, },
}..addAll(customAttachmentBuilders ?? {}), }..addAll(customAttachmentBuilders ?? {}),
super(key: key); super(key: key);