Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ui): refactor message widget bottom row #1132

Merged
merged 8 commits into from
May 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/stream_chat_flutter/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
🐞 Fixed

- Fixed attachment picker ui.
- Fixed StreamChannelHeader and StreamThreadHeader subtitle alignment.
- 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

Expand Down
10 changes: 4 additions & 6 deletions packages/stream_chat_flutter/lib/src/channel_info.dart
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,10 @@ class StreamChannelInfo extends StatelessWidget {
return alternativeWidget ?? const Offstage();
}

return Align(
child: StreamTypingIndicator(
parentId: parentId,
style: textStyle,
alternativeWidget: alternativeWidget,
),
return StreamTypingIndicator(
parentId: parentId,
style: textStyle,
alternativeWidget: alternativeWidget,
);
}

Expand Down
95 changes: 50 additions & 45 deletions packages/stream_chat_flutter/lib/src/message_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -878,7 +878,7 @@ class _StreamMessageWidgetState extends State<StreamMessageWidget>
const Offstage();
}

final children = <Widget>[];
final children = <WidgetSpan>[];

final threadParticipants = widget.message.threadParticipants?.take(2);
final showThreadParticipants = threadParticipants?.isNotEmpty == true;
Expand Down Expand Up @@ -909,68 +909,72 @@ class _StreamMessageWidgetState extends State<StreamMessageWidget>
const usernameKey = Key('username');

children.addAll([
if (showUsername) _buildUsername(usernameKey),
if (showUsername) WidgetSpan(child: _buildUsername(usernameKey)),
if (showTimeStamp)
Text(
Jiffy(widget.message.createdAt.toLocal()).jm,
style: widget.messageTheme.createdAtStyle,
WidgetSpan(
child: Text(
Jiffy(widget.message.createdAt.toLocal()).jm,
style: widget.messageTheme.createdAtStyle,
),
),
if (showSendingIndicator)
WidgetSpan(
child: _buildSendingIndicator(),
),
if (showSendingIndicator) _buildSendingIndicator(),
]);

final showThreadTail = !(hasUrlAttachments || isGiphy || isOnlyEmoji) &&
(showThreadReplyIndicator || showInChannel);

final threadIndicatorWidgets = <Widget>[
final threadIndicatorWidgets = <WidgetSpan>[
if (showThreadTail)
Container(
margin: EdgeInsets.only(
bottom: context.textScaleFactor *
((widget.messageTheme.repliesStyle?.fontSize ?? 1) / 2),
),
child: CustomPaint(
size: const Size(16, 32) * context.textScaleFactor,
painter: _ThreadReplyPainter(
context: context,
color: widget.messageTheme.messageBorderColor,
reverse: widget.reverse,
WidgetSpan(
child: Container(
margin: EdgeInsets.only(
bottom: context.textScaleFactor *
((widget.messageTheme.repliesStyle?.fontSize ?? 1) / 2),
),
child: CustomPaint(
size: const Size(16, 32) * context.textScaleFactor,
painter: _ThreadReplyPainter(
context: context,
color: widget.messageTheme.messageBorderColor,
reverse: widget.reverse,
),
),
),
),
if (showInChannel || showThreadReplyIndicator) ...[
if (showThreadParticipants)
SizedBox.fromSize(
size: Size((threadParticipants!.length * 8.0) + 8, 16),
child: _buildThreadParticipantsIndicator(threadParticipants),
WidgetSpan(
child: SizedBox.fromSize(
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(
crossAxisAlignment: CrossAxisAlignment.end,
mainAxisAlignment:
widget.reverse ? MainAxisAlignment.end : MainAxisAlignment.start,
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;
},
),
if (showThreadTail && widget.reverse)
...threadIndicatorWidgets.reversed,
].insertBetween(const SizedBox(width: 8)),
if (widget.reverse) {
children.addAll(threadIndicatorWidgets.reversed);
} else {
children.insertAll(0, threadIndicatorWidgets);
}

return Text.rich(
TextSpan(
children: [
...children,
].insertBetween(const WidgetSpan(child: SizedBox(width: 8))),
),
maxLines: 1,
textAlign: widget.reverse ? TextAlign.right : TextAlign.left,
);
}

Expand Down Expand Up @@ -1259,6 +1263,7 @@ class _StreamMessageWidgetState extends State<StreamMessageWidget>
);
if (isMessageRead) {
child = Row(
mainAxisSize: MainAxisSize.min,
children: [
if (memberCount > 2)
Text(
Expand Down
12 changes: 5 additions & 7 deletions packages/stream_chat_flutter/lib/src/thread_header.dart
Original file line number Diff line number Diff line change
Expand Up @@ -186,13 +186,11 @@ class StreamThreadHeader extends StatelessWidget
),
const SizedBox(height: 2),
if (showTypingIndicator)
Align(
child: StreamTypingIndicator(
channel: StreamChannel.of(context).channel,
style: channelHeaderTheme.subtitleStyle,
parentId: parent.id,
alternativeWidget: defaultSubtitle,
),
StreamTypingIndicator(
channel: StreamChannel.of(context).channel,
style: channelHeaderTheme.subtitleStyle,
parentId: parent.id,
alternativeWidget: defaultSubtitle,
)
else
defaultSubtitle,
Expand Down