From 53a9cc78a3798c2f3a4670f37b1b4973838156ed Mon Sep 17 00:00:00 2001 From: Alan Silva Date: Sat, 7 Nov 2026 19:40:57 +0000 Subject: [PATCH] Preview quick switch styles with the real local workspace --- .../settings/quick_switch_preview.dart | 174 +++++++++++++++++ .../settings_quick_switch_control.dart | 3 + .../list_detail_consistency_test.dart | 11 +- .../settings/quick_switch_preview_test.dart | 61 ++++++ .../settings_animation_section_test.dart | 10 +- .../settings_quick_switch_control_test.dart | 14 +- .../examples/settings-animation-library.json | 179 ++++++++++++++++++ 7 files changed, 441 insertions(+), 11 deletions(-) create mode 100644 app/lib/features/settings/quick_switch_preview.dart create mode 100644 app/test/features/settings/quick_switch_preview_test.dart create mode 100644 app/tool/capture/examples/settings-animation-library.json diff --git a/app/lib/features/settings/quick_switch_preview.dart b/app/lib/features/settings/quick_switch_preview.dart new file mode 100644 index 00000000..0e54b8d2 --- /dev/null +++ b/app/lib/features/settings/quick_switch_preview.dart @@ -0,0 +1,174 @@ +import 'package:flutter/cupertino.dart'; +import 'package:flutter/material.dart'; +import '../../ui/motion/quick_switch_animation.dart'; +import '../chat/workspace/chat_workspace.dart'; +import 'settings_theme.dart'; + +/// The real workspace renderer, with local miniature chats. Previewing never +/// opens an operator chat, changes a saved pane layout or contacts the server. +class QuickSwitchPreview extends StatefulWidget { + const QuickSwitchPreview({super.key, required this.animation}); + final QuickSwitchAnimation animation; + + @override + State createState() => _QuickSwitchPreviewState(); +} + +class _QuickSwitchPreviewState extends State { + late final ChatWorkspaceController _panes; + + @override + void initState() { + super.initState(); + _panes = ChatWorkspaceController()..open('First chat'); + _panes.splitActive('Second chat', ChatSplitAxis.horizontal); + _schedulePreview(); + } + + @override + void didUpdateWidget(QuickSwitchPreview oldWidget) { + super.didUpdateWidget(oldWidget); + if (oldWidget.animation != widget.animation) _schedulePreview(); + } + + void _schedulePreview() { + WidgetsBinding.instance.addPostFrameCallback((_) { + if (mounted && !MediaQuery.disableAnimationsOf(context)) _replay(); + }); + } + + void _replay() { + final next = _panes.panes.firstWhere((p) => p.id != _panes.activePaneId); + _panes.activate(next.id); + } + + @override + void dispose() { + _panes.dispose(); + super.dispose(); + } + + @override + Widget build(BuildContext context) { + final reduced = MediaQuery.disableAnimationsOf(context); + final cupertino = usesCupertinoControls(context); + return Column( + crossAxisAlignment: CrossAxisAlignment.stretch, + children: [ + Wrap( + alignment: WrapAlignment.spaceBetween, + crossAxisAlignment: WrapCrossAlignment.center, + children: [ + Text('Preview', style: settingsTextStyle(context, title: true)), + cupertino + ? CupertinoButton( + onPressed: reduced ? null : _replay, + child: const Text('Replay animation'), + ) + : TextButton.icon( + onPressed: reduced ? null : _replay, + icon: const Icon(Icons.replay), + label: const Text('Replay animation'), + ), + ], + ), + Center( + child: ConstrainedBox( + constraints: const BoxConstraints(maxWidth: 420), + child: AspectRatio( + aspectRatio: 1.6, + child: Semantics( + identifier: 'quick-switch-preview', + label: '${widget.animation.label} animation preview', + image: true, + child: ExcludeSemantics( + child: IgnorePointer( + child: ClipRRect( + borderRadius: BorderRadius.circular(12), + child: ChatWorkspace( + controller: _panes, + animationStyle: widget.animation, + shortcutsEnabled: false, + singlePane: true, + mobilePeeks: true, + paneBuilder: (context, pane, active) => _PreviewChat( + title: pane.sessionId, + alternate: pane.sessionId == 'Second chat', + ), + ), + ), + ), + ), + ), + ), + ), + ), + if (reduced) + const Padding( + padding: EdgeInsets.only(top: 8), + child: Text('Reduced motion is enabled. Preview stays still.'), + ), + ], + ); + } +} + +class _PreviewChat extends StatelessWidget { + const _PreviewChat({required this.title, required this.alternate}); + final String title; + final bool alternate; + + @override + Widget build(BuildContext context) { + final cupertino = usesCupertinoControls(context); + final color = cupertino + ? (alternate ? CupertinoColors.systemTeal : CupertinoColors.systemBlue) + .resolveFrom(context) + : (alternate + ? Theme.of(context).colorScheme.tertiary + : Theme.of(context).colorScheme.primary); + final background = cupertino + ? CupertinoColors.secondarySystemGroupedBackground.resolveFrom(context) + : Theme.of(context).colorScheme.surfaceContainerHigh; + return DecoratedBox( + decoration: BoxDecoration( + color: background, + border: Border.all(color: color.withValues(alpha: .5)), + borderRadius: BorderRadius.circular(12), + ), + child: LayoutBuilder( + builder: (context, constraints) => SingleChildScrollView( + child: Padding( + padding: const EdgeInsets.all(12), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text(title, style: settingsTextStyle(context, title: true)), + if (constraints.maxHeight > 80) ...[ + const SizedBox(height: 12), + for (final width in [0.65, 0.85, 0.5]) + Padding( + padding: const EdgeInsets.only(bottom: 8), + child: FractionallySizedBox( + widthFactor: width, + child: SizedBox( + height: 8, + child: ColoredBox( + color: color.withValues(alpha: .18), + ), + ), + ), + ), + Text( + 'Draft a reply…', + style: settingsTextStyle(context, secondary: true), + ), + ], + ], + ), + ), + ), + ), + ); + } +} diff --git a/app/lib/features/settings/settings_quick_switch_control.dart b/app/lib/features/settings/settings_quick_switch_control.dart index a2f37df8..514d4bd5 100644 --- a/app/lib/features/settings/settings_quick_switch_control.dart +++ b/app/lib/features/settings/settings_quick_switch_control.dart @@ -3,6 +3,7 @@ import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import '../../ui/motion/quick_switch_animation.dart'; import 'settings_theme.dart'; +import 'quick_switch_preview.dart'; class SettingsQuickSwitchControl extends StatelessWidget { const SettingsQuickSwitchControl({super.key, required this.controller}); @@ -68,6 +69,8 @@ class SettingsQuickSwitchControl extends StatelessWidget { }, ), Text(controller.value.description), + const SizedBox(height: 8), + QuickSwitchPreview(animation: controller.value), if (controller.saveFailed) Text( 'Could not save; applies until reload.', diff --git a/app/test/application/list_detail_consistency_test.dart b/app/test/application/list_detail_consistency_test.dart index 701acf38..9ea22c32 100644 --- a/app/test/application/list_detail_consistency_test.dart +++ b/app/test/application/list_detail_consistency_test.dart @@ -187,7 +187,7 @@ void main() { selected, reason: '$destination: $rowKey after opening $key', ); - // Every list uses the shared row and its highlight. + // Every list retains shared row semantics; features may supply their own fill. final context = tester.element(row); expect(tester.widget(row).selected, selected); final surface = find.descendant( @@ -199,10 +199,11 @@ void main() { ? tester.widget(surface).color : tester.widget(surface).color, selected - ? AppListRow.selectedColor( - context, - cupertino: cupertino, - ) + ? tester.widget(row).selectedFill ?? + AppListRow.selectedColor( + context, + cupertino: cupertino, + ) : const Color(0x00000000), ); } diff --git a/app/test/features/settings/quick_switch_preview_test.dart b/app/test/features/settings/quick_switch_preview_test.dart new file mode 100644 index 00000000..360900d0 --- /dev/null +++ b/app/test/features/settings/quick_switch_preview_test.dart @@ -0,0 +1,61 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:pipelines_app/features/settings/quick_switch_preview.dart'; +import 'package:pipelines_app/features/chat/workspace/chat_workspace.dart'; +import 'package:pipelines_app/ui/motion/quick_switch_animation.dart'; + +Widget _host(QuickSwitchAnimation style, {bool reduced = false}) => MaterialApp( + home: Scaffold( + body: MediaQuery( + data: MediaQueryData(disableAnimations: reduced), + child: SingleChildScrollView(child: QuickSwitchPreview(animation: style)), + ), + ), +); + +void main() { + testWidgets('preview replays the real local workspace with chosen style', ( + tester, + ) async { + await tester.pumpWidget(_host(QuickSwitchAnimation.cardStack)); + await tester.pumpAndSettle(); + final workspace = tester.widget(find.byType(ChatWorkspace)); + expect(workspace.animationStyle, QuickSwitchAnimation.cardStack); + expect(workspace.controller.paneCount, 2); + final active = workspace.controller.activePaneId; + await tester.tap(find.text('Replay animation')); + await tester.pumpAndSettle(); + expect(workspace.controller.activePaneId, isNot(active)); + expect(tester.binding.transientCallbackCount, 0); + await tester.pumpWidget(_host(QuickSwitchAnimation.swap)); + await tester.pumpAndSettle(); + expect( + tester.widget(find.byType(ChatWorkspace)).controller, + same(workspace.controller), + ); + expect( + tester.widget(find.byType(ChatWorkspace)).animationStyle, + QuickSwitchAnimation.swap, + ); + expect(tester.takeException(), isNull); + }); + + testWidgets('reduced-motion preview remains still and disables replay', ( + tester, + ) async { + await tester.pumpWidget( + _host(QuickSwitchAnimation.cardStack, reduced: true), + ); + await tester.pumpAndSettle(); + expect( + find.text('Reduced motion is enabled. Preview stays still.'), + findsOneWidget, + ); + final button = tester.widget( + find.widgetWithText(TextButton, 'Replay animation'), + ); + expect(button.onPressed, isNull); + expect(tester.binding.transientCallbackCount, 0); + expect(tester.takeException(), isNull); + }); +} diff --git a/app/test/features/settings/settings_animation_section_test.dart b/app/test/features/settings/settings_animation_section_test.dart index fc0e9dc3..8f093a7b 100644 --- a/app/test/features/settings/settings_animation_section_test.dart +++ b/app/test/features/settings/settings_animation_section_test.dart @@ -27,8 +27,14 @@ void main() { final section = SettingsAnimationSection(controller: controller); await tester.pumpWidget( cupertino - ? CupertinoApp(home: CupertinoPageScaffold(child: section)) - : MaterialApp(home: Scaffold(body: section)), + ? CupertinoApp( + home: CupertinoPageScaffold( + child: SingleChildScrollView(child: section), + ), + ) + : MaterialApp( + home: Scaffold(body: SingleChildScrollView(child: section)), + ), ); if (cupertino) { final slider = tester.widget( diff --git a/app/test/features/settings/settings_quick_switch_control_test.dart b/app/test/features/settings/settings_quick_switch_control_test.dart index 44c26886..05805b0e 100644 --- a/app/test/features/settings/settings_quick_switch_control_test.dart +++ b/app/test/features/settings/settings_quick_switch_control_test.dart @@ -31,8 +31,14 @@ void main() { ); await tester.pumpWidget( cupertino - ? CupertinoApp(home: CupertinoPageScaffold(child: child)) - : MaterialApp(home: Scaffold(body: child)), + ? CupertinoApp( + home: CupertinoPageScaffold( + child: SingleChildScrollView(child: child), + ), + ) + : MaterialApp( + home: Scaffold(body: SingleChildScrollView(child: child)), + ), ); expect(find.text('Quick switch animation'), findsOneWidget); expect( @@ -41,7 +47,7 @@ void main() { ); await tester.tap(find.text('Tape')); await tester.pumpAndSettle(); - await tester.tap(find.text('Card stack').last); + await tester.tap(find.text('Card deck').last); await tester.pumpAndSettle(); expect(controller.value, QuickSwitchAnimation.cardStack); expect(store.saved, 'cardStack'); @@ -50,7 +56,7 @@ void main() { findsOneWidget, ); store.success = false; - await tester.tap(find.text('Card stack')); + await tester.tap(find.text('Card deck')); await tester.pumpAndSettle(); await tester.tap(find.text('Swap').last); await tester.pumpAndSettle(); diff --git a/app/tool/capture/examples/settings-animation-library.json b/app/tool/capture/examples/settings-animation-library.json new file mode 100644 index 00000000..854ed8dd --- /dev/null +++ b/app/tool/capture/examples/settings-animation-library.json @@ -0,0 +1,179 @@ +{ + "size": "560x1000", + "platform": "material", + "theme": "dark", + "params": "chats=4&colors=1&header=1&rich=1", + "steps": [ + { + "open": "/settings" + }, + { + "shot": "appearance" + }, + { + "click": "Tape" + }, + { + "shot": "all-animation-options" + }, + { + "click": "Card deck" + }, + { + "film": "Replay animation", + "name": "card-deck", + "ms": 900, + "frames": 6 + }, + { + "click": "Card deck" + }, + { + "click": "Deck slide" + }, + { + "film": "Replay animation", + "name": "deck-slide", + "ms": 900, + "frames": 6 + }, + { + "click": "Deck slide" + }, + { + "click": "Fan" + }, + { + "film": "Replay animation", + "name": "fan", + "ms": 900, + "frames": 6 + }, + { + "click": "Fan" + }, + { + "click": "Slide" + }, + { + "film": "Replay animation", + "name": "slide", + "ms": 900, + "frames": 6 + }, + { + "click": "Slide" + }, + { + "click": "Push" + }, + { + "film": "Replay animation", + "name": "push", + "ms": 900, + "frames": 6 + }, + { + "click": "Push" + }, + { + "click": "Crossfade" + }, + { + "film": "Replay animation", + "name": "crossfade", + "ms": 900, + "frames": 6 + }, + { + "click": "Crossfade" + }, + { + "click": "Zoom" + }, + { + "film": "Replay animation", + "name": "zoom", + "ms": 900, + "frames": 6 + }, + { + "click": "Zoom" + }, + { + "click": "Flip" + }, + { + "film": "Replay animation", + "name": "flip", + "ms": 900, + "frames": 6 + }, + { + "click": "Flip" + }, + { + "click": "Rolodex" + }, + { + "film": "Replay animation", + "name": "rolodex", + "ms": 900, + "frames": 6 + }, + { + "click": "Rolodex" + }, + { + "click": "Swap" + }, + { + "film": "Replay animation", + "name": "swap", + "ms": 900, + "frames": 6 + }, + { + "click": "Swap" + }, + { + "click": "Tape" + }, + { + "film": "Replay animation", + "name": "tape", + "ms": 900, + "frames": 6 + }, + { + "click": "Connection" + }, + { + "shot": "connection" + }, + { + "click": "Notifications" + }, + { + "shot": "notifications" + }, + { + "click": "Tools" + }, + { + "shot": "tools" + }, + { + "click": "Updates" + }, + { + "shot": "updates" + }, + { + "click": "Appearance" + }, + { + "shot": "appearance" + } + ] +}