Skip to content

Commit 03a4244

Browse files
Gaurav-Kushwaha-1225gnprice
authored andcommitted
message_list: added pressedTint feature
This feature allows to see a tint color on the message when it is pressed. Shifted `MessageWithPossibleSender` to StatefulWidget and used `isMessageActionSheetOpen` to check BottomSheet is open or not (via onDismiss) in `showMessageActionSheet`. Added `pressedTint` to `DesignVariables` for using it in `MessageWithPossibleSender`. Fixes: #1142
1 parent 07d63d9 commit 03a4244

File tree

3 files changed

+178
-140
lines changed

3 files changed

+178
-140
lines changed

lib/widgets/action_sheet.dart

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import 'theme.dart';
3131
void _showActionSheet(
3232
BuildContext context, {
3333
required List<Widget> optionButtons,
34+
VoidCallback? onDismiss
3435
}) {
3536
showModalBottomSheet<void>(
3637
context: context,
@@ -61,7 +62,7 @@ void _showActionSheet(
6162
children: optionButtons))))),
6263
const ActionSheetCancelButton(),
6364
])));
64-
});
65+
}).whenComplete(onDismiss ?? () {});
6566
}
6667

6768
abstract class ActionSheetMenuItemButton extends StatelessWidget {
@@ -361,7 +362,7 @@ class UserTopicUpdateButton extends ActionSheetMenuItemButton {
361362
/// Show a sheet of actions you can take on a message in the message list.
362363
///
363364
/// Must have a [MessageListPage] ancestor.
364-
void showMessageActionSheet({required BuildContext context, required Message message}) {
365+
void showMessageActionSheet({required BuildContext context, required Message message, VoidCallback? onDismiss}) {
365366
final store = PerAccountStoreWidget.of(context);
366367

367368
// The UI that's conditioned on this won't live-update during this appearance
@@ -388,7 +389,7 @@ void showMessageActionSheet({required BuildContext context, required Message mes
388389
ShareButton(message: message, pageContext: context),
389390
];
390391

391-
_showActionSheet(context, optionButtons: optionButtons);
392+
_showActionSheet(context, optionButtons: optionButtons, onDismiss: onDismiss);
392393
}
393394

394395
abstract class MessageActionSheetMenuItemButton extends ActionSheetMenuItemButton {

lib/widgets/message_list.dart

Lines changed: 65 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1274,22 +1274,29 @@ String formatHeaderDate(
12741274
// Design referenced from:
12751275
// - https://github.com/zulip/zulip-mobile/issues/5511
12761276
// - https://www.figma.com/file/1JTNtYo9memgW7vV6d0ygq/Zulip-Mobile?node-id=538%3A20849&mode=dev
1277-
class MessageWithPossibleSender extends StatelessWidget {
1277+
class MessageWithPossibleSender extends StatefulWidget {
12781278
const MessageWithPossibleSender({super.key, required this.item});
12791279

12801280
final MessageListMessageItem item;
12811281

1282+
@override
1283+
State<MessageWithPossibleSender> createState() => _MessageWithPossibleSenderState();
1284+
}
1285+
1286+
class _MessageWithPossibleSenderState extends State<MessageWithPossibleSender> {
1287+
bool isMessageActionSheetOpen = false;
1288+
12821289
@override
12831290
Widget build(BuildContext context) {
12841291
final store = PerAccountStoreWidget.of(context);
12851292
final messageListTheme = MessageListTheme.of(context);
12861293
final designVariables = DesignVariables.of(context);
12871294

1288-
final message = item.message;
1295+
final message = widget.item.message;
12891296
final sender = store.users[message.senderId];
12901297

12911298
Widget? senderRow;
1292-
if (item.showSender) {
1299+
if (widget.item.showSender) {
12931300
final time = _kMessageTimestampFormat
12941301
.format(DateTime.fromMillisecondsSinceEpoch(1000 * message.timestamp));
12951302
senderRow = Row(
@@ -1347,40 +1354,63 @@ class MessageWithPossibleSender extends StatelessWidget {
13471354

13481355
return GestureDetector(
13491356
behavior: HitTestBehavior.translucent,
1350-
onLongPress: () => showMessageActionSheet(context: context, message: message),
1357+
onLongPress: () async {
1358+
setState(() {
1359+
isMessageActionSheetOpen = true;
1360+
});
1361+
1362+
await Future.delayed(const Duration(milliseconds: 100), () {
1363+
if (context.mounted) {return showMessageActionSheet(
1364+
context: context,
1365+
message: message,
1366+
onDismiss: () {
1367+
if (context.mounted) {
1368+
setState(() {
1369+
isMessageActionSheetOpen = false;
1370+
});
1371+
}
1372+
},
1373+
);}
1374+
});
1375+
},
13511376
child: Padding(
13521377
padding: const EdgeInsets.symmetric(vertical: 4),
1353-
child: Column(children: [
1354-
if (senderRow != null)
1355-
Padding(padding: const EdgeInsets.fromLTRB(16, 2, 16, 0),
1356-
child: senderRow),
1357-
Row(
1358-
crossAxisAlignment: CrossAxisAlignment.baseline,
1359-
textBaseline: localizedTextBaseline(context),
1360-
children: [
1361-
const SizedBox(width: 16),
1362-
Expanded(child: Column(
1363-
crossAxisAlignment: CrossAxisAlignment.stretch,
1364-
children: [
1365-
MessageContent(message: message, content: item.content),
1366-
if ((message.reactions?.total ?? 0) > 0)
1367-
ReactionChipsList(messageId: message.id, reactions: message.reactions!),
1368-
if (editStateText != null)
1369-
Text(editStateText,
1370-
textAlign: TextAlign.end,
1371-
style: TextStyle(
1372-
color: designVariables.labelEdited,
1373-
fontSize: 12,
1374-
height: (12 / 12),
1375-
letterSpacing: proportionalLetterSpacing(
1376-
context, 0.05, baseFontSize: 12))),
1377-
])),
1378-
SizedBox(width: 16,
1379-
child: message.flags.contains(MessageFlag.starred)
1380-
? Icon(ZulipIcons.star_filled, size: 16, color: designVariables.star)
1381-
: null),
1382-
]),
1383-
])));
1378+
child: DecoratedBox(
1379+
decoration: BoxDecoration(
1380+
color: isMessageActionSheetOpen ? designVariables.pressedTint : Colors.transparent
1381+
),
1382+
child: Column(children: [
1383+
if (senderRow != null)
1384+
Padding(padding: const EdgeInsets.fromLTRB(16, 2, 16, 0),
1385+
child: senderRow),
1386+
Row(
1387+
crossAxisAlignment: CrossAxisAlignment.baseline,
1388+
textBaseline: localizedTextBaseline(context),
1389+
children: [
1390+
const SizedBox(width: 16),
1391+
Expanded(child: Column(
1392+
crossAxisAlignment: CrossAxisAlignment.stretch,
1393+
children: [
1394+
MessageContent(message: message, content: widget.item.content),
1395+
if ((message.reactions?.total ?? 0) > 0)
1396+
ReactionChipsList(messageId: message.id, reactions: message.reactions!),
1397+
if (editStateText != null)
1398+
Text(editStateText,
1399+
textAlign: TextAlign.end,
1400+
style: TextStyle(
1401+
color: designVariables.labelEdited,
1402+
fontSize: 12,
1403+
height: (12 / 12),
1404+
letterSpacing: proportionalLetterSpacing(
1405+
context, 0.05, baseFontSize: 12))),
1406+
])),
1407+
SizedBox(width: 16,
1408+
child: message.flags.contains(MessageFlag.starred)
1409+
? Icon(ZulipIcons.star_filled, size: 16, color: designVariables.star)
1410+
: null),
1411+
]),
1412+
]),
1413+
)));
13841414
}
13851415
}
13861416

0 commit comments

Comments
 (0)