diff --git a/app/lib/ui/layout/collapsible_list_section.dart b/app/lib/ui/layout/collapsible_list_section.dart index 41e49078..2887332e 100644 --- a/app/lib/ui/layout/collapsible_list_section.dart +++ b/app/lib/ui/layout/collapsible_list_section.dart @@ -73,22 +73,28 @@ class _CollapsibleListSectionState extends State { ), ), ); + final rows = _open + ? Column( + crossAxisAlignment: CrossAxisAlignment.stretch, + children: widget.children, + ) + : const SizedBox(width: double.infinity); + final duration = Motion.of(context, Motion.standard); return Column( crossAxisAlignment: CrossAxisAlignment.stretch, children: [ Padding(padding: const EdgeInsets.only(top: 8), child: heading), ClipRect( - child: AnimatedSize( - duration: Motion.of(context, Motion.standard), - curve: Motion.curve, - alignment: Alignment.topCenter, - child: _open - ? Column( - crossAxisAlignment: CrossAxisAlignment.stretch, - children: widget.children, - ) - : const SizedBox(width: double.infinity), - ), + // A zero-duration AnimatedSize can notify during its own layout when + // rows arrive asynchronously. Reduced motion should skip it entirely. + child: duration == Duration.zero + ? rows + : AnimatedSize( + duration: duration, + curve: Motion.curve, + alignment: Alignment.topCenter, + child: rows, + ), ), ], ); diff --git a/app/test/ui/layout/collapsible_list_section_test.dart b/app/test/ui/layout/collapsible_list_section_test.dart new file mode 100644 index 00000000..166dad2d --- /dev/null +++ b/app/test/ui/layout/collapsible_list_section_test.dart @@ -0,0 +1,46 @@ +import 'package:flutter/cupertino.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:pipelines_app/ui/layout/collapsible_list_section.dart'; + +void main() { + for (final cupertino in [false, true]) { + testWidgets( + 'reduced-motion groups accept asynchronous row changes without layout animation ($cupertino)', + (tester) async { + tester.platformDispatcher.accessibilityFeaturesTestValue = + const FakeAccessibilityFeatures(disableAnimations: true); + addTearDown( + tester.platformDispatcher.clearAccessibilityFeaturesTestValue, + ); + final rows = ValueNotifier(1); + addTearDown(rows.dispose); + final body = ValueListenableBuilder( + valueListenable: rows, + builder: (context, count, _) => SingleChildScrollView( + child: CollapsibleListSection( + title: 'Group', + count: count, + children: [for (var i = 0; i < count; i++) Text('Row $i')], + ), + ), + ); + await tester.pumpWidget( + cupertino + ? CupertinoApp(home: CupertinoPageScaffold(child: body)) + : MaterialApp(home: Scaffold(body: body)), + ); + await tester.pumpAndSettle(); + rows.value = 3; + await tester.pumpAndSettle(); + expect(find.text('Row 2'), findsOneWidget); + expect(find.byType(AnimatedSize), findsNothing); + expect(tester.takeException(), isNull); + await tester.tap(find.text('Group')); + await tester.pumpAndSettle(); + expect(find.text('Row 0'), findsNothing); + expect(tester.takeException(), isNull); + }, + ); + } +}