Keep chat bodies opaque and animate only a small focus accent

This commit is contained in:
2026-11-06 22:14:50 +00:00
parent cad9bbd0f7
commit 8473b24d1b
2 changed files with 111 additions and 62 deletions
@@ -1,6 +1,8 @@
import 'package:flutter/semantics.dart';
import 'dart:math' as math;
import 'package:flutter/widgets.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import '../ui/sessions/chat_adaptive.dart';
import 'chat_workspace_controller.dart';
/// A phone presentation only: saved split axes and ratios are left untouched.
@@ -75,14 +77,10 @@ class _ChatMobilePaneViewportState extends State<ChatMobilePaneViewport>
duration: const Duration(milliseconds: 120),
value: 1,
);
late final Animation<double> _opacity = Tween(
begin: .75,
end: 1.0,
).animate(CurvedAnimation(parent: _reveal, curve: Curves.easeOutCubic));
late final Animation<Offset> _slide = Tween(
begin: const Offset(0, .005),
end: Offset.zero,
).animate(CurvedAnimation(parent: _reveal, curve: Curves.easeOutCubic));
late final Animation<double> _accent = CurvedAnimation(
parent: _reveal,
curve: Curves.easeOutCubic,
);
@override
void didUpdateWidget(covariant ChatMobilePaneViewport oldWidget) {
super.didUpdateWidget(oldWidget);
@@ -101,48 +99,84 @@ class _ChatMobilePaneViewportState extends State<ChatMobilePaneViewport>
@override
Widget build(BuildContext context) => ClipRect(
child: FadeTransition(
key: ValueKey('chat-reveal-${widget.paneId}'),
opacity: _opacity,
child: SlideTransition(
position: _slide,
child: Stack(
fit: StackFit.expand,
children: [
OverflowBox(
alignment: Alignment.topCenter,
minHeight: widget.contentHeight,
maxHeight: widget.contentHeight,
child: SizedBox(
height: widget.contentHeight,
child: ExcludeFocus(
excluding: widget.peek,
child: ExcludeSemantics(
excluding: widget.peek,
child: IgnorePointer(
ignoring: widget.peek,
child: RepaintBoundary(child: widget.child),
),
child: Stack(
fit: StackFit.expand,
children: [
OverflowBox(
alignment: Alignment.topCenter,
minHeight: widget.contentHeight,
maxHeight: widget.contentHeight,
child: SizedBox(
height: widget.contentHeight,
child: ExcludeFocus(
excluding: widget.peek,
child: ExcludeSemantics(
excluding: widget.peek,
child: IgnorePointer(
ignoring: widget.peek,
child: RepaintBoundary(child: widget.child),
),
),
),
),
),
if (widget.peek)
Semantics(
key: ValueKey('chat-peek-${widget.paneId}'),
identifier: 'chat-peek-${widget.paneId}',
container: true,
sortKey: const OrdinalSortKey(1),
label: 'Expand ${widget.label}',
button: true,
child: GestureDetector(
behavior: HitTestBehavior.opaque,
onTap: widget.onActivate,
),
),
if (widget.active && widget.animate)
Positioned(
left: 0,
right: 0,
top: 0,
height: 2,
child: IgnorePointer(
child: RepaintBoundary(
child: CustomPaint(
key: ValueKey('chat-focus-accent-${widget.paneId}'),
painter: ChatPaneFocusAccent(
progress: _accent,
color:
chatControlsStyleOf(context) ==
ChatControlsStyle.cupertino
? CupertinoTheme.of(context).primaryColor
: Theme.of(context).colorScheme.primary,
),
),
),
),
if (widget.peek)
Semantics(
key: ValueKey('chat-peek-${widget.paneId}'),
identifier: 'chat-peek-${widget.paneId}',
container: true,
sortKey: const OrdinalSortKey(1),
label: 'Expand ${widget.label}',
button: true,
child: GestureDetector(
behavior: HitTestBehavior.opaque,
onTap: widget.onActivate,
),
),
],
),
),
),
],
),
);
}
/// Only this tiny focus stripe repaints during the transition; the rich chat
/// body remains opaque and stationary, avoiding a full-pane alpha/saveLayer.
class ChatPaneFocusAccent extends CustomPainter {
ChatPaneFocusAccent({required this.progress, required this.color})
: super(repaint: progress);
final Animation<double> progress;
final Color color;
@override
void paint(Canvas canvas, Size size) {
if (progress.value >= 1) return;
canvas.drawRect(
Offset.zero & size,
Paint()..color = color.withValues(alpha: (1 - progress.value) * .7),
);
}
@override
bool shouldRepaint(covariant ChatPaneFocusAccent oldDelegate) =>
oldDelegate.color != color || oldDelegate.progress != progress;
}
@@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/features/chat/workspace/chat_workspace.dart';
import 'package:pipelines_app/features/chat/workspace/chat_mobile_panes.dart';
Widget _host(
ChatWorkspaceController controller, {
@@ -75,7 +76,7 @@ class _CountLayouts extends RenderProxyBox {
Finder _rect(String pane) => find.byKey(ValueKey('chat-workspace-$pane'));
void main() {
testWidgets(
'active chat promotes to top with cheap reveal and stable thread layout',
'active chat promotes to top with small focus accent and stable thread layout',
(tester) async {
tester.view.physicalSize = const Size(560, 800);
tester.view.devicePixelRatio = 1;
@@ -119,11 +120,27 @@ void main() {
final aLayouts = (aState as _DraftState).layouts;
final bLayouts = (bState as _DraftState).layouts;
await tester.pump(const Duration(milliseconds: 60));
final reveal = tester.widget<FadeTransition>(
find.byKey(ValueKey('chat-reveal-$first')),
final accentFinder = find.byKey(ValueKey('chat-focus-accent-$first'));
final accent =
tester.widget<CustomPaint>(accentFinder).painter!
as ChatPaneFocusAccent;
expect(tester.getSize(accentFinder).height, 2);
expect(accent.progress.value, greaterThan(0));
expect(accent.progress.value, lessThan(1));
expect(
find.descendant(
of: find.byType(ChatWorkspace),
matching: find.byType(FadeTransition),
),
findsNothing,
);
expect(
find.descendant(
of: find.byType(ChatWorkspace),
matching: find.byType(SlideTransition),
),
findsNothing,
);
expect(reveal.opacity.value, greaterThan(.75));
expect(reveal.opacity.value, lessThan(1));
// The short animation only composites retained content. In particular,
// neither transcript nor composer receives a new size on each tick.
expect(
@@ -164,9 +181,13 @@ void main() {
await tester.pumpAndSettle();
expect(tester.getRect(_rect(second)).top, 0);
expect(
tester
.widget<FadeTransition>(find.byKey(ValueKey('chat-reveal-$second')))
.opacity
(tester
.widget<CustomPaint>(
find.byKey(ValueKey('chat-focus-accent-$second')),
)
.painter!
as ChatPaneFocusAccent)
.progress
.value,
1,
);
@@ -200,13 +221,7 @@ void main() {
await tester.pump();
expect(tester.getSize(_rect(first)).height, closeTo((800 - 6) * .8, 1));
expect(tester.getRect(_rect(first)).top, 0);
expect(
tester
.widget<FadeTransition>(find.byKey(ValueKey('chat-reveal-$first')))
.opacity
.value,
1,
);
expect(find.byKey(ValueKey('chat-focus-accent-$first')), findsNothing);
expect(find.byType(_Draft), findsNWidgets(2));
expect(find.byType(_Draft, skipOffstage: false), findsNWidgets(3));
controller.activate(third);