Merge pull request #683 from GetStream/attachment-tap-fix

fix(ui): Attachment tap fix
This commit is contained in:
Salvatore Giordano
2021-09-16 12:55:55 +02:00
committed by GitHub
4 changed files with 38 additions and 18 deletions
@@ -37,6 +37,7 @@
🐞 Fixed 🐞 Fixed
- Fixed `MessageSearchListView` pagination. - Fixed `MessageSearchListView` pagination.
- Fixed `MessageWidget` attachment tap callbacks.
## 2.2.1 ## 2.2.1
@@ -98,7 +98,13 @@ class GiphyAttachment extends AttachmentWidget {
Padding( Padding(
padding: const EdgeInsets.all(2), padding: const EdgeInsets.all(2),
child: GestureDetector( child: GestureDetector(
onTap: () => onAttachmentTap ?? _onImageTap(context), onTap: () {
if (onAttachmentTap != null) {
onAttachmentTap?.call();
} else {
_onImageTap(context);
}
},
child: CachedNetworkImage( child: CachedNetworkImage(
height: size?.height, height: size?.height,
width: size?.width, width: size?.width,
@@ -253,21 +259,12 @@ class GiphyAttachment extends AttachmentWidget {
Widget _buildSentAttachment(BuildContext context, String imageUrl) => Widget _buildSentAttachment(BuildContext context, String imageUrl) =>
SizedBox( SizedBox(
child: GestureDetector( child: GestureDetector(
onTap: () async { onTap: () {
final res = if (onAttachmentTap != null) {
await Navigator.push(context, MaterialPageRoute(builder: (_) { onAttachmentTap?.call();
final channel = StreamChannel.of(context).channel; } else {
return StreamChannel( _onImageTap(context);
channel: channel, }
child: FullScreenMedia(
mediaAttachments: [attachment],
userName: message.user?.name,
message: message,
onShowMessage: onShowMessage,
),
);
}));
if (res != null) onReturnAction!(res);
}, },
child: Stack( child: Stack(
children: [ children: [
@@ -15,6 +15,7 @@ class ImageGroup extends StatelessWidget {
required this.size, required this.size,
this.onReturnAction, this.onReturnAction,
this.onShowMessage, this.onShowMessage,
this.onAttachmentTap,
}) : super(key: key); }) : super(key: key);
/// List of attachments to show /// List of attachments to show
@@ -23,6 +24,9 @@ class ImageGroup extends StatelessWidget {
/// Callback when attachment is returned to from other screens /// Callback when attachment is returned to from other screens
final ValueChanged<ReturnActionType>? onReturnAction; final ValueChanged<ReturnActionType>? onReturnAction;
/// Callback when attachment is tapped
final void Function(Message message, Attachment attachment)? onAttachmentTap;
/// Message which images are attached to /// Message which images are attached to
final Message message; final Message message;
@@ -117,6 +121,10 @@ class ImageGroup extends StatelessWidget {
BuildContext context, BuildContext context,
int index, int index,
) async { ) async {
if (onAttachmentTap != null) {
return onAttachmentTap!(message, images[index]);
}
final channel = StreamChannel.of(context).channel; final channel = StreamChannel.of(context).channel;
final res = await Navigator.push( final res = await Navigator.push(
@@ -96,7 +96,7 @@ class MessageWidget extends StatefulWidget {
this.bottomRowBuilder, this.bottomRowBuilder,
this.deletedBottomRowBuilder, this.deletedBottomRowBuilder,
this.onReturnAction, this.onReturnAction,
Map<String, AttachmentBuilder>? customAttachmentBuilders, this.customAttachmentBuilders,
this.readList, this.readList,
this.padding, this.padding,
this.textPadding = const EdgeInsets.symmetric( this.textPadding = const EdgeInsets.symmetric(
@@ -133,6 +133,7 @@ class MessageWidget extends StatefulWidget {
messageTheme: messageTheme, messageTheme: messageTheme,
onShowMessage: onShowMessage, onShowMessage: onShowMessage,
onReturnAction: onReturnAction, onReturnAction: onReturnAction,
onAttachmentTap: onAttachmentTap,
), ),
), ),
border, border,
@@ -214,6 +215,11 @@ class MessageWidget extends StatefulWidget {
), ),
onShowMessage: onShowMessage, onShowMessage: onShowMessage,
onReturnAction: onReturnAction, onReturnAction: onReturnAction,
onAttachmentTap: onAttachmentTap != null
? () {
onAttachmentTap(message, attachment);
}
: null,
); );
}).toList(), }).toList(),
), ),
@@ -243,6 +249,11 @@ class MessageWidget extends StatefulWidget {
mediaQueryData.size.width * 0.8, mediaQueryData.size.width * 0.8,
mediaQueryData.size.height * 0.3, mediaQueryData.size.height * 0.3,
), ),
onAttachmentTap: onAttachmentTap != null
? () {
onAttachmentTap(message, attachment);
}
: null,
), ),
border, border,
reverse, reverse,
@@ -395,6 +406,9 @@ class MessageWidget extends StatefulWidget {
/// Builder for respective attachment types /// Builder for respective attachment types
final Map<String, AttachmentBuilder> attachmentBuilders; final Map<String, AttachmentBuilder> attachmentBuilders;
/// Builder for respective attachment types (user facing builder)
final Map<String, AttachmentBuilder>? customAttachmentBuilders;
/// Center user avatar with bottom of the message /// Center user avatar with bottom of the message
final bool translateUserAvatar; final bool translateUserAvatar;
@@ -519,7 +533,7 @@ class MessageWidget extends StatefulWidget {
showPinButton: showPinButton ?? this.showPinButton, showPinButton: showPinButton ?? this.showPinButton,
showPinHighlight: showPinHighlight ?? this.showPinHighlight, showPinHighlight: showPinHighlight ?? this.showPinHighlight,
customAttachmentBuilders: customAttachmentBuilders:
customAttachmentBuilders ?? attachmentBuilders, customAttachmentBuilders ?? this.customAttachmentBuilders,
translateUserAvatar: translateUserAvatar ?? this.translateUserAvatar, translateUserAvatar: translateUserAvatar ?? this.translateUserAvatar,
onQuotedMessageTap: onQuotedMessageTap ?? this.onQuotedMessageTap, onQuotedMessageTap: onQuotedMessageTap ?? this.onQuotedMessageTap,
onMessageTap: onMessageTap ?? this.onMessageTap, onMessageTap: onMessageTap ?? this.onMessageTap,