import 'package:flutter/semantics.dart'; import 'dart:math' as math; import 'package:flutter/widgets.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. Only the cheap /// viewport clip and position change during a switch; 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 = AnimationController( vsync: this, duration: const Duration(milliseconds: 120), value: 1, ); late final Animation _opacity = Tween( begin: .75, end: 1.0, ).animate(CurvedAnimation(parent: _reveal, curve: Curves.easeOutCubic)); late final Animation _slide = Tween( begin: const Offset(0, .005), end: Offset.zero, ).animate(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() { _reveal.dispose(); super.dispose(); } @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), ), ), ), ), ), 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, ), ), ], ), ), ), ); }