Merge pull request #1132 from GetStream/hotfix/messageWidget

fix(ui): refactor message widget bottom row
This commit is contained in:
Salvatore Giordano
2022-05-11 10:22:34 +02:00
committed by GitHub
4 changed files with 61 additions and 58 deletions
@@ -8,7 +8,9 @@
🐞 Fixed 🐞 Fixed
- Fixed attachment picker ui. - Fixed attachment picker ui.
- Fixed StreamChannelHeader and StreamThreadHeader subtitle alignment.
- Fixed message widget thread indicator in reverse mode. - Fixed message widget thread indicator in reverse mode.
- [[#1044]](https://github.com/GetStream/stream-chat-flutter/issues/1044): Refactor StreamMessageWidget bottom row to use Text.rich.
🔄 Changed 🔄 Changed
@@ -100,12 +100,10 @@ class StreamChannelInfo extends StatelessWidget {
return alternativeWidget ?? const Offstage(); return alternativeWidget ?? const Offstage();
} }
return Align( return StreamTypingIndicator(
child: StreamTypingIndicator( parentId: parentId,
parentId: parentId, style: textStyle,
style: textStyle, alternativeWidget: alternativeWidget,
alternativeWidget: alternativeWidget,
),
); );
} }
@@ -878,7 +878,7 @@ class _StreamMessageWidgetState extends State<StreamMessageWidget>
const Offstage(); const Offstage();
} }
final children = <Widget>[]; final children = <WidgetSpan>[];
final threadParticipants = widget.message.threadParticipants?.take(2); final threadParticipants = widget.message.threadParticipants?.take(2);
final showThreadParticipants = threadParticipants?.isNotEmpty == true; final showThreadParticipants = threadParticipants?.isNotEmpty == true;
@@ -909,68 +909,72 @@ class _StreamMessageWidgetState extends State<StreamMessageWidget>
const usernameKey = Key('username'); const usernameKey = Key('username');
children.addAll([ children.addAll([
if (showUsername) _buildUsername(usernameKey), if (showUsername) WidgetSpan(child: _buildUsername(usernameKey)),
if (showTimeStamp) if (showTimeStamp)
Text( WidgetSpan(
Jiffy(widget.message.createdAt.toLocal()).jm, child: Text(
style: widget.messageTheme.createdAtStyle, Jiffy(widget.message.createdAt.toLocal()).jm,
style: widget.messageTheme.createdAtStyle,
),
),
if (showSendingIndicator)
WidgetSpan(
child: _buildSendingIndicator(),
), ),
if (showSendingIndicator) _buildSendingIndicator(),
]); ]);
final showThreadTail = !(hasUrlAttachments || isGiphy || isOnlyEmoji) && final showThreadTail = !(hasUrlAttachments || isGiphy || isOnlyEmoji) &&
(showThreadReplyIndicator || showInChannel); (showThreadReplyIndicator || showInChannel);
final threadIndicatorWidgets = <Widget>[ final threadIndicatorWidgets = <WidgetSpan>[
if (showThreadTail) if (showThreadTail)
Container( WidgetSpan(
margin: EdgeInsets.only( child: Container(
bottom: context.textScaleFactor * margin: EdgeInsets.only(
((widget.messageTheme.repliesStyle?.fontSize ?? 1) / 2), bottom: context.textScaleFactor *
), ((widget.messageTheme.repliesStyle?.fontSize ?? 1) / 2),
child: CustomPaint( ),
size: const Size(16, 32) * context.textScaleFactor, child: CustomPaint(
painter: _ThreadReplyPainter( size: const Size(16, 32) * context.textScaleFactor,
context: context, painter: _ThreadReplyPainter(
color: widget.messageTheme.messageBorderColor, context: context,
reverse: widget.reverse, color: widget.messageTheme.messageBorderColor,
reverse: widget.reverse,
),
), ),
), ),
), ),
if (showInChannel || showThreadReplyIndicator) ...[ if (showInChannel || showThreadReplyIndicator) ...[
if (showThreadParticipants) if (showThreadParticipants)
SizedBox.fromSize( WidgetSpan(
size: Size((threadParticipants!.length * 8.0) + 8, 16), child: SizedBox.fromSize(
child: _buildThreadParticipantsIndicator(threadParticipants), size: Size((threadParticipants!.length * 8.0) + 8, 16),
child: _buildThreadParticipantsIndicator(threadParticipants),
),
),
WidgetSpan(
child: InkWell(
onTap: widget.onThreadTap != null ? onThreadTap : null,
child: Text(msg, style: widget.messageTheme.repliesStyle),
), ),
InkWell(
onTap: widget.onThreadTap != null ? onThreadTap : null,
child: Text(msg, style: widget.messageTheme.repliesStyle),
), ),
], ],
]; ];
return Row( if (widget.reverse) {
crossAxisAlignment: CrossAxisAlignment.end, children.addAll(threadIndicatorWidgets.reversed);
mainAxisAlignment: } else {
widget.reverse ? MainAxisAlignment.end : MainAxisAlignment.start, children.insertAll(0, threadIndicatorWidgets);
children: [ }
if (showThreadTail && !widget.reverse) ...threadIndicatorWidgets,
...children.map( return Text.rich(
(child) { TextSpan(
Widget mappedChild = SizedBox( children: [
height: context.textScaleFactor * 14, ...children,
child: child, ].insertBetween(const WidgetSpan(child: SizedBox(width: 8))),
); ),
if (child.key == usernameKey) { maxLines: 1,
mappedChild = Flexible(child: mappedChild); textAlign: widget.reverse ? TextAlign.right : TextAlign.left,
}
return mappedChild;
},
),
if (showThreadTail && widget.reverse)
...threadIndicatorWidgets.reversed,
].insertBetween(const SizedBox(width: 8)),
); );
} }
@@ -1259,6 +1263,7 @@ class _StreamMessageWidgetState extends State<StreamMessageWidget>
); );
if (isMessageRead) { if (isMessageRead) {
child = Row( child = Row(
mainAxisSize: MainAxisSize.min,
children: [ children: [
if (memberCount > 2) if (memberCount > 2)
Text( Text(
@@ -186,13 +186,11 @@ class StreamThreadHeader extends StatelessWidget
), ),
const SizedBox(height: 2), const SizedBox(height: 2),
if (showTypingIndicator) if (showTypingIndicator)
Align( StreamTypingIndicator(
child: StreamTypingIndicator( channel: StreamChannel.of(context).channel,
channel: StreamChannel.of(context).channel, style: channelHeaderTheme.subtitleStyle,
style: channelHeaderTheme.subtitleStyle, parentId: parent.id,
parentId: parent.id, alternativeWidget: defaultSubtitle,
alternativeWidget: defaultSubtitle,
),
) )
else else
defaultSubtitle, defaultSubtitle,