fix: Remove too sensitive dismiss gesture on chat list items

pull/1666/head
Krille 9 months ago
parent 5c969a1299
commit 7a47a6a595
No known key found for this signature in database
GPG Key ID: E067ECD60F1A0652

@ -93,325 +93,304 @@ class ChatListItem extends StatelessWidget {
: room.getState(EventTypes.RoomMember, lastEvent.senderId) == null; : room.getState(EventTypes.RoomMember, lastEvent.senderId) == null;
final space = this.space; final space = this.space;
return Dismissible( return Padding(
key: ValueKey(room.id), padding: const EdgeInsets.symmetric(
confirmDismiss: (_) => archiveAction(context), horizontal: 8,
onDismissed: (_) { vertical: 1,
// Empty dismissed callback to trigger the dismiss animation
},
background: Material(
color: theme.colorScheme.errorContainer,
child: Icon(
Icons.archive_outlined,
color: theme.colorScheme.onErrorContainer,
),
), ),
child: Padding( child: Material(
padding: const EdgeInsets.symmetric( borderRadius: BorderRadius.circular(AppConfig.borderRadius),
horizontal: 8, clipBehavior: Clip.hardEdge,
vertical: 1, color: backgroundColor,
), child: FutureBuilder(
child: Material( future: room.loadHeroUsers(),
borderRadius: BorderRadius.circular(AppConfig.borderRadius), builder: (context, snapshot) => HoverBuilder(
clipBehavior: Clip.hardEdge, builder: (context, listTileHovered) => ListTile(
color: backgroundColor, visualDensity: const VisualDensity(vertical: -0.5),
child: FutureBuilder( contentPadding: const EdgeInsets.symmetric(horizontal: 8),
future: room.loadHeroUsers(), onLongPress: () => onLongPress?.call(context),
builder: (context, snapshot) => HoverBuilder( leading: HoverBuilder(
builder: (context, listTileHovered) => ListTile( builder: (context, hovered) => AnimatedScale(
visualDensity: const VisualDensity(vertical: -0.5), duration: FluffyThemes.animationDuration,
contentPadding: const EdgeInsets.symmetric(horizontal: 8), curve: FluffyThemes.animationCurve,
onLongPress: () => onLongPress?.call(context), scale: hovered ? 1.1 : 1.0,
leading: HoverBuilder( child: SizedBox(
builder: (context, hovered) => AnimatedScale( width: Avatar.defaultSize,
duration: FluffyThemes.animationDuration, height: Avatar.defaultSize,
curve: FluffyThemes.animationCurve, child: Stack(
scale: hovered ? 1.1 : 1.0, children: [
child: SizedBox( if (space != null)
width: Avatar.defaultSize,
height: Avatar.defaultSize,
child: Stack(
children: [
if (space != null)
Positioned(
top: 0,
left: 0,
child: Avatar(
border: BorderSide(
width: 2,
color: backgroundColor ??
theme.colorScheme.surface,
),
borderRadius: BorderRadius.circular(
AppConfig.borderRadius / 4,
),
mxContent: space.avatar,
size: Avatar.defaultSize * 0.75,
name: space.getLocalizedDisplayname(),
onTap: () => onLongPress?.call(context),
),
),
Positioned( Positioned(
bottom: 0, top: 0,
right: 0, left: 0,
child: Avatar( child: Avatar(
border: space == null border: BorderSide(
? room.isSpace width: 2,
? BorderSide( color: backgroundColor ??
width: 1, theme.colorScheme.surface,
color: theme.dividerColor, ),
) borderRadius: BorderRadius.circular(
: null AppConfig.borderRadius / 4,
: BorderSide( ),
width: 2, mxContent: space.avatar,
color: backgroundColor ?? size: Avatar.defaultSize * 0.75,
theme.colorScheme.surface, name: space.getLocalizedDisplayname(),
),
borderRadius: room.isSpace
? BorderRadius.circular(
AppConfig.borderRadius / 4,
)
: null,
mxContent: room.avatar,
size: space != null
? Avatar.defaultSize * 0.75
: Avatar.defaultSize,
name: displayname,
presenceUserId: directChatMatrixId,
presenceBackgroundColor: backgroundColor,
onTap: () => onLongPress?.call(context), onTap: () => onLongPress?.call(context),
), ),
), ),
Positioned( Positioned(
top: 0, bottom: 0,
right: 0, right: 0,
child: GestureDetector( child: Avatar(
onTap: () => onLongPress?.call(context), border: space == null
child: AnimatedScale( ? room.isSpace
duration: FluffyThemes.animationDuration, ? BorderSide(
curve: FluffyThemes.animationCurve, width: 1,
scale: listTileHovered ? 1.0 : 0.0, color: theme.dividerColor,
child: Material( )
color: backgroundColor, : null
borderRadius: BorderRadius.circular(16), : BorderSide(
child: const Icon( width: 2,
Icons.arrow_drop_down_circle_outlined, color: backgroundColor ??
size: 18, theme.colorScheme.surface,
), ),
borderRadius: room.isSpace
? BorderRadius.circular(
AppConfig.borderRadius / 4,
)
: null,
mxContent: room.avatar,
size: space != null
? Avatar.defaultSize * 0.75
: Avatar.defaultSize,
name: displayname,
presenceUserId: directChatMatrixId,
presenceBackgroundColor: backgroundColor,
onTap: () => onLongPress?.call(context),
),
),
Positioned(
top: 0,
right: 0,
child: GestureDetector(
onTap: () => onLongPress?.call(context),
child: AnimatedScale(
duration: FluffyThemes.animationDuration,
curve: FluffyThemes.animationCurve,
scale: listTileHovered ? 1.0 : 0.0,
child: Material(
color: backgroundColor,
borderRadius: BorderRadius.circular(16),
child: const Icon(
Icons.arrow_drop_down_circle_outlined,
size: 18,
), ),
), ),
), ),
), ),
], ),
), ],
), ),
), ),
), ),
title: Row( ),
children: <Widget>[ title: Row(
Expanded( children: <Widget>[
child: Text( Expanded(
displayname, child: Text(
maxLines: 1, displayname,
overflow: TextOverflow.ellipsis, maxLines: 1,
softWrap: false, overflow: TextOverflow.ellipsis,
style: TextStyle( softWrap: false,
fontWeight: unread || room.hasNewMessages style: TextStyle(
? FontWeight.w500 fontWeight: unread || room.hasNewMessages
: null, ? FontWeight.w500
), : null,
), ),
), ),
if (isMuted) ),
const Padding( if (isMuted)
padding: EdgeInsets.only(left: 4.0), const Padding(
child: Icon( padding: EdgeInsets.only(left: 4.0),
Icons.notifications_off_outlined, child: Icon(
size: 16, Icons.notifications_off_outlined,
), size: 16,
), ),
if (room.isFavourite) ),
Padding( if (room.isFavourite)
padding: EdgeInsets.only( Padding(
right: hasNotifications ? 4.0 : 0.0, padding: EdgeInsets.only(
), right: hasNotifications ? 4.0 : 0.0,
child: Icon(
Icons.push_pin,
size: 16,
color: theme.colorScheme.primary,
),
), ),
if (!room.isSpace && child: Icon(
lastEvent != null && Icons.push_pin,
room.membership != Membership.invite) size: 16,
Padding( color: theme.colorScheme.primary,
padding: const EdgeInsets.only(left: 4.0), ),
child: Text( ),
lastEvent.originServerTs.localizedTimeShort(context), if (!room.isSpace &&
style: TextStyle( lastEvent != null &&
fontSize: 12, room.membership != Membership.invite)
color: theme.colorScheme.outline, Padding(
), padding: const EdgeInsets.only(left: 4.0),
child: Text(
lastEvent.originServerTs.localizedTimeShort(context),
style: TextStyle(
fontSize: 12,
color: theme.colorScheme.outline,
), ),
), ),
),
],
),
subtitle: Row(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
if (typingText.isEmpty &&
ownMessage &&
room.lastEvent!.status.isSending) ...[
const SizedBox(
width: 16,
height: 16,
child: CircularProgressIndicator.adaptive(strokeWidth: 2),
),
const SizedBox(width: 4),
], ],
), AnimatedContainer(
subtitle: Row( width: typingText.isEmpty ? 0 : 18,
crossAxisAlignment: CrossAxisAlignment.start, clipBehavior: Clip.hardEdge,
mainAxisAlignment: MainAxisAlignment.center, decoration: const BoxDecoration(),
children: <Widget>[ duration: FluffyThemes.animationDuration,
if (typingText.isEmpty && curve: FluffyThemes.animationCurve,
ownMessage && padding: const EdgeInsets.only(right: 4),
room.lastEvent!.status.isSending) ...[ child: Icon(
const SizedBox( Icons.edit_outlined,
width: 16, color: theme.colorScheme.secondary,
height: 16, size: 14,
child:
CircularProgressIndicator.adaptive(strokeWidth: 2),
),
const SizedBox(width: 4),
],
AnimatedContainer(
width: typingText.isEmpty ? 0 : 18,
clipBehavior: Clip.hardEdge,
decoration: const BoxDecoration(),
duration: FluffyThemes.animationDuration,
curve: FluffyThemes.animationCurve,
padding: const EdgeInsets.only(right: 4),
child: Icon(
Icons.edit_outlined,
color: theme.colorScheme.secondary,
size: 14,
),
), ),
Expanded( ),
child: room.isSpace && room.membership == Membership.join Expanded(
? Text( child: room.isSpace && room.membership == Membership.join
L10n.of(context).countChatsAndCountParticipants( ? Text(
room.spaceChildren.length, L10n.of(context).countChatsAndCountParticipants(
(room.summary.mJoinedMemberCount ?? 1), room.spaceChildren.length,
), (room.summary.mJoinedMemberCount ?? 1),
style: ),
TextStyle(color: theme.colorScheme.outline), style: TextStyle(color: theme.colorScheme.outline),
) )
: typingText.isNotEmpty : typingText.isNotEmpty
? Text( ? Text(
typingText, typingText,
style: TextStyle( style: TextStyle(
color: theme.colorScheme.primary, color: theme.colorScheme.primary,
), ),
maxLines: 1, maxLines: 1,
softWrap: false,
)
: FutureBuilder(
key: ValueKey(
'${lastEvent?.eventId}_${lastEvent?.type}_${lastEvent?.redacted}',
),
future: needLastEventSender
? lastEvent.calcLocalizedBody(
MatrixLocals(L10n.of(context)),
hideReply: true,
hideEdit: true,
plaintextBody: true,
removeMarkdown: true,
withSenderNamePrefix: (!isDirectChat ||
directChatMatrixId !=
room.lastEvent?.senderId),
)
: null,
initialData:
lastEvent?.calcLocalizedBodyFallback(
MatrixLocals(L10n.of(context)),
hideReply: true,
hideEdit: true,
plaintextBody: true,
removeMarkdown: true,
withSenderNamePrefix: (!isDirectChat ||
directChatMatrixId !=
room.lastEvent?.senderId),
),
builder: (context, snapshot) => Text(
room.membership == Membership.invite
? room
.getState(
EventTypes.RoomMember,
room.client.userID!,
)
?.content
.tryGet<String>('reason') ??
(isDirectChat
? L10n.of(context).newChatRequest
: L10n.of(context)
.inviteGroupChat)
: snapshot.data ??
L10n.of(context).emptyChat,
softWrap: false, softWrap: false,
) maxLines: room.notificationCount >= 1 ? 2 : 1,
: FutureBuilder( overflow: TextOverflow.ellipsis,
key: ValueKey( style: TextStyle(
'${lastEvent?.eventId}_${lastEvent?.type}_${lastEvent?.redacted}', color: unread || room.hasNewMessages
), ? theme.colorScheme.onSurface
future: needLastEventSender : theme.colorScheme.outline,
? lastEvent.calcLocalizedBody( decoration: room.lastEvent?.redacted == true
MatrixLocals(L10n.of(context)), ? TextDecoration.lineThrough
hideReply: true, : null,
hideEdit: true,
plaintextBody: true,
removeMarkdown: true,
withSenderNamePrefix:
(!isDirectChat ||
directChatMatrixId !=
room.lastEvent?.senderId),
)
: null,
initialData:
lastEvent?.calcLocalizedBodyFallback(
MatrixLocals(L10n.of(context)),
hideReply: true,
hideEdit: true,
plaintextBody: true,
removeMarkdown: true,
withSenderNamePrefix: (!isDirectChat ||
directChatMatrixId !=
room.lastEvent?.senderId),
),
builder: (context, snapshot) => Text(
room.membership == Membership.invite
? room
.getState(
EventTypes.RoomMember,
room.client.userID!,
)
?.content
.tryGet<String>('reason') ??
(isDirectChat
? L10n.of(context)
.newChatRequest
: L10n.of(context)
.inviteGroupChat)
: snapshot.data ??
L10n.of(context).emptyChat,
softWrap: false,
maxLines:
room.notificationCount >= 1 ? 2 : 1,
overflow: TextOverflow.ellipsis,
style: TextStyle(
color: unread || room.hasNewMessages
? theme.colorScheme.onSurface
: theme.colorScheme.outline,
decoration:
room.lastEvent?.redacted == true
? TextDecoration.lineThrough
: null,
),
), ),
), ),
),
const SizedBox(width: 8),
AnimatedContainer(
duration: FluffyThemes.animationDuration,
curve: FluffyThemes.animationCurve,
alignment: Alignment.center,
padding: const EdgeInsets.symmetric(horizontal: 7),
height: unreadBubbleSize,
width:
!hasNotifications && !unread && !room.hasNewMessages
? 0
: (unreadBubbleSize - 9) *
room.notificationCount.toString().length +
9,
decoration: BoxDecoration(
color: room.highlightCount > 0 ||
room.membership == Membership.invite
? theme.colorScheme.error
: hasNotifications || room.markedUnread
? theme.colorScheme.primary
: theme.colorScheme.primaryContainer,
borderRadius: BorderRadius.circular(7),
),
child: hasNotifications
? Text(
room.notificationCount.toString(),
style: TextStyle(
color: room.highlightCount > 0 ||
room.membership == Membership.invite
? theme.colorScheme.onError
: hasNotifications
? theme.colorScheme.onPrimary
: theme.colorScheme.onPrimaryContainer,
fontSize: 13,
fontWeight: FontWeight.w500,
), ),
textAlign: TextAlign.center, ),
) const SizedBox(width: 8),
: const SizedBox.shrink(), AnimatedContainer(
duration: FluffyThemes.animationDuration,
curve: FluffyThemes.animationCurve,
alignment: Alignment.center,
padding: const EdgeInsets.symmetric(horizontal: 7),
height: unreadBubbleSize,
width: !hasNotifications && !unread && !room.hasNewMessages
? 0
: (unreadBubbleSize - 9) *
room.notificationCount.toString().length +
9,
decoration: BoxDecoration(
color: room.highlightCount > 0 ||
room.membership == Membership.invite
? theme.colorScheme.error
: hasNotifications || room.markedUnread
? theme.colorScheme.primary
: theme.colorScheme.primaryContainer,
borderRadius: BorderRadius.circular(7),
), ),
], child: hasNotifications
), ? Text(
onTap: onTap, room.notificationCount.toString(),
trailing: onForget == null style: TextStyle(
? null color: room.highlightCount > 0 ||
: IconButton( room.membership == Membership.invite
icon: const Icon(Icons.delete_outlined), ? theme.colorScheme.onError
onPressed: onForget, : hasNotifications
), ? theme.colorScheme.onPrimary
: theme.colorScheme.onPrimaryContainer,
fontSize: 13,
fontWeight: FontWeight.w500,
),
textAlign: TextAlign.center,
)
: const SizedBox.shrink(),
),
],
), ),
onTap: onTap,
trailing: onForget == null
? null
: IconButton(
icon: const Icon(Icons.delete_outlined),
onPressed: onForget,
),
), ),
), ),
), ),

Loading…
Cancel
Save