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;
}