import 'dart:math' as math; import 'package:flutter/semantics.dart'; import 'package:flutter/widgets.dart'; import '../conversation/chat_pane_presentation.dart'; import 'chat_peek_gesture.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); this.activeId = active.id; 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; this.activeId = active.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; String? activeId; /// [panes] with the active one last: it is drawn over the other during a /// switch and takes pointers first. List paintOrder(List panes) => [ for (final pane in panes) if (pane.id != activeId) pane, for (final pane in panes) if (pane.id == activeId) pane, ]; } /// One retained chat in the phone presentation. /// /// Both chats keep the same full content box ([contentHeight]), aligned to /// the pane's top and clipped to it, so a switch moves and clips retained /// pictures without laying a transcript out again. The peek shows its /// transcript from the top (its bar steps aside through /// [ChatPanePresentation]); a drag on it scrolls that transcript and a tap /// activates the chat. The tree keeps one shape in both roles, so a chat /// changing role keeps its state. class ChatMobilePaneViewport extends StatelessWidget { const ChatMobilePaneViewport({ super.key, required this.peek, required this.active, required this.barReveal, required this.child, required this.onActivate, required this.label, required this.paneId, this.contentHeight, }); final bool peek; final bool active; /// The bar's reveal for this pane's role (see [ChatPanePresentation]). final Animation barReveal; final Widget child; final VoidCallback onActivate; final String label; final String paneId; final double? contentHeight; @override Widget build(BuildContext context) => ClipRect( child: Semantics( key: ValueKey('chat-peek-$paneId'), identifier: peek ? 'chat-peek-$paneId' : null, container: peek, sortKey: peek ? const OrdinalSortKey(1) : null, label: peek ? 'Expand $label' : null, button: peek ? true : null, onTap: peek ? onActivate : null, child: ChatPeekGesture( onTap: peek ? onActivate : null, child: OverflowBox( alignment: Alignment.topCenter, minHeight: contentHeight, maxHeight: contentHeight, child: SizedBox( height: contentHeight, child: ExcludeFocus( excluding: peek, child: ExcludeSemantics( excluding: peek, child: RepaintBoundary( child: ChatPanePresentation( peek: peek, barReveal: barReveal, child: child, ), ), ), ), ), ), ), ), ); }