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,21 +909,27 @@ 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(
child: Text(
Jiffy(widget.message.createdAt.toLocal()).jm, Jiffy(widget.message.createdAt.toLocal()).jm,
style: widget.messageTheme.createdAtStyle, style: widget.messageTheme.createdAtStyle,
), ),
if (showSendingIndicator) _buildSendingIndicator(), ),
if (showSendingIndicator)
WidgetSpan(
child: _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(
child: Container(
margin: EdgeInsets.only( margin: EdgeInsets.only(
bottom: context.textScaleFactor * bottom: context.textScaleFactor *
((widget.messageTheme.repliesStyle?.fontSize ?? 1) / 2), ((widget.messageTheme.repliesStyle?.fontSize ?? 1) / 2),
@@ -937,40 +943,38 @@ class _StreamMessageWidgetState extends State<StreamMessageWidget>
), ),
), ),
), ),
),
if (showInChannel || showThreadReplyIndicator) ...[ if (showInChannel || showThreadReplyIndicator) ...[
if (showThreadParticipants) if (showThreadParticipants)
SizedBox.fromSize( WidgetSpan(
child: SizedBox.fromSize(
size: Size((threadParticipants!.length * 8.0) + 8, 16), size: Size((threadParticipants!.length * 8.0) + 8, 16),
child: _buildThreadParticipantsIndicator(threadParticipants), child: _buildThreadParticipantsIndicator(threadParticipants),
), ),
InkWell( ),
WidgetSpan(
child: InkWell(
onTap: widget.onThreadTap != null ? onThreadTap : null, onTap: widget.onThreadTap != null ? onThreadTap : null,
child: Text(msg, style: widget.messageTheme.repliesStyle), 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(
(child) {
Widget mappedChild = SizedBox(
height: context.textScaleFactor * 14,
child: child,
);
if (child.key == usernameKey) {
mappedChild = Flexible(child: mappedChild);
} }
return mappedChild;
}, return Text.rich(
TextSpan(
children: [
...children,
].insertBetween(const WidgetSpan(child: SizedBox(width: 8))),
), ),
if (showThreadTail && widget.reverse) maxLines: 1,
...threadIndicatorWidgets.reversed, textAlign: widget.reverse ? TextAlign.right : TextAlign.left,
].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,