Allow adding chats on phones and keep their native detail route
This commit is contained in:
@@ -6,6 +6,7 @@ mixin _ChatScreenWorkspace on State<ChatScreen> {
|
||||
ChatComposerFocusRequests get _composerFocus;
|
||||
JsonMap? _rowFor(String id);
|
||||
void _back();
|
||||
bool get _pageOpen;
|
||||
Widget _thread(
|
||||
String selected,
|
||||
VoidCallback onBack, {
|
||||
@@ -193,8 +194,15 @@ mixin _ChatScreenWorkspace on State<ChatScreen> {
|
||||
if (id.isEmpty) return;
|
||||
_openedSessions[id] = session;
|
||||
_workspaceVisible = true;
|
||||
if (!_pageOpen && showsListBesideDetail(context)) _usedWorkspace = true;
|
||||
_workspace.splitActive(id, axis);
|
||||
_composerFocus.request(id);
|
||||
if (showsListBesideDetail(context) ||
|
||||
chatSelectionFocusesComposer(const {})) {
|
||||
_composerFocus.request(id);
|
||||
} else {
|
||||
_composerFocus.cancel();
|
||||
FocusManager.instance.primaryFocus?.unfocus();
|
||||
}
|
||||
}
|
||||
|
||||
void _openBeside(JsonMap session) =>
|
||||
@@ -225,11 +233,34 @@ mixin _ChatScreenWorkspace on State<ChatScreen> {
|
||||
},
|
||||
);
|
||||
|
||||
void _addPane(BuildContext context) {
|
||||
final opened = _workspace.panes.map((pane) => pane.sessionId).toSet();
|
||||
final available = _sessionsForSidebar.sessions
|
||||
.where((row) => !opened.contains('${row['id'] ?? ''}'))
|
||||
.toList();
|
||||
showChatPanePicker(
|
||||
context,
|
||||
title: available.isEmpty
|
||||
? 'All available chats are already open'
|
||||
: 'Add chat pane',
|
||||
panes: [
|
||||
for (final row in available)
|
||||
(id: '${row['id']}', title: chatSessionTitle(row)),
|
||||
],
|
||||
activeId: null,
|
||||
onSelected: (id) =>
|
||||
_openBelow(available.firstWhere((row) => row['id'] == id)),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _workspaceView() => ChatWorkspace(
|
||||
key: _workspaceKey,
|
||||
controller: _workspace,
|
||||
shortcutsEnabled: _workspaceVisible,
|
||||
singlePane: !showsListBesideDetail(context),
|
||||
mobilePeeks: !showsListBesideDetail(context),
|
||||
paneTitle: (pane) =>
|
||||
'${_rowFor(pane.sessionId)?['title'] ?? pane.sessionId}',
|
||||
onFocusPane: (pane) => _composerFocus.request(pane.sessionId),
|
||||
paneBuilder: (context, pane, active) => Semantics(
|
||||
selected: active,
|
||||
|
||||
@@ -9,13 +9,14 @@ Future<void> showChatPanePicker(
|
||||
required List<({String id, String title})> panes,
|
||||
required String? activeId,
|
||||
required ValueChanged<String> onSelected,
|
||||
String title = 'Open chats',
|
||||
}) async {
|
||||
final String? selected;
|
||||
if (chatControlsStyleOf(context) == ChatControlsStyle.cupertino) {
|
||||
selected = await showCupertinoModalPopup<String>(
|
||||
context: context,
|
||||
builder: (context) => CupertinoActionSheet(
|
||||
title: const Text('Open chats'),
|
||||
title: Text(title),
|
||||
actions: [
|
||||
for (final pane in panes)
|
||||
CupertinoActionSheetAction(
|
||||
@@ -34,7 +35,7 @@ Future<void> showChatPanePicker(
|
||||
selected = await showDialog<String>(
|
||||
context: context,
|
||||
builder: (context) => SimpleDialog(
|
||||
title: const Text('Open chats'),
|
||||
title: Text(title),
|
||||
children: [
|
||||
for (final pane in panes)
|
||||
SimpleDialogOption(
|
||||
|
||||
@@ -30,6 +30,7 @@ import 'conversation/composer_selection_focus.dart';
|
||||
import 'data/chat_repository.dart';
|
||||
import 'domain/chat_commands.dart';
|
||||
import 'domain/chat_cycle.dart';
|
||||
import 'domain/chat_sessions.dart';
|
||||
import 'ui/sessions/chat_sessions_body.dart';
|
||||
import 'ui/sessions/chat_sessions_controller.dart';
|
||||
import 'ui/sessions/chat_sessions_screen.dart';
|
||||
@@ -364,6 +365,8 @@ class _ChatScreenState extends State<ChatScreen> with _ChatScreenWorkspace {
|
||||
|
||||
/// On a phone the open chat is a real page above the main screen.
|
||||
final DetailPageHost _page = DetailPageHost();
|
||||
@override
|
||||
bool get _pageOpen => _page.open;
|
||||
|
||||
@override
|
||||
void didUpdateWidget(covariant ChatScreen oldWidget) {
|
||||
@@ -429,13 +432,22 @@ class _ChatScreenState extends State<ChatScreen> with _ChatScreenWorkspace {
|
||||
onNextChat: _nextAfter(selected) != null
|
||||
? () => _openNext(selected)
|
||||
: null,
|
||||
showBackButton: pane == null ? null : !showsListBesideDetail(context),
|
||||
sidebarControl: pane == null || !showsListBesideDetail(context)
|
||||
showBackButton: pane == null
|
||||
? null
|
||||
: _page.open || !showsListBesideDetail(context),
|
||||
sidebarControl:
|
||||
pane == null || _page.open || !showsListBesideDetail(context)
|
||||
? null
|
||||
: ChatSidebarButton(mode: _sidebarMode, onChanged: _setSidebarMode),
|
||||
paneControls: pane == null
|
||||
? const []
|
||||
: [
|
||||
ChatBarAction(
|
||||
label: 'Add chat pane',
|
||||
onPressed: () => _addPane(paneContext ?? context),
|
||||
materialIcon: Icons.add_box_outlined,
|
||||
cupertinoIcon: CupertinoIcons.plus_square,
|
||||
),
|
||||
if (_workspace.paneCount > 1)
|
||||
ChatBarAction(
|
||||
label: 'Open chats (${_workspace.paneCount})',
|
||||
@@ -471,7 +483,7 @@ class _ChatScreenState extends State<ChatScreen> with _ChatScreenWorkspace {
|
||||
// A phone opens a chat as a real Navigator page with stock Back. A wide
|
||||
// window keeps the destination rail and the chat list beside the open
|
||||
// chat, which has no Back: another row, `/close` or a route change swaps it.
|
||||
final beside = showsListBesideDetail(context);
|
||||
final beside = !_page.open && showsListBesideDetail(context);
|
||||
if (beside && selected != null) _usedWorkspace = true;
|
||||
_page.sync(
|
||||
context,
|
||||
@@ -480,7 +492,7 @@ class _ChatScreenState extends State<ChatScreen> with _ChatScreenWorkspace {
|
||||
onClosed: _back,
|
||||
builder: (context) => selected == null
|
||||
? const SizedBox.shrink()
|
||||
: _thread(selected, () => Navigator.of(context).maybePop()),
|
||||
: ShellBar(barless: true, child: _workspaceView()),
|
||||
);
|
||||
// The session list pads its first row by the bar's height itself, so it
|
||||
// scrolls behind the shell's floating bar like the other lists.
|
||||
@@ -492,7 +504,7 @@ class _ChatScreenState extends State<ChatScreen> with _ChatScreenWorkspace {
|
||||
folds: _folds,
|
||||
onOpen: _openBySelection,
|
||||
onOpenBeside: beside ? _openBeside : null,
|
||||
onOpenBelow: beside ? _openBelow : null,
|
||||
onOpenBelow: _openBelow,
|
||||
onShortcutOpen: _openByShortcut,
|
||||
onSessions: _adoptRows,
|
||||
activeSessionId: selected,
|
||||
@@ -515,6 +527,7 @@ class _ChatScreenState extends State<ChatScreen> with _ChatScreenWorkspace {
|
||||
child: ShellBar(
|
||||
active: selected != null,
|
||||
barless: true,
|
||||
hideNavigation: true,
|
||||
child: Stack(
|
||||
fit: StackFit.expand,
|
||||
children: [
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
# Mobile chat panes
|
||||
|
||||
Phones can add a chat with the header's **Add chat pane** action (in More if space is tight). The session list also offers **Open below** on narrow windows. The native picker lists chats not already open.
|
||||
|
||||
Narrow windows show two retained conversations stacked: the active pane gets80% of the available height and one inactive preview gets20%, separated by6 logical pixels. Tapping a preview animates their heights over220ms. Reduced-motion settings switch immediately. An accessible preview names the chat it will expand. Pointer switching unfocuses inputs and does not request the new composer's keyboard.
|
||||
|
||||
With more than two retained chats, the active pane and previous active pane are visible; **Open chats** accesses every retained pane. The presentation never rewrites stored desktop split ratios. Every thread remains a stable keyed sibling, preserving drafts and transcript state. A small preview clips a full-height layout instead of squeezing its composer into a tiny viewport.
|
||||
|
||||
A chat first opened on a phone stays in its native full-screen detail route while adding panes or unfolding. It already uses the full width; Back returns to the list. The sidebar control is absent on this full-screen route. A chat first opened in the wide list/detail workspace keeps the existing sidebar expanded/compact/hidden control and changes to mobile previews when folded. The destination bar stays hidden while this narrow chat workspace is open, so it cannot overlap either composer or preview.
|
||||
|
||||
Checks: bounded analysis clean;7 real-screen split tests passed, including first-phone-split draft/state identity, exactly one initial Back control, large text with300px keyboard inset and desktop/narrow restoration;23 workspace/controller/persistence tests passed, including intermediate animation geometry, reduced motion and three retained panes;10 list-shortcut tests passed. Tests use the memory watchdog.
|
||||
|
||||
Rendered browser evidence: `/private/tmp/mobile-panes-phone-final/` (Material/light560x1000, Add pane, draft retention, real peek taps, no native input focus after a peek switch, unfold880); `/private/tmp/mobile-panes-unfolded-final/` (Cupertino/dark880x1100 hidden sidebar, fold560x1000, switch). All8 final screenshots/contact sheet were inspected; reports have no errors. The phone film contact sheet and10 frame files show the actual220ms transition, including intermediate frames. Test browsers/servers exited. No physical Fold testing, backend change or deployment was performed in this lane.
|
||||
@@ -79,6 +79,90 @@ Future<void> _split(WidgetTester tester, String id, String action) async {
|
||||
}
|
||||
|
||||
void main() {
|
||||
testWidgets('phone peeks fit a small keyboard viewport at large text', (
|
||||
tester,
|
||||
) async {
|
||||
SharedPreferences.setMockInitialValues({});
|
||||
tester.view.physicalSize = const Size(560, 700);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.reset);
|
||||
final gateway = _Gateway()..history = (_) async => chatPage([]);
|
||||
addTearDown(gateway.close);
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
builder: (context, child) => MediaQuery(
|
||||
data: MediaQuery.of(
|
||||
context,
|
||||
).copyWith(textScaler: TextScaler.linear(2)),
|
||||
child: child!,
|
||||
),
|
||||
home: Scaffold(body: ChatScreen(gateway: gateway)),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.text('Chat a').first);
|
||||
await tester.pumpAndSettle();
|
||||
final controller = tester
|
||||
.widget<ChatWorkspace>(find.byType(ChatWorkspace))
|
||||
.controller;
|
||||
controller.splitActive('b', ChatSplitAxis.vertical);
|
||||
await tester.pumpAndSettle();
|
||||
tester.view.viewInsets = const FakeViewPadding(bottom: 300);
|
||||
await tester.pumpAndSettle();
|
||||
expect(_thread('a'), findsOneWidget);
|
||||
expect(_thread('b'), findsOneWidget);
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
testWidgets('phone can add a second chat without losing its first draft', (
|
||||
tester,
|
||||
) async {
|
||||
SharedPreferences.setMockInitialValues({});
|
||||
tester.view.physicalSize = const Size(560, 1000);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.reset);
|
||||
final gateway = _Gateway()..history = (_) async => chatPage([]);
|
||||
addTearDown(gateway.close);
|
||||
await tester.pumpWidget(_app(gateway));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.text('Chat a').first);
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byTooltip('Back').hitTestable(), findsOneWidget);
|
||||
final stateA = tester.state(_thread('a'));
|
||||
await tester.enterText(_input('a'), 'Phone draft A');
|
||||
await tester.pumpAndSettle();
|
||||
final add = find.byTooltip('Add chat pane').hitTestable();
|
||||
if (add.evaluate().isEmpty) {
|
||||
await tester.tap(find.byTooltip('More actions').first);
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.text('Add chat pane'));
|
||||
} else {
|
||||
await tester.tap(add);
|
||||
}
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.text('Chat b'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(_thread('a'), findsOneWidget);
|
||||
expect(_thread('b'), findsOneWidget);
|
||||
expect(tester.state(_thread('a')), same(stateA));
|
||||
expect(
|
||||
tester.widget<EditableText>(_input('a')).controller.text,
|
||||
'Phone draft A',
|
||||
);
|
||||
final workspace = tester.widget<ChatWorkspace>(find.byType(ChatWorkspace));
|
||||
expect(workspace.controller.paneCount, 2);
|
||||
expect(workspace.controller.activePane?.sessionId, 'b');
|
||||
final first = workspace.controller.panes.first.id;
|
||||
await tester.tap(find.byKey(ValueKey('chat-peek-$first')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(workspace.controller.activePane?.sessionId, 'a');
|
||||
expect(
|
||||
tester.widget<EditableText>(_input('b')).focusNode.hasFocus,
|
||||
isFalse,
|
||||
);
|
||||
expect(tester.state(_thread('a')), same(stateA));
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
|
||||
testWidgets('compact and hidden sidebar preserve panes and drafts', (
|
||||
tester,
|
||||
) async {
|
||||
@@ -147,12 +231,11 @@ void main() {
|
||||
tester.view.physicalSize = const Size(560, 1000);
|
||||
await tester.pumpAndSettle();
|
||||
expect(_thread('c'), findsOneWidget);
|
||||
expect(_thread('a'), findsNothing);
|
||||
expect(_thread('b'), findsNothing);
|
||||
expect(find.byType(ChatThreadView), findsNWidgets(2));
|
||||
tester.view.physicalSize = const Size(390, 844);
|
||||
await tester.pumpAndSettle();
|
||||
expect(_thread('c'), findsOneWidget);
|
||||
expect(_thread('a'), findsNothing);
|
||||
expect(find.byType(ChatThreadView), findsNWidgets(2));
|
||||
expect(tester.state(_thread('a', offstage: true)), same(stateA));
|
||||
tester.view.physicalSize = const Size(1800, 1000);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
Reference in New Issue
Block a user