diff --git a/app/lib/features/chat/ui/transcript/chat_response_pending.dart b/app/lib/features/chat/ui/transcript/chat_response_pending.dart index 621a077d..65bab79a 100644 --- a/app/lib/features/chat/ui/transcript/chat_response_pending.dart +++ b/app/lib/features/chat/ui/transcript/chat_response_pending.dart @@ -35,32 +35,58 @@ class _ChatResponsePendingState extends State } @override - Widget build(BuildContext context) => Semantics( - label: 'Assistant is responding', - liveRegion: true, - excludeSemantics: true, - child: AnimatedBuilder( - animation: _animation, - builder: (context, _) => Row( - mainAxisSize: MainAxisSize.min, - children: [ - for (var index = 0; index < 3; index++) - Opacity( - opacity: MediaQuery.disableAnimationsOf(context) - ? 1 - : 0.35 + - 0.65 * - (0.5 + - 0.5 * - math.sin( - 2 * - math.pi * - (_animation.value - index / 3), - )), - child: const Text('.'), - ), - ], + Widget build(BuildContext context) { + // Round dots sized from the surrounding text, so they sit on the text's + // middle (a period glyph sits on the baseline and reads low) and follow + // text scaling and colour. + final style = DefaultTextStyle.of(context).style; + final fontSize = MediaQuery.textScalerOf( + context, + ).scale(style.fontSize ?? 14); + final dot = fontSize * 0.3; + final color = style.color ?? const Color(0xFF808080); + return Semantics( + label: 'Assistant is responding', + liveRegion: true, + excludeSemantics: true, + child: SizedBox( + key: const Key('chat-response-pending-dots'), + height: fontSize, + child: AnimatedBuilder( + animation: _animation, + builder: (context, _) => Row( + mainAxisSize: MainAxisSize.min, + children: [ + for (var index = 0; index < 3; index++) + Padding( + padding: EdgeInsetsDirectional.only( + start: index == 0 ? 0 : dot * 0.6, + ), + child: Opacity( + opacity: MediaQuery.disableAnimationsOf(context) + ? 1 + : 0.35 + + 0.65 * + (0.5 + + 0.5 * + math.sin( + 2 * + math.pi * + (_animation.value - index / 3), + )), + child: DecoratedBox( + decoration: BoxDecoration( + color: color, + shape: BoxShape.circle, + ), + child: SizedBox.square(dimension: dot), + ), + ), + ), + ], + ), + ), ), - ), - ); + ); + } } diff --git a/app/test/features/chat/conversation/chat_response_pending_test.dart b/app/test/features/chat/conversation/chat_response_pending_test.dart index ccfe395f..d7d19717 100644 --- a/app/test/features/chat/conversation/chat_response_pending_test.dart +++ b/app/test/features/chat/conversation/chat_response_pending_test.dart @@ -194,8 +194,42 @@ void main() { ), ); await tester.pumpAndSettle(); - expect(find.text('.'), findsNWidgets(3)); + // Three steady dots, all fully drawn, with no animation scheduled. + final opacities = tester + .widgetList( + find.descendant( + of: find.byType(ChatResponsePending), + matching: find.byType(Opacity), + ), + ) + .map((widget) => widget.opacity); + expect(opacities, [1, 1, 1]); expect(find.bySemanticsLabel('Assistant is responding'), findsOneWidget); expect(tester.binding.hasScheduledFrame, isFalse); }); + + for (final cupertino in [false, true]) { + testWidgets('the pending dots sit on the activity text\'s middle ' + '($cupertino)', (tester) async { + final gateway = _Gateway(); + addTearDown(gateway.close); + await _host(tester, gateway, cupertino: cupertino); + await _send(tester); + + final dots = tester.getRect( + find.byKey(const Key('chat-response-pending-dots')), + ); + final label = tester.getRect(find.textContaining('Thinking')); + expect(dots.center.dy, closeTo(label.center.dy, 1)); + expect(dots.height, lessThanOrEqualTo(label.height)); + // Round dots, not baseline glyphs. + expect( + find.descendant( + of: find.byType(ChatResponsePending), + matching: find.text('.'), + ), + findsNothing, + ); + }); + } }