From e7338534ebf61c23f989a2875b2033312e28ead6 Mon Sep 17 00:00:00 2001 From: Tom Brow Date: Sun, 18 Oct 2026 12:35:49 -0700 Subject: [PATCH] perf(mobile): skip send animation machinery for loaded history Signed-off-by: Tom Brow --- .../local_message_send_transition.dart | 31 +++++++++++- .../local_message_send_transition_test.dart | 49 +++++++++++++++++-- 2 files changed, 75 insertions(+), 5 deletions(-) diff --git a/mobile/lib/features/channels/local_message_send_transition.dart b/mobile/lib/features/channels/local_message_send_transition.dart index 23024701e7..c2f3ab17f0 100644 --- a/mobile/lib/features/channels/local_message_send_transition.dart +++ b/mobile/lib/features/channels/local_message_send_transition.dart @@ -68,12 +68,39 @@ class LocalMessageSendTransition extends HookConsumerWidget { @override Widget build(BuildContext context, WidgetRef ref) { + final reduceMotion = MediaQuery.disableAnimationsOf(context); + final needsAnimation = useMemoized( + () => animate && !reduceMotion, + const [], + ); + // Loaded history never needs a ticker, animation builder, or expanding row. + // Choose at mount: later claim or accessibility changes must not replay a + // settled entrance or remount media, selection, and other message state. + if (!needsAnimation) { + return LocalSendProgress(progress: 1, widthProgress: 1, child: child); + } + return _AnimatedLocalMessageSendTransition(transition: this); + } +} + +class _AnimatedLocalMessageSendTransition extends HookConsumerWidget { + const _AnimatedLocalMessageSendTransition({required this.transition}); + + final LocalMessageSendTransition transition; + + @override + Widget build(BuildContext context, WidgetRef ref) { + final animate = transition.animate; + final channelId = transition.channelId; + final messageId = transition.messageId; + final startOffsetFactor = transition.startOffsetFactor; + final child = transition.child; final origin = useMemoized( () => !animate || channelId == null || messageId == null ? null : ref - .read(localMessageSendAnimationProvider(channelId!).notifier) - .originFor(messageId!), + .read(localMessageSendAnimationProvider(channelId).notifier) + .originFor(messageId), const [], ); final reduceMotion = MediaQuery.disableAnimationsOf(context); diff --git a/mobile/test/features/channels/local_message_send_transition_test.dart b/mobile/test/features/channels/local_message_send_transition_test.dart index dfde7864f6..3b4d8742f3 100644 --- a/mobile/test/features/channels/local_message_send_transition_test.dart +++ b/mobile/test/features/channels/local_message_send_transition_test.dart @@ -64,6 +64,43 @@ void main() { isFalse, ); }); + testWidgets('loaded history has no send animation or row layout', ( + tester, + ) async { + await tester.pumpWidget(_testable(animate: false)); + final history = find.byType(LocalMessageSendTransition); + expect( + find.descendant(of: history, matching: find.byType(AnimatedBuilder)), + findsNothing, + ); + expect(find.byType(LocalSendRow), findsNothing); + expect(tester.getSize(history).height, 80); + expect( + tester.getSize(find.byKey(const ValueKey('avatar'))), + const Size(40, 40), + ); + }); + + testWidgets('enabling motion does not replay a settled entrance', ( + tester, + ) async { + await tester.pumpWidget(_testable(animate: true, reduceMotion: true)); + final avatar = tester.element(find.byKey(const ValueKey('avatar'))); + await tester.pumpWidget(_testable(animate: true, reduceMotion: false)); + expect(tester.element(find.byKey(const ValueKey('avatar'))), same(avatar)); + expect(tester.getSize(find.byType(LocalMessageSendTransition)).height, 80); + expect(find.byType(LocalSendRow), findsNothing); + }); + + testWidgets('expiring a send claim retains message state', (tester) async { + await tester.pumpWidget(_testable()); + await tester.pumpAndSettle(); + final avatar = tester.element(find.byKey(const ValueKey('avatar'))); + await tester.pumpWidget(_testable(animate: false)); + expect(tester.element(find.byKey(const ValueKey('avatar'))), same(avatar)); + expect(tester.getSize(find.byType(LocalMessageSendTransition)).height, 80); + }); + testWidgets('history moves up while the avatar remains anchored', ( tester, ) async { @@ -85,7 +122,7 @@ void main() { ), ); await tester.pumpAndSettle(); - expect(tester.getSize(find.byType(LocalSendRow)).height, 80); + expect(tester.getSize(find.byType(LocalMessageSendTransition)).height, 80); expect(tester.getRect(find.byKey(const ValueKey('avatar'))), avatar); expect( tester.getTopLeft(find.byKey(const ValueKey('history'))).dy, @@ -130,7 +167,10 @@ void main() { await tester.pumpWidget( _testable(animate: reduced, reduceMotion: reduced), ); - expect(tester.getSize(find.byType(LocalSendRow)).height, 80); + expect( + tester.getSize(find.byType(LocalMessageSendTransition)).height, + 80, + ); expect( tester .widget(find.byType(LocalSendProgress)) @@ -138,7 +178,10 @@ void main() { 1, ); await tester.pump(const Duration(milliseconds: 100)); - expect(tester.getSize(find.byType(LocalSendRow)).height, 80); + expect( + tester.getSize(find.byType(LocalMessageSendTransition)).height, + 80, + ); }); } }