Dim inactive chat panes
Make inactive split panes visibly recede while preserving readability and pointer activation. Add reduced-motion behavior and widget coverage for pane dimming, activation, and single-pane layouts.
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../../ui/motion/motion.dart';
|
||||
|
||||
/// The opacity of the surface scrim over an inactive split pane. The pane's
|
||||
/// transcript and bars keep reading through it at about two thirds emphasis.
|
||||
const double chatPaneDimOpacity = 0.35;
|
||||
|
||||
/// Covers a pane that is not the active one with the theme's surface colour,
|
||||
/// so the active pane reads as the one in focus. The scrim ignores pointers:
|
||||
/// taps reach the pane's content, and its activation listener still runs.
|
||||
/// Reduced motion switches the scrim at once; otherwise it fades briefly.
|
||||
class ChatPaneDim extends StatelessWidget {
|
||||
const ChatPaneDim({super.key, required this.dimmed, required this.child});
|
||||
|
||||
final bool dimmed;
|
||||
final Widget child;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final surface = Theme.of(context).colorScheme.surface;
|
||||
return Stack(
|
||||
fit: StackFit.passthrough,
|
||||
children: [
|
||||
child,
|
||||
Positioned.fill(
|
||||
child: IgnorePointer(
|
||||
child: AnimatedContainer(
|
||||
key: const ValueKey('chat-pane-dim-scrim'),
|
||||
duration: Motion.of(context, Motion.standard),
|
||||
curve: Motion.curve,
|
||||
// The clear end keeps the surface hue, so the fade never greys.
|
||||
color: dimmed
|
||||
? surface.withValues(alpha: chatPaneDimOpacity)
|
||||
: surface.withValues(alpha: 0),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -15,6 +15,7 @@ import 'chat_pane_move_motion.dart';
|
||||
import 'chat_pane_move_shortcuts.dart';
|
||||
import 'chat_pane_switch_motion.dart';
|
||||
import 'chat_pane_backdrop.dart';
|
||||
import 'chat_pane_dim.dart';
|
||||
import 'chat_workspace_pane_scope.dart';
|
||||
import 'chat_workspace_surface.dart';
|
||||
import '../../../ui/input/keyboard_owner.dart';
|
||||
@@ -509,8 +510,11 @@ class _ChatWorkspaceState extends State<ChatWorkspace>
|
||||
onPreferredWidthChanged: (width) =>
|
||||
_reportPaneExtraWidth(pane.id, width),
|
||||
child: Builder(
|
||||
builder: (paneContext) =>
|
||||
widget.paneBuilder(paneContext, pane, active),
|
||||
builder: (paneContext) => ChatPaneDim(
|
||||
// A single pane is always the active one, so it never dims.
|
||||
dimmed: widget.controller.paneCount > 1 && !active,
|
||||
child: widget.paneBuilder(paneContext, pane, active),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
# Dim inactive chat panes
|
||||
|
||||
## Change
|
||||
- `lib/features/chat/workspace/chat_pane_dim.dart` (new): `ChatPaneDim` lays an
|
||||
`IgnorePointer` surface scrim over a pane's content. The scrim is the theme's
|
||||
`colorScheme.surface` at `chatPaneDimOpacity` (0.35), so content reads at
|
||||
about 65% emphasis in light and dark. Its colour fades over `Motion.standard`;
|
||||
`Motion.of` returns zero under reduced motion, so the change is immediate.
|
||||
- `lib/features/chat/workspace/chat_workspace.dart`: `_paneContent` wraps each
|
||||
pane's built content in `ChatPaneDim(dimmed: paneCount > 1 && !active)`.
|
||||
Pointer activation (the pane `Listener`), focus and the action bar's
|
||||
existing tint (`ChatPaneActivity`) are unchanged. The scrim ignores pointers,
|
||||
so a tap reaches the content beneath it and still activates the pane.
|
||||
- The optional primary outline is not added. The active pane already has its
|
||||
chat-coloured foreground border (`chat_screen_workspace.dart`).
|
||||
|
||||
## Tests
|
||||
- `test/features/chat/workspace/chat_pane_dim_test.dart` (new, 7 tests):
|
||||
two panes dim only the inactive one; three panes dim both inactive panes;
|
||||
a single pane is never dimmed; a tap on an inactive input activates it and
|
||||
focuses its editable text; a tap on bare space in an inactive pane activates
|
||||
it; reduced motion gives a zero duration and an immediate switch; default
|
||||
motion uses `Motion.standard`.
|
||||
- Existing users of `ChatWorkspace` also run: `chat_workspace_test`,
|
||||
`chat_pane_move_test`, `chat_center_stage_test`, `chat_switch_styles_test`,
|
||||
`chat_mobile_panes_test`, `chat_peek_identity_test`, and
|
||||
`test/features/settings/quick_switch_preview_test.dart`.
|
||||
|
||||
Command (from `app/`):
|
||||
`tool/memwatch/full.sh 'test/features/chat/workspace/chat_pane_dim_test.dart test/features/chat/workspace/chat_workspace_test.dart test/features/chat/workspace/chat_pane_move_test.dart test/features/chat/workspace/chat_center_stage_test.dart test/features/chat/workspace/chat_switch_styles_test.dart test/features/chat/workspace/chat_mobile_panes_test.dart test/features/chat/workspace/chat_peek_identity_test.dart test/features/settings/quick_switch_preview_test.dart'`
|
||||
|
||||
Result: `PASS: 70 passed, 0 failed, 0 skipped; peak 1329 MB; 11s; exit 0`.
|
||||
|
||||
Analyzer (`tool/analyze.sh`): clean, exit 0.
|
||||
|
||||
## Not done here
|
||||
- No captures. The 2- and 3-pane light and dark captures belong to ui-review
|
||||
(`tool/capture/`), and no UI was built or run in this stage.
|
||||
- No test or capture covers the chat screen's full path (`chat_screen_workspace.dart`).
|
||||
The dim comes from `ChatWorkspace`, which that screen uses, so it applies there too.
|
||||
@@ -0,0 +1,182 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/features/chat/workspace/chat_pane_dim.dart';
|
||||
import 'package:pipelines_app/features/chat/workspace/chat_workspace.dart';
|
||||
import 'package:pipelines_app/ui/motion/motion.dart';
|
||||
|
||||
Widget host(
|
||||
ChatWorkspaceController controller, {
|
||||
bool disableAnimations = false,
|
||||
}) => MaterialApp(
|
||||
home: Scaffold(
|
||||
body: SizedBox(
|
||||
width: 1200,
|
||||
height: 900,
|
||||
child: Builder(
|
||||
builder: (context) => MediaQuery(
|
||||
data: MediaQuery.of(
|
||||
context,
|
||||
).copyWith(disableAnimations: disableAnimations),
|
||||
child: ChatWorkspace(
|
||||
controller: controller,
|
||||
paneBuilder: (_, pane, active) =>
|
||||
TextField(key: ValueKey('input-${pane.sessionId}')),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
/// The dim overlay wrapping the pane that shows [session].
|
||||
Finder dimOf(String session) => find.ancestor(
|
||||
of: find.byKey(ValueKey('input-$session')),
|
||||
matching: find.byType(ChatPaneDim),
|
||||
);
|
||||
|
||||
/// The alpha of the scrim over [session]'s pane: zero when the pane is clear.
|
||||
double scrimAlpha(WidgetTester tester, String session) {
|
||||
final scrim = find.descendant(
|
||||
of: dimOf(session),
|
||||
matching: find.byKey(const ValueKey('chat-pane-dim-scrim')),
|
||||
);
|
||||
// AnimatedContainer builds a Container whose BoxDecoration holds the colour.
|
||||
final container = tester.widget<Container>(
|
||||
find.descendant(of: scrim, matching: find.byType(Container)),
|
||||
);
|
||||
final decoration = container.decoration as BoxDecoration?;
|
||||
return (decoration?.color ?? container.color ?? const Color(0x00000000)).a;
|
||||
}
|
||||
|
||||
void usePhoneSizedView(WidgetTester tester) {
|
||||
tester.view.physicalSize = const Size(1200, 900);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.resetPhysicalSize);
|
||||
addTearDown(tester.view.resetDevicePixelRatio);
|
||||
}
|
||||
|
||||
void main() {
|
||||
testWidgets('two panes: the inactive pane is dimmed and the active is not', (
|
||||
tester,
|
||||
) async {
|
||||
final controller = ChatWorkspaceController()
|
||||
..open('one')
|
||||
..splitActive('two', ChatSplitAxis.horizontal);
|
||||
addTearDown(controller.dispose);
|
||||
await tester.pumpWidget(host(controller));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(controller.activePane?.sessionId, 'two');
|
||||
expect(scrimAlpha(tester, 'one'), closeTo(chatPaneDimOpacity, 0.001));
|
||||
expect(scrimAlpha(tester, 'two'), 0);
|
||||
});
|
||||
|
||||
testWidgets('three panes: every inactive pane is dimmed, the active is not', (
|
||||
tester,
|
||||
) async {
|
||||
final controller = ChatWorkspaceController()
|
||||
..open('one')
|
||||
..splitActive('two', ChatSplitAxis.horizontal)
|
||||
..splitActive('three', ChatSplitAxis.horizontal);
|
||||
addTearDown(controller.dispose);
|
||||
await tester.pumpWidget(host(controller));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(controller.activePane?.sessionId, 'three');
|
||||
expect(scrimAlpha(tester, 'one'), closeTo(chatPaneDimOpacity, 0.001));
|
||||
expect(scrimAlpha(tester, 'two'), closeTo(chatPaneDimOpacity, 0.001));
|
||||
expect(scrimAlpha(tester, 'three'), 0);
|
||||
});
|
||||
|
||||
testWidgets('a single pane is never dimmed', (tester) async {
|
||||
final controller = ChatWorkspaceController()..open('one');
|
||||
addTearDown(controller.dispose);
|
||||
await tester.pumpWidget(host(controller));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(scrimAlpha(tester, 'one'), 0);
|
||||
});
|
||||
|
||||
testWidgets('tapping an inactive pane activates it and focuses its input', (
|
||||
tester,
|
||||
) async {
|
||||
usePhoneSizedView(tester);
|
||||
final controller = ChatWorkspaceController()
|
||||
..open('one')
|
||||
..splitActive('two', ChatSplitAxis.horizontal);
|
||||
addTearDown(controller.dispose);
|
||||
await tester.pumpWidget(host(controller));
|
||||
await tester.pumpAndSettle();
|
||||
final first = controller.panes.first.id;
|
||||
expect(controller.activePaneId, isNot(first));
|
||||
|
||||
await tester.tap(find.byKey(const ValueKey('input-one')));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(controller.activePaneId, first);
|
||||
expect(scrimAlpha(tester, 'one'), 0);
|
||||
expect(scrimAlpha(tester, 'two'), closeTo(chatPaneDimOpacity, 0.001));
|
||||
final editable = tester.widget<EditableText>(
|
||||
find.descendant(
|
||||
of: find.byKey(const ValueKey('input-one')),
|
||||
matching: find.byType(EditableText),
|
||||
),
|
||||
);
|
||||
expect(editable.focusNode.hasFocus, isTrue);
|
||||
});
|
||||
|
||||
testWidgets('a tap on bare space in an inactive pane activates it', (
|
||||
tester,
|
||||
) async {
|
||||
usePhoneSizedView(tester);
|
||||
final controller = ChatWorkspaceController()
|
||||
..open('one')
|
||||
..splitActive('two', ChatSplitAxis.horizontal);
|
||||
addTearDown(controller.dispose);
|
||||
await tester.pumpWidget(host(controller));
|
||||
await tester.pumpAndSettle();
|
||||
final first = controller.panes.first.id;
|
||||
|
||||
final corner = tester.getTopLeft(dimOf('one')) + const Offset(2, 2);
|
||||
await tester.tapAt(corner);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(controller.activePaneId, first);
|
||||
});
|
||||
|
||||
testWidgets('reduced motion switches the dim at once, without a fade', (
|
||||
tester,
|
||||
) async {
|
||||
final controller = ChatWorkspaceController()
|
||||
..open('one')
|
||||
..splitActive('two', ChatSplitAxis.horizontal);
|
||||
addTearDown(controller.dispose);
|
||||
await tester.pumpWidget(host(controller, disableAnimations: true));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
final scrim = find.byKey(const ValueKey('chat-pane-dim-scrim')).first;
|
||||
expect(tester.widget<AnimatedContainer>(scrim).duration, Duration.zero);
|
||||
|
||||
controller.activate(controller.panes.first.id);
|
||||
await tester.pump();
|
||||
expect(scrimAlpha(tester, 'one'), 0);
|
||||
expect(scrimAlpha(tester, 'two'), closeTo(chatPaneDimOpacity, 0.001));
|
||||
});
|
||||
|
||||
testWidgets('motion is on by default: the dim fades over the standard time', (
|
||||
tester,
|
||||
) async {
|
||||
final controller = ChatWorkspaceController()
|
||||
..open('one')
|
||||
..splitActive('two', ChatSplitAxis.horizontal);
|
||||
addTearDown(controller.dispose);
|
||||
await tester.pumpWidget(host(controller));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
final scrim = find.byKey(const ValueKey('chat-pane-dim-scrim')).first;
|
||||
expect(
|
||||
tester.widget<AnimatedContainer>(scrim).duration,
|
||||
Motion.standard,
|
||||
);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user