🐛 Fix performance issue and recycle logic issue
This commit is contained in:
@@ -545,7 +545,9 @@ class ChatRoomScreen extends HookConsumerWidget {
|
|||||||
findChildIndexCallback: (key) {
|
findChildIndexCallback: (key) {
|
||||||
if (key is! ValueKey<String>) return null;
|
if (key is! ValueKey<String>) return null;
|
||||||
final messageId = key.value.substring(messageKeyPrefix.length);
|
final messageId = key.value.substring(messageKeyPrefix.length);
|
||||||
final index = messageList.indexWhere((m) => m.id == messageId);
|
final index = messageList.indexWhere(
|
||||||
|
(m) => (m.nonce ?? m.id) == messageId,
|
||||||
|
);
|
||||||
// Return null for invalid indices to let SuperListView handle it properly
|
// Return null for invalid indices to let SuperListView handle it properly
|
||||||
return index >= 0 ? index : null;
|
return index >= 0 ? index : null;
|
||||||
},
|
},
|
||||||
@@ -564,13 +566,13 @@ class ChatRoomScreen extends HookConsumerWidget {
|
|||||||
3;
|
3;
|
||||||
|
|
||||||
// Use a stable animation key that doesn't change during message lifecycle
|
// Use a stable animation key that doesn't change during message lifecycle
|
||||||
final animationKey = Key('message-anim-${message.nonce ?? message.id}');
|
final key = Key('$messageKeyPrefix${message.nonce ?? message.id}');
|
||||||
|
|
||||||
final messageWidget = chatIdentity.when(
|
final messageWidget = chatIdentity.when(
|
||||||
skipError: true,
|
skipError: true,
|
||||||
data:
|
data:
|
||||||
(identity) => MessageItem(
|
(identity) => MessageItem(
|
||||||
key: Key('$messageKeyPrefix${message.nonce ?? message.id}'),
|
key: settings.disableAnimation ? key : null,
|
||||||
message: message,
|
message: message,
|
||||||
isCurrentUser: identity?.id == message.senderId,
|
isCurrentUser: identity?.id == message.senderId,
|
||||||
onAction: (action) {
|
onAction: (action) {
|
||||||
@@ -621,7 +623,7 @@ class ChatRoomScreen extends HookConsumerWidget {
|
|||||||
return settings.disableAnimation
|
return settings.disableAnimation
|
||||||
? messageWidget
|
? messageWidget
|
||||||
: TweenAnimationBuilder<double>(
|
: TweenAnimationBuilder<double>(
|
||||||
key: animationKey,
|
key: key,
|
||||||
tween: Tween<double>(begin: 0.0, end: 1.0),
|
tween: Tween<double>(begin: 0.0, end: 1.0),
|
||||||
duration: Duration(
|
duration: Duration(
|
||||||
milliseconds: 400 + (index % 5) * 50,
|
milliseconds: 400 + (index % 5) * 50,
|
||||||
|
Reference in New Issue
Block a user