1+ import 'dart:async' ;
12import 'dart:math' ;
23
34import 'package:collection/collection.dart' ;
5+ import 'package:flutter/gestures.dart' ;
46import 'package:flutter/material.dart' ;
57import 'package:flutter_color_models/flutter_color_models.dart' ;
68import 'package:intl/intl.dart' hide TextDirection;
@@ -16,6 +18,7 @@ import 'actions.dart';
1618import 'app_bar.dart' ;
1719import 'compose_box.dart' ;
1820import 'content.dart' ;
21+ import 'dialog.dart' ;
1922import 'emoji_reaction.dart' ;
2023import 'icons.dart' ;
2124import 'page.dart' ;
@@ -1318,22 +1321,45 @@ String formatHeaderDate(
13181321// Design referenced from:
13191322// - https://github.com/zulip/zulip-mobile/issues/5511
13201323// - https://www.figma.com/file/1JTNtYo9memgW7vV6d0ygq/Zulip-Mobile?node-id=538%3A20849&mode=dev
1321- class MessageWithPossibleSender extends StatelessWidget {
1324+ class MessageWithPossibleSender extends StatefulWidget {
13221325 const MessageWithPossibleSender ({super .key, required this .item});
13231326
13241327 final MessageListMessageItem item;
13251328
1329+ @override
1330+ State <MessageWithPossibleSender > createState () => _MessageWithPossibleSenderState ();
1331+ }
1332+
1333+ class _MessageWithPossibleSenderState extends State <MessageWithPossibleSender > {
1334+ final WidgetStatesController statesController = WidgetStatesController ();
1335+
1336+ @override
1337+ void initState () {
1338+ super .initState ();
1339+ statesController.addListener (() {
1340+ setState (() {
1341+ // Force a rebuild to resolve background color
1342+ });
1343+ });
1344+ }
1345+
1346+ @override
1347+ void dispose () {
1348+ statesController.dispose ();
1349+ super .dispose ();
1350+ }
1351+
13261352 @override
13271353 Widget build (BuildContext context) {
13281354 final store = PerAccountStoreWidget .of (context);
13291355 final messageListTheme = MessageListTheme .of (context);
13301356 final designVariables = DesignVariables .of (context);
13311357
1332- final message = item.message;
1358+ final message = widget. item.message;
13331359 final sender = store.getUser (message.senderId);
13341360
13351361 Widget ? senderRow;
1336- if (item.showSender) {
1362+ if (widget. item.showSender) {
13371363 final time = _kMessageTimestampFormat
13381364 .format (DateTime .fromMillisecondsSinceEpoch (1000 * message.timestamp));
13391365 senderRow = Row (
@@ -1400,40 +1426,62 @@ class MessageWithPossibleSender extends StatelessWidget {
14001426 child: Icon (ZulipIcons .star_filled, size: 16 , color: designVariables.star));
14011427 }
14021428
1403- return GestureDetector (
1429+ return RawGestureDetector (
14041430 behavior: HitTestBehavior .translucent,
1405- onLongPress: () => showMessageActionSheet (context: context, message: message),
1406- child: Padding (
1407- padding: const EdgeInsets .symmetric (vertical: 4 ),
1408- child: Column (children: [
1409- if (senderRow != null )
1410- Padding (padding: const EdgeInsets .fromLTRB (16 , 2 , 16 , 0 ),
1411- child: senderRow),
1412- Row (
1413- crossAxisAlignment: CrossAxisAlignment .baseline,
1414- textBaseline: localizedTextBaseline (context),
1415- children: [
1416- const SizedBox (width: 16 ),
1417- Expanded (child: Column (
1418- crossAxisAlignment: CrossAxisAlignment .stretch,
1419- children: [
1420- MessageContent (message: message, content: item.content),
1421- if ((message.reactions? .total ?? 0 ) > 0 )
1422- ReactionChipsList (messageId: message.id, reactions: message.reactions! ),
1423- if (editStateText != null )
1424- Text (editStateText,
1425- textAlign: TextAlign .end,
1426- style: TextStyle (
1427- color: designVariables.labelEdited,
1428- fontSize: 12 ,
1429- height: (12 / 12 ),
1430- letterSpacing: proportionalLetterSpacing (
1431- context, 0.05 , baseFontSize: 12 ))),
1432- ])),
1433- SizedBox (width: 16 ,
1434- child: star),
1435- ]),
1436- ])));
1431+ gestures: < Type , GestureRecognizerFactory > {
1432+ LongPressGestureRecognizer : GestureRecognizerFactoryWithHandlers <LongPressGestureRecognizer >(
1433+ () => LongPressGestureRecognizer (duration: Duration (milliseconds: 600 )),
1434+ (instance) {
1435+ instance.onLongPress = () async {
1436+ statesController.update (WidgetState .selected, true );
1437+ ModalStatus status = showMessageActionSheet (context: context,
1438+ message: message);
1439+ await status.closed;
1440+ statesController.update (WidgetState .selected, false );
1441+ };
1442+ instance.onLongPressDown = (_) => statesController.update (WidgetState .pressed, true );
1443+ instance.onLongPressCancel = () => statesController.update (WidgetState .pressed, false );
1444+ instance.onLongPressUp = () => statesController.update (WidgetState .pressed, false );
1445+ },
1446+ ),
1447+ },
1448+ child: DecoratedBox (decoration: BoxDecoration (
1449+ color: WidgetStateColor .fromMap ({
1450+ WidgetState .pressed: designVariables.pressedTint,
1451+ WidgetState .selected: designVariables.pressedTint,
1452+ WidgetState .any: Colors .transparent,
1453+ }).resolve (statesController.value)),
1454+ child: Padding (
1455+ padding: const EdgeInsets .symmetric (vertical: 4 ),
1456+ child: Column (children: [
1457+ if (senderRow != null )
1458+ Padding (padding: const EdgeInsets .fromLTRB (16 , 2 , 16 , 0 ),
1459+ child: senderRow),
1460+ Row (
1461+ crossAxisAlignment: CrossAxisAlignment .baseline,
1462+ textBaseline: localizedTextBaseline (context),
1463+ children: [
1464+ const SizedBox (width: 16 ),
1465+ Expanded (child: Column (
1466+ crossAxisAlignment: CrossAxisAlignment .stretch,
1467+ children: [
1468+ MessageContent (message: message, content: widget.item.content),
1469+ if ((message.reactions? .total ?? 0 ) > 0 )
1470+ ReactionChipsList (messageId: message.id, reactions: message.reactions! ),
1471+ if (editStateText != null )
1472+ Text (editStateText,
1473+ textAlign: TextAlign .end,
1474+ style: TextStyle (
1475+ color: designVariables.labelEdited,
1476+ fontSize: 12 ,
1477+ height: (12 / 12 ),
1478+ letterSpacing: proportionalLetterSpacing (
1479+ context, 0.05 , baseFontSize: 12 ))),
1480+ ])),
1481+ SizedBox (width: 16 ,
1482+ child: star),
1483+ ]),
1484+ ]))));
14371485 }
14381486}
14391487
0 commit comments