Loop mobile chats as a tape and remember resizable peek height
This commit is contained in:
@@ -4,12 +4,11 @@ import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
import 'chat_workspace_controller.dart';
|
||||
import 'chat_workspace_divider.dart';
|
||||
import 'chat_workspace_geometry.dart';
|
||||
import 'chat_mobile_panes.dart';
|
||||
import 'chat_pane_switch_motion.dart';
|
||||
import 'chat_pane_backdrop.dart';
|
||||
import 'chat_pane_swap_card.dart';
|
||||
import 'chat_workspace_surface.dart';
|
||||
|
||||
export 'chat_workspace_controller.dart';
|
||||
export 'chat_workspace_geometry.dart' show ChatPaneDirection;
|
||||
@@ -29,6 +28,7 @@ class ChatWorkspace extends StatefulWidget {
|
||||
this.singlePane = false,
|
||||
this.mobilePeeks = false,
|
||||
this.paneTitle,
|
||||
this.onVisibleSessionIdsChanged,
|
||||
});
|
||||
final ChatWorkspaceController controller;
|
||||
final ChatWorkspacePaneBuilder paneBuilder;
|
||||
@@ -38,6 +38,7 @@ class ChatWorkspace extends StatefulWidget {
|
||||
final bool singlePane;
|
||||
final bool mobilePeeks;
|
||||
final String Function(ChatWorkspacePane)? paneTitle;
|
||||
final ValueChanged<Set<String>>? onVisibleSessionIdsChanged;
|
||||
|
||||
/// Keyboard navigation only: the owner can focus the target composer.
|
||||
/// Pointer activation leaves text-selection and pointer focus alone.
|
||||
@@ -54,6 +55,7 @@ class _ChatWorkspaceState extends State<ChatWorkspace>
|
||||
late final ChatPaneSwitchMotion _motion;
|
||||
ChatWorkspaceGeometry? _geometry;
|
||||
String? _lastActiveId;
|
||||
Set<String> _visibleSessionIds = const {};
|
||||
String? _peekId;
|
||||
late final ChatPaneBackdrop _backdrop;
|
||||
void _backdropChanged() {
|
||||
@@ -64,11 +66,31 @@ class _ChatWorkspaceState extends State<ChatWorkspace>
|
||||
void initState() {
|
||||
super.initState();
|
||||
_motion = ChatPaneSwitchMotion(vsync: this);
|
||||
_motion.animation.addStatusListener(_motionSettled);
|
||||
_backdrop = ChatPaneBackdrop(_motion.animation)
|
||||
..addListener(_backdropChanged);
|
||||
HardwareKeyboard.instance.addHandler(_key);
|
||||
}
|
||||
|
||||
void _reportVisible(Set<String> ids) {
|
||||
if (setEquals(ids, _visibleSessionIds)) return;
|
||||
_visibleSessionIds = Set.unmodifiable(ids);
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
if (mounted && setEquals(ids, _visibleSessionIds)) {
|
||||
widget.onVisibleSessionIdsChanged?.call(_visibleSessionIds);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void _motionSettled(AnimationStatus status) {
|
||||
if (status != AnimationStatus.completed) return;
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
if (mounted && widget.controller.activePaneId != _lastActiveId) {
|
||||
setState(() {});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
bool _key(KeyEvent event) {
|
||||
if (!widget.shortcutsEnabled ||
|
||||
widget.controller.paneCount <= 1 ||
|
||||
@@ -116,6 +138,7 @@ class _ChatWorkspaceState extends State<ChatWorkspace>
|
||||
void dispose() {
|
||||
HardwareKeyboard.instance.removeHandler(_key);
|
||||
_backdrop.dispose();
|
||||
_motion.animation.removeStatusListener(_motionSettled);
|
||||
_motion.dispose();
|
||||
_focus.dispose();
|
||||
for (final node in _panes.values) {
|
||||
@@ -132,12 +155,21 @@ class _ChatWorkspaceState extends State<ChatWorkspace>
|
||||
builder: (context, _) => LayoutBuilder(
|
||||
builder: (context, constraints) {
|
||||
final root = widget.controller.root;
|
||||
if (root == null) return const SizedBox.shrink();
|
||||
if (root == null) {
|
||||
_reportVisible({});
|
||||
return const SizedBox.shrink();
|
||||
}
|
||||
final geometry = ChatWorkspaceGeometry(root, constraints.biggest);
|
||||
_geometry = geometry;
|
||||
final collapsed = widget.singlePane || geometry.collapsed;
|
||||
final panes = widget.controller.panes;
|
||||
final activeId = widget.controller.activePaneId;
|
||||
// Finish one joined loop before taking the latest requested role.
|
||||
// Repeated taps/chords never tear the tape or duplicate a live chat.
|
||||
final activeId =
|
||||
_motion.isAnimating &&
|
||||
panes.any((pane) => pane.id == _lastActiveId)
|
||||
? _lastActiveId
|
||||
: widget.controller.activePaneId;
|
||||
final switching = _lastActiveId != activeId;
|
||||
if (switching) {
|
||||
_peekId = _lastActiveId;
|
||||
@@ -149,12 +181,14 @@ class _ChatWorkspaceState extends State<ChatWorkspace>
|
||||
activeId: activeId,
|
||||
peekId: _peekId,
|
||||
size: constraints.biggest,
|
||||
peekFraction: widget.controller.mobilePeekFraction,
|
||||
)
|
||||
: null;
|
||||
if (mobile != null &&
|
||||
switching &&
|
||||
!MediaQuery.disableAnimationsOf(context)) {
|
||||
_backdrop.capture(context);
|
||||
var animate = !MediaQuery.disableAnimationsOf(context);
|
||||
if (mobile != null && switching && animate) {
|
||||
// The top exit requires a fresh picture. If painting is not ready,
|
||||
// settle safely instead of moving the only live tree offscreen.
|
||||
animate = _backdrop.capture(context);
|
||||
}
|
||||
if (mobile == null) {
|
||||
_motion.rest();
|
||||
@@ -164,59 +198,33 @@ class _ChatWorkspaceState extends State<ChatWorkspace>
|
||||
size: constraints.biggest,
|
||||
activeId: activeId!,
|
||||
switching: switching,
|
||||
animate: !MediaQuery.disableAnimationsOf(context),
|
||||
animate: animate,
|
||||
);
|
||||
}
|
||||
_reportVisible({
|
||||
for (final pane in panes)
|
||||
if (mobile != null
|
||||
? mobile.rects.containsKey(pane.id)
|
||||
: !collapsed || pane.id == activeId)
|
||||
pane.sessionId,
|
||||
});
|
||||
final existing = panes.map((p) => p.id).toSet();
|
||||
for (final id
|
||||
in _panes.keys.where((id) => !existing.contains(id)).toList()) {
|
||||
final node = _panes.remove(id)!;
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) => node.dispose());
|
||||
}
|
||||
final ordered = mobile?.paintOrder(panes) ?? panes;
|
||||
return ChatPanePicture(
|
||||
key: _backdrop.pictureKey,
|
||||
child: Stack(
|
||||
fit: StackFit.expand,
|
||||
clipBehavior: Clip.hardEdge,
|
||||
children: [
|
||||
if (_backdrop.image != null)
|
||||
IgnorePointer(
|
||||
child: RawImage(image: _backdrop.image, fit: BoxFit.fill),
|
||||
),
|
||||
for (final pane in ordered)
|
||||
// A switch moves the retained pane view; the view itself is
|
||||
// built once per layout; ticks resize its real scroll viewport.
|
||||
AnimatedBuilder(
|
||||
key: ValueKey('chat-workspace-${pane.id}'),
|
||||
animation: _motion.animation,
|
||||
child: _paneView(pane, mobile, collapsed, activeId),
|
||||
builder: (context, child) => Positioned.fromRect(
|
||||
rect:
|
||||
_motion.rectFor(pane.id) ??
|
||||
(collapsed
|
||||
? Offset.zero & constraints.biggest
|
||||
: geometry.panes[pane.id]!),
|
||||
child: ChatPaneSwapCard(
|
||||
enabled: mobile != null,
|
||||
lift: _motion.liftFor(pane.id),
|
||||
child: child!,
|
||||
),
|
||||
),
|
||||
),
|
||||
if (!collapsed && mobile == null)
|
||||
for (final divider in geometry.dividers)
|
||||
Positioned.fromRect(
|
||||
key: ValueKey('chat-workspace-${divider.split.id}'),
|
||||
rect: divider.rect,
|
||||
child: ChatWorkspaceDivider(
|
||||
geometry: divider,
|
||||
onChanged: (ratio) =>
|
||||
widget.controller.resize(divider.split.id, ratio),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
return chatWorkspaceSurface(
|
||||
context: context,
|
||||
backdrop: _backdrop,
|
||||
motion: _motion,
|
||||
controller: widget.controller,
|
||||
geometry: geometry,
|
||||
mobile: mobile,
|
||||
collapsed: collapsed,
|
||||
size: constraints.biggest,
|
||||
panes: panes,
|
||||
paneView: (pane) => _paneView(pane, mobile, collapsed, activeId),
|
||||
);
|
||||
},
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user