import 'package:flutter/semantics.dart'; import 'dart:math' as math; 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. class ChatMobilePanes { ChatMobilePanes({ required List panes, required String activeId, required String? peekId, required Size size, }) { final active = panes.firstWhere((pane) => pane.id == activeId); final peek = panes .where((pane) => pane.id == peekId && pane.id != activeId) .firstOrNull ?? panes.where((pane) => pane.id != activeId).firstOrNull; if (peek == null) { contentHeight = size.height; rects[active.id] = Offset.zero & size; return; } this.peekId = peek.id; const gap = 6.0; final available = math.max(0.0, size.height - gap); final peekHeight = available * .2; contentHeight = available - peekHeight; // Selection always promotes the active conversation to the top. rects[active.id] = Rect.fromLTWH(0, 0, size.width, contentHeight); rects[peek.id] = Rect.fromLTWH( 0, contentHeight + gap, size.width, peekHeight, ); } late final double contentHeight; final rects = {}; String? peekId; } /// Both mobile threads retain the same full content layout. Selection changes /// positions once; only a tiny focus cue animates, so transcript layout, scroll /// anchoring and backdrop painting do not repeat on every animation tick. class ChatMobilePaneViewport extends StatefulWidget { const ChatMobilePaneViewport({ super.key, required this.peek, required this.active, required this.animate, required this.child, required this.onActivate, required this.label, required this.paneId, this.contentHeight, }); final bool peek; final bool active; final bool animate; final Widget child; final VoidCallback onActivate; final String label; final String paneId; final double? contentHeight; @override State createState() => _ChatMobilePaneViewportState(); } class _ChatMobilePaneViewportState extends State with SingleTickerProviderStateMixin { late final AnimationController _reveal; late final CurvedAnimation _accent; @override void initState() { super.initState(); _reveal = AnimationController( vsync: this, duration: const Duration(milliseconds: 120), value: 1, ); _accent = CurvedAnimation(parent: _reveal, curve: Curves.easeOutCubic); } @override void didUpdateWidget(covariant ChatMobilePaneViewport oldWidget) { super.didUpdateWidget(oldWidget); if (!widget.animate || !widget.active) { _reveal.value = 1; } else if (!oldWidget.active) { _reveal.forward(from: 0); } } @override void dispose() { _accent.dispose(); _reveal.dispose(); super.dispose(); } @override Widget build(BuildContext context) => ClipRect( 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, ), ), ), ), ), ], ), ); } /// 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 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; }