Animate focused mobile chat panes while preserving saved geometry
This commit is contained in:
@@ -5,6 +5,7 @@ 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';
|
||||
|
||||
export 'chat_workspace_controller.dart';
|
||||
export 'chat_workspace_geometry.dart' show ChatPaneDirection;
|
||||
@@ -22,6 +23,8 @@ class ChatWorkspace extends StatefulWidget {
|
||||
this.onFocusPane,
|
||||
this.shortcutsEnabled = true,
|
||||
this.singlePane = false,
|
||||
this.mobilePeeks = false,
|
||||
this.paneTitle,
|
||||
});
|
||||
final ChatWorkspaceController controller;
|
||||
final ChatWorkspacePaneBuilder paneBuilder;
|
||||
@@ -29,6 +32,8 @@ class ChatWorkspace extends StatefulWidget {
|
||||
|
||||
/// Keeps the retained layout while presenting only the active chat.
|
||||
final bool singlePane;
|
||||
final bool mobilePeeks;
|
||||
final String Function(ChatWorkspacePane)? paneTitle;
|
||||
|
||||
/// Keyboard navigation only: the owner can focus the target composer.
|
||||
/// Pointer activation leaves text-selection and pointer focus alone.
|
||||
@@ -42,6 +47,8 @@ class _ChatWorkspaceState extends State<ChatWorkspace> {
|
||||
final _focus = FocusNode(debugLabel: 'Chat workspace');
|
||||
final Map<String, FocusScopeNode> _panes = {};
|
||||
ChatWorkspaceGeometry? _geometry;
|
||||
String? _lastActiveId;
|
||||
String? _peekId;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
@@ -115,6 +122,23 @@ class _ChatWorkspaceState extends State<ChatWorkspace> {
|
||||
_geometry = geometry;
|
||||
final collapsed = widget.singlePane || geometry.collapsed;
|
||||
final panes = widget.controller.panes;
|
||||
final activeId = widget.controller.activePaneId;
|
||||
if (_lastActiveId != activeId) {
|
||||
_peekId = _lastActiveId;
|
||||
_lastActiveId = activeId;
|
||||
}
|
||||
final mobile = widget.mobilePeeks && activeId != null
|
||||
? ChatMobilePanes(
|
||||
panes: panes,
|
||||
activeId: activeId,
|
||||
peekId: _peekId,
|
||||
size: constraints.biggest,
|
||||
)
|
||||
: null;
|
||||
final duration =
|
||||
mobile != null && !MediaQuery.disableAnimationsOf(context)
|
||||
? const Duration(milliseconds: 220)
|
||||
: Duration.zero;
|
||||
final existing = panes.map((p) => p.id).toSet();
|
||||
for (final id
|
||||
in _panes.keys.where((id) => !existing.contains(id)).toList()) {
|
||||
@@ -126,37 +150,60 @@ class _ChatWorkspaceState extends State<ChatWorkspace> {
|
||||
clipBehavior: Clip.hardEdge,
|
||||
children: [
|
||||
for (final pane in panes)
|
||||
Positioned.fromRect(
|
||||
AnimatedPositioned.fromRect(
|
||||
duration: duration,
|
||||
curve: Curves.easeInOutCubic,
|
||||
key: ValueKey('chat-workspace-${pane.id}'),
|
||||
rect: collapsed
|
||||
? Offset.zero & constraints.biggest
|
||||
: geometry.panes[pane.id]!,
|
||||
rect:
|
||||
mobile?.rects[pane.id] ??
|
||||
(collapsed
|
||||
? Offset.zero & constraints.biggest
|
||||
: geometry.panes[pane.id]!),
|
||||
child: Offstage(
|
||||
offstage:
|
||||
collapsed && pane.id != widget.controller.activePaneId,
|
||||
offstage: mobile != null
|
||||
? !mobile.rects.containsKey(pane.id)
|
||||
: collapsed &&
|
||||
pane.id != widget.controller.activePaneId,
|
||||
child: ExcludeFocus(
|
||||
excluding:
|
||||
collapsed &&
|
||||
pane.id != widget.controller.activePaneId,
|
||||
child: FocusScope(
|
||||
node: _panes.putIfAbsent(
|
||||
pane.id,
|
||||
() => FocusScopeNode(debugLabel: pane.id),
|
||||
),
|
||||
onFocusChange: (focused) {
|
||||
if (focused) widget.controller.activate(pane.id);
|
||||
child: ChatMobilePaneViewport(
|
||||
peek: mobile?.peekId == pane.id,
|
||||
label: widget.paneTitle?.call(pane) ?? pane.sessionId,
|
||||
paneId: pane.id,
|
||||
height:
|
||||
(mobile?.rects[pane.id] ??
|
||||
(collapsed
|
||||
? Offset.zero & constraints.biggest
|
||||
: geometry.panes[pane.id]!))
|
||||
.height,
|
||||
onActivate: () {
|
||||
FocusManager.instance.primaryFocus?.unfocus();
|
||||
widget.controller.activate(pane.id);
|
||||
},
|
||||
child: Listener(
|
||||
behavior: HitTestBehavior.translucent,
|
||||
onPointerDown: (_) =>
|
||||
widget.controller.activate(pane.id),
|
||||
child: Semantics(
|
||||
identifier: 'chat-pane-${pane.id}',
|
||||
container: true,
|
||||
child: widget.paneBuilder(
|
||||
context,
|
||||
pane,
|
||||
pane.id == widget.controller.activePaneId,
|
||||
child: FocusScope(
|
||||
node: _panes.putIfAbsent(
|
||||
pane.id,
|
||||
() => FocusScopeNode(debugLabel: pane.id),
|
||||
),
|
||||
onFocusChange: (focused) {
|
||||
if (focused && !widget.mobilePeeks) {
|
||||
widget.controller.activate(pane.id);
|
||||
}
|
||||
},
|
||||
child: Listener(
|
||||
behavior: HitTestBehavior.translucent,
|
||||
onPointerDown: (_) =>
|
||||
widget.controller.activate(pane.id),
|
||||
child: Semantics(
|
||||
identifier: 'chat-pane-${pane.id}',
|
||||
container: true,
|
||||
child: widget.paneBuilder(
|
||||
context,
|
||||
pane,
|
||||
pane.id == widget.controller.activePaneId,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
@@ -164,7 +211,7 @@ class _ChatWorkspaceState extends State<ChatWorkspace> {
|
||||
),
|
||||
),
|
||||
),
|
||||
if (!collapsed)
|
||||
if (!collapsed && mobile == null)
|
||||
for (final divider in geometry.dividers)
|
||||
Positioned.fromRect(
|
||||
key: ValueKey('chat-workspace-${divider.split.id}'),
|
||||
|
||||
Reference in New Issue
Block a user