Chat stack: the default, also on a wide phone or tablet; a close button where the pile was
Chat stack is now the default phone chat navigation (a stored choice is kept), and on Android or iOS it stays on a wide layout (an unfolded foldable) above the active pane, where floating is ignored too. When expanded, the pile turns into a close button at its own spot and the column rises above it; while a chat is dragged that button is the remove target, replacing the separate x at the bottom. Chat widget tests start on Quick switch (they run as Android); the stack's tests choose it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -67,8 +67,11 @@ mixin _ChatScreenFloat on State<ChatScreen>, _ChatScreenWorkspace {
|
||||
|
||||
/// Called from build: a change between a phone and a wide layout moves
|
||||
/// the floating chats between panes and windows after the frame.
|
||||
@override
|
||||
void _trackFloatLayout() {
|
||||
_phoneLayout = !showsListBesideDetail(context);
|
||||
// A phone-width window, or the Chat stack on a wide phone or tablet
|
||||
// layout: both navigate one chat at a time and ignore floating.
|
||||
_phoneLayout = !showsListBesideDetail(context) || _stacked(context);
|
||||
if (widget.windows == null) return;
|
||||
final phone = _phoneIgnoresFloat;
|
||||
if (phone == _builtPhoneFloat) return;
|
||||
|
||||
@@ -6,6 +6,12 @@ part of 'screen.dart';
|
||||
/// workspace's panes, the same open chats the server syncs; choosing one
|
||||
/// opens it as a tap on its list row does, Add chat is the pane menu's Add
|
||||
/// chat pane, and removing one closes its pane.
|
||||
/// Whether this is a phone or tablet (Android or iOS, also a browser on one).
|
||||
bool chatStackOnMobile() => switch (defaultTargetPlatform) {
|
||||
TargetPlatform.android || TargetPlatform.iOS => true,
|
||||
_ => false,
|
||||
};
|
||||
|
||||
mixin _ChatScreenStack on State<ChatScreen>, _ChatScreenWorkspace {
|
||||
final LayerLink _stackLink = LayerLink();
|
||||
|
||||
@@ -15,10 +21,14 @@ mixin _ChatScreenStack on State<ChatScreen>, _ChatScreenWorkspace {
|
||||
MobileChatNavigationController get _navigation =>
|
||||
MobileChatNavigationController.instance;
|
||||
|
||||
/// Whether this layout navigates with the stack rather than the peek.
|
||||
/// Whether this layout navigates with the stack rather than the peek: on
|
||||
/// a phone-width window, and on a phone or tablet at any width (an
|
||||
/// unfolded foldable keeps the stack above the active pane). A wide
|
||||
/// desktop or web window keeps its panes alone.
|
||||
@override
|
||||
bool _stacked(BuildContext context) =>
|
||||
_navigation.stack && !showsListBesideDetail(context);
|
||||
_navigation.stack &&
|
||||
(!showsListBesideDetail(context) || chatStackOnMobile());
|
||||
|
||||
/// Gives the active pane the stack's spot.
|
||||
@override
|
||||
|
||||
@@ -514,10 +514,12 @@ mixin _ChatScreenWorkspace on State<ChatScreen> {
|
||||
Widget _stackScope(BuildContext context, bool active, Widget child);
|
||||
Widget _stackOverlay();
|
||||
MobileChatNavigationController get _navigation;
|
||||
void _trackFloatLayout();
|
||||
|
||||
Widget _workspaceView() => ListenableBuilder(
|
||||
listenable: _navigation,
|
||||
builder: (context, _) {
|
||||
_trackFloatLayout();
|
||||
final stacked = _stacked(context);
|
||||
final workspace = _tiledWorkspace(context, stacked: stacked);
|
||||
if (!stacked) return workspace;
|
||||
|
||||
@@ -14,7 +14,7 @@ import 'dart:async';
|
||||
import '../../ui/motion/motion.dart';
|
||||
import '../../ui/motion/container_transform_source.dart';
|
||||
|
||||
import 'package:flutter/foundation.dart' show setEquals;
|
||||
import 'package:flutter/foundation.dart' show defaultTargetPlatform, setEquals;
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/scheduler.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
@@ -0,0 +1,126 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../../ui/theme/app_design_tokens.dart';
|
||||
import 'chat_stack_disc.dart';
|
||||
|
||||
/// How near the close button's centre a dragged chat's pointer counts as
|
||||
/// over it: a little past its rim, as a thumb covers what it drags, and
|
||||
/// short of the first chat's slot a pitch above.
|
||||
const double kChatStackRemoveReach = kChatStackSlot * .7;
|
||||
|
||||
/// How much the button grows while a dragged chat is over it.
|
||||
const double chatStackRemoveGrowth = 1.2;
|
||||
|
||||
/// The open stack's close button, exactly where the pile was: the pile
|
||||
/// turns into a "×" as the column rises above it, and a tap folds the
|
||||
/// column back.
|
||||
///
|
||||
/// While a chat is dragged it is also the remove target: its "×" turns the
|
||||
/// error colour ([armed]), and with the chat over it ([hover]) it grows and
|
||||
/// fills with the error colour. Dropping there is decided from the
|
||||
/// pointer's position, not by this widget.
|
||||
///
|
||||
/// Everything moves through transitions (fade, turn, scale, decoration), so
|
||||
/// opening and dragging repaint it without rebuilding.
|
||||
class ChatStackCloseTarget extends StatelessWidget {
|
||||
const ChatStackCloseTarget({
|
||||
super.key,
|
||||
required this.open,
|
||||
required this.armed,
|
||||
required this.hover,
|
||||
required this.reduced,
|
||||
required this.onClose,
|
||||
});
|
||||
|
||||
static const label = 'Close chats';
|
||||
|
||||
/// 0 folded (the pile shows), 1 open.
|
||||
final Animation<double> open;
|
||||
|
||||
/// 0 at rest, 1 while a chat is dragged.
|
||||
final Animation<double> armed;
|
||||
|
||||
/// 0 idle, 1 with a dragged chat over it.
|
||||
final Animation<double> hover;
|
||||
|
||||
/// Fades only: no turn, no growth.
|
||||
final bool reduced;
|
||||
final VoidCallback onClose;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final tokens = AppDesignTokens.of(context);
|
||||
final scheme = Theme.of(context).colorScheme;
|
||||
final dark = Theme.of(context).brightness == Brightness.dark;
|
||||
final shape = chatStackShape(tokens);
|
||||
final side = tokens.flat
|
||||
? tokens.frameSide ?? BorderSide(color: scheme.outlineVariant)
|
||||
: BorderSide.none;
|
||||
final idle = ShapeDecoration(
|
||||
color: tokens.panelFill(
|
||||
scheme,
|
||||
dark ? scheme.surfaceContainerHighest : scheme.surface,
|
||||
),
|
||||
shape: shape.copyWith(side: side),
|
||||
shadows: tokens.flat ? null : chatStackShadows(scheme),
|
||||
);
|
||||
final hot = ShapeDecoration(
|
||||
color: scheme.error,
|
||||
shape: shape.copyWith(
|
||||
side: tokens.flat ? side.copyWith(color: scheme.error) : side,
|
||||
),
|
||||
shadows: tokens.flat ? null : chatStackShadows(scheme),
|
||||
);
|
||||
Widget icon(Color color, Animation<double> opacity) => FadeTransition(
|
||||
opacity: opacity,
|
||||
child: Icon(Icons.close, color: color),
|
||||
);
|
||||
Widget button = DecoratedBoxTransition(
|
||||
decoration: DecorationTween(begin: idle, end: hot).animate(hover),
|
||||
child: SizedBox.square(
|
||||
dimension: kChatStackDisc,
|
||||
child: Stack(
|
||||
alignment: Alignment.center,
|
||||
children: [
|
||||
icon(scheme.onSurfaceVariant, ReverseAnimation(armed)),
|
||||
icon(scheme.error, armed),
|
||||
icon(scheme.onError, hover),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
final shown = open.drive(CurveTween(curve: Curves.easeOutCubic));
|
||||
if (!reduced) {
|
||||
button = ScaleTransition(
|
||||
scale: Tween<double>(
|
||||
begin: 1,
|
||||
end: chatStackRemoveGrowth,
|
||||
).chain(CurveTween(curve: Curves.easeOutBack)).animate(hover),
|
||||
child: button,
|
||||
);
|
||||
// The pile's top avatar turns into the "×" a quarter turn.
|
||||
button = RotationTransition(
|
||||
turns: Tween<double>(begin: -.25, end: 0).animate(shown),
|
||||
child: ScaleTransition(
|
||||
scale: Tween<double>(begin: .6, end: 1).animate(shown),
|
||||
child: button,
|
||||
),
|
||||
);
|
||||
}
|
||||
return Semantics(
|
||||
container: true,
|
||||
button: true,
|
||||
label: label,
|
||||
onTap: onClose,
|
||||
child: GestureDetector(
|
||||
behavior: HitTestBehavior.opaque,
|
||||
excludeFromSemantics: true,
|
||||
onTap: onClose,
|
||||
child: FadeTransition(
|
||||
opacity: shown,
|
||||
child: Center(child: button),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,3 @@
|
||||
import 'dart:math' as math;
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
@@ -9,13 +7,14 @@ import 'chat_stack_disc.dart';
|
||||
import 'chat_stack_drag.dart';
|
||||
import 'chat_stack_entry.dart';
|
||||
import 'chat_stack_motion.dart';
|
||||
import 'chat_stack_remove_target.dart';
|
||||
import 'chat_stack_close_target.dart';
|
||||
|
||||
/// The chat stack fanned out: a scrim over the screen and the open chats in
|
||||
/// a column rising from the stack's own slot, each avatar with its name in a
|
||||
/// small pill beside it, and Add chat at the top.
|
||||
///
|
||||
/// Item 0 sits exactly on the collapsed stack, nearest the thumb. The chats
|
||||
/// The stack's own slot turns into a close button ([ChatStackCloseTarget]);
|
||||
/// item 0 sits a pitch above it, nearest the thumb. The chats
|
||||
/// keep the open-chat order (the order the server syncs), so a chat keeps
|
||||
/// its place in the column from one visit to the next; the chat on screen
|
||||
/// wears a ring in its colour. Add chat is last, at the top: the reachable
|
||||
@@ -24,7 +23,8 @@ import 'chat_stack_remove_target.dart';
|
||||
///
|
||||
/// A short hold lifts a chat ([ChatStackDrag]): dragged up or down it
|
||||
/// reorders the open chats, the others sliding aside to open its slot;
|
||||
/// dropped on the "×" that comes in at the bottom it leaves them. Add chat
|
||||
/// dropped on the close button (armed as a remove target while dragging)
|
||||
/// it leaves them. Add chat
|
||||
/// stays put. The same moves are semantic actions on each chat.
|
||||
///
|
||||
/// Nothing here rebuilds per frame: every item moves through
|
||||
@@ -168,7 +168,8 @@ class _ChatStackColumnState extends State<ChatStackColumn>
|
||||
builder: (context, constraints) {
|
||||
final size = constraints.biggest;
|
||||
final count = widget.motion.count;
|
||||
final height = (count - 1) * kChatStackPitch + kChatStackSlot;
|
||||
// The stack's own slot (the close button) and the items above it.
|
||||
final height = count * kChatStackPitch + kChatStackSlot;
|
||||
final top = media.padding.top + 8;
|
||||
final available = anchor.bottom - top;
|
||||
final fits = height <= available;
|
||||
@@ -184,18 +185,23 @@ class _ChatStackColumnState extends State<ChatStackColumn>
|
||||
..sort((a, b) => (depths[b] ?? 99).compareTo(depths[a] ?? 99));
|
||||
final lifted = _entries.indexWhere((e) => e.paneId == _drag.lifted);
|
||||
if (lifted >= 0) order.add(order.removeAt(order.indexOf(lifted)));
|
||||
// The remove target: centred in the band below the stack's slot
|
||||
// (over the composer), clear of the safe area.
|
||||
const r = kChatStackRemoveSize / 2;
|
||||
final floor = size.height - media.padding.bottom;
|
||||
final removeCenter = Offset(
|
||||
size.width / 2,
|
||||
math.max(
|
||||
anchor.bottom + 4,
|
||||
math.min((anchor.bottom + floor) / 2, floor - r - 8),
|
||||
// The close button takes the pile's place; while a chat is dragged
|
||||
// it is the remove target.
|
||||
_removeCenter = anchor.center;
|
||||
final close = Positioned.fromRect(
|
||||
key: const ValueKey('chat-stack-close'),
|
||||
rect: anchor,
|
||||
child: IgnorePointer(
|
||||
ignoring: _drag.lifted != null,
|
||||
child: ChatStackCloseTarget(
|
||||
open: widget.motion.close,
|
||||
armed: _drag.removeShown,
|
||||
hover: _drag.hover,
|
||||
reduced: _drag.reduced,
|
||||
onClose: widget.onDismiss,
|
||||
),
|
||||
),
|
||||
);
|
||||
_removeCenter = removeCenter;
|
||||
final items = ChatStackColumnItems(
|
||||
motion: widget.motion,
|
||||
entries: _entries,
|
||||
@@ -226,24 +232,15 @@ class _ChatStackColumnState extends State<ChatStackColumn>
|
||||
color: scheme.scrim.withValues(alpha: dark ? .5 : .32),
|
||||
dismissible: true,
|
||||
onDismiss: widget.onDismiss,
|
||||
semanticsLabel: 'Close chats',
|
||||
semanticsLabel: 'Dismiss',
|
||||
),
|
||||
),
|
||||
),
|
||||
// Under the column: a chat dragged onto it is drawn over it.
|
||||
if (widget.onRemove != null)
|
||||
Positioned(
|
||||
left: removeCenter.dx - r,
|
||||
top: removeCenter.dy - r,
|
||||
width: kChatStackRemoveSize,
|
||||
height: kChatStackRemoveSize,
|
||||
child: ChatStackRemoveTarget(
|
||||
shown: _drag.removeShown,
|
||||
hover: _drag.hover,
|
||||
reduced: _drag.reduced,
|
||||
),
|
||||
),
|
||||
// A dragged chat is drawn over the button (it shrinks into
|
||||
// it); otherwise the button is on top, to take its tap.
|
||||
if (_drag.lifted != null) close,
|
||||
PositionedDirectional(
|
||||
key: const ValueKey('chat-stack-column'),
|
||||
end: endInset,
|
||||
bottom: size.height - anchor.bottom,
|
||||
top: top,
|
||||
@@ -266,6 +263,7 @@ class _ChatStackColumnState extends State<ChatStackColumn>
|
||||
),
|
||||
),
|
||||
),
|
||||
if (_drag.lifted == null) close,
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
@@ -20,9 +20,10 @@ const Curve chatStackRise = Cubic(.22, 1.18, .36, 1);
|
||||
const Curve chatStackFold = Curves.easeInCubic;
|
||||
|
||||
/// Every animation the open column reads, derived once from one controller
|
||||
/// when the items change (never per frame). Item 0 is nearest the thumb; the
|
||||
/// column rises from there, each item starting a little after the one below
|
||||
/// it, and folds back top first.
|
||||
/// when the items change (never per frame). Item 0 is nearest the thumb, a
|
||||
/// pitch above the stack's slot (where the close button is); the column
|
||||
/// rises from there, each item starting a little after the one below it,
|
||||
/// and folds back top first.
|
||||
class ChatStackMotion {
|
||||
ChatStackMotion({
|
||||
required Animation<double> parent,
|
||||
@@ -31,13 +32,16 @@ class ChatStackMotion {
|
||||
required bool rtl,
|
||||
}) : count = depths.length {
|
||||
scrim = _curve(parent, const Interval(0, .7, curve: Curves.easeOut));
|
||||
close = reduced ? parent : _curve(parent, const Interval(0, .6));
|
||||
final span = count <= 1 ? 1.0 : .62;
|
||||
final step = count <= 1 ? 0.0 : (1 - span) / (count - 1);
|
||||
for (var i = 0; i < count; i++) {
|
||||
final start = i * step;
|
||||
final end = math.min(1.0, start + span);
|
||||
final depth = depths[i];
|
||||
final to = chatStackColumnPose(i, kChatStackPitch);
|
||||
// The stack's own slot holds the close button; the column starts a
|
||||
// pitch above it.
|
||||
final to = chatStackColumnPose(i + 1, kChatStackPitch);
|
||||
final layer = chatStackLayers[depth ?? chatStackLayers.length - 1];
|
||||
target.add(to);
|
||||
if (reduced) {
|
||||
@@ -75,6 +79,9 @@ class ChatStackMotion {
|
||||
final int count;
|
||||
final bool reduced;
|
||||
late final Animation<double> scrim;
|
||||
|
||||
/// The close button taking the pile's place.
|
||||
late final Animation<double> close;
|
||||
final List<ChatStackPose> from = [];
|
||||
final List<ChatStackPose> target = [];
|
||||
final List<Animation<double>> move = [];
|
||||
|
||||
@@ -1,106 +0,0 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../../ui/theme/app_design_tokens.dart';
|
||||
import 'chat_stack_disc.dart';
|
||||
|
||||
/// The remove target's diameter: a little larger than an item, so it reads
|
||||
/// as a destination rather than another chat.
|
||||
const double kChatStackRemoveSize = kChatStackSlot + 8;
|
||||
|
||||
/// How near its centre a finger counts as over the target: past its rim,
|
||||
/// as a thumb covers what it drags.
|
||||
const double kChatStackRemoveReach = kChatStackRemoveSize * .8;
|
||||
|
||||
/// How much the target grows while a chat is over it.
|
||||
const double chatStackRemoveGrowth = 1.2;
|
||||
|
||||
/// The "×" a dragged chat is dropped on to leave the open chats: a circle
|
||||
/// (the design's square under a flat design) that comes in when a drag
|
||||
/// starts and fills with the error colour while a chat is over it. It takes
|
||||
/// no input and says nothing to assistive technology: dropping is decided
|
||||
/// from the pointer's position, and the column's items offer the same
|
||||
/// removal as an action.
|
||||
///
|
||||
/// Everything moves through transitions (fade, slide, scale, decoration),
|
||||
/// so a drag repaints it without rebuilding.
|
||||
class ChatStackRemoveTarget extends StatelessWidget {
|
||||
const ChatStackRemoveTarget({
|
||||
super.key,
|
||||
required this.shown,
|
||||
required this.hover,
|
||||
required this.reduced,
|
||||
});
|
||||
|
||||
/// 0 hidden, 1 in place.
|
||||
final Animation<double> shown;
|
||||
|
||||
/// 0 idle, 1 with a chat over it.
|
||||
final Animation<double> hover;
|
||||
|
||||
/// Fades only: no slide in, no growth.
|
||||
final bool reduced;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final tokens = AppDesignTokens.of(context);
|
||||
final scheme = Theme.of(context).colorScheme;
|
||||
final dark = Theme.of(context).brightness == Brightness.dark;
|
||||
final shape = chatStackShape(tokens);
|
||||
final side = tokens.flat
|
||||
? tokens.frameSide ?? BorderSide(color: scheme.outlineVariant)
|
||||
: BorderSide.none;
|
||||
final idle = ShapeDecoration(
|
||||
color: tokens.panelFill(
|
||||
scheme,
|
||||
dark ? scheme.surfaceContainerHighest : scheme.surface,
|
||||
),
|
||||
shape: shape.copyWith(side: side),
|
||||
shadows: tokens.flat ? null : chatStackShadows(scheme),
|
||||
);
|
||||
final hot = ShapeDecoration(
|
||||
color: scheme.error,
|
||||
shape: shape.copyWith(
|
||||
side: tokens.flat ? side.copyWith(color: scheme.error) : side,
|
||||
),
|
||||
shadows: tokens.flat ? null : chatStackShadows(scheme),
|
||||
);
|
||||
final curve = shown.drive(CurveTween(curve: Curves.easeOutCubic));
|
||||
Widget target = DecoratedBoxTransition(
|
||||
decoration: DecorationTween(begin: idle, end: hot).animate(hover),
|
||||
child: SizedBox.square(
|
||||
dimension: kChatStackRemoveSize,
|
||||
child: Stack(
|
||||
alignment: Alignment.center,
|
||||
children: [
|
||||
Icon(Icons.close, color: scheme.onSurfaceVariant),
|
||||
FadeTransition(
|
||||
opacity: hover,
|
||||
child: Icon(Icons.close, color: scheme.onError),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
if (!reduced) {
|
||||
target = ScaleTransition(
|
||||
scale: Tween<double>(
|
||||
begin: 1,
|
||||
end: chatStackRemoveGrowth,
|
||||
).chain(CurveTween(curve: Curves.easeOutBack)).animate(hover),
|
||||
child: target,
|
||||
);
|
||||
target = SlideTransition(
|
||||
position: Tween<Offset>(
|
||||
begin: const Offset(0, .5),
|
||||
end: Offset.zero,
|
||||
).animate(curve),
|
||||
child: target,
|
||||
);
|
||||
}
|
||||
return IgnorePointer(
|
||||
child: ExcludeSemantics(
|
||||
child: FadeTransition(opacity: curve, child: target),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,8 @@ import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
const mobileChatNavigationKey = 'pipelines.mobile-chat-navigation.v1';
|
||||
|
||||
/// How a phone-width layout moves between the open chats.
|
||||
/// How a phone-width layout (and any layout on a phone or tablet, an unfolded
|
||||
/// foldable too, for the Chat stack) moves between the open chats.
|
||||
enum MobileChatNavigation {
|
||||
quickSwitch(
|
||||
'Quick switch',
|
||||
@@ -59,7 +60,11 @@ class MobileChatNavigationController extends ChangeNotifier {
|
||||
static final instance = MobileChatNavigationController();
|
||||
|
||||
final MobileChatNavigationStore _store;
|
||||
MobileChatNavigation _value = MobileChatNavigation.quickSwitch;
|
||||
|
||||
/// Without a stored choice, the Chat stack.
|
||||
static const fallback = MobileChatNavigation.chatStack;
|
||||
|
||||
MobileChatNavigation _value = fallback;
|
||||
int _revision = 0;
|
||||
bool _disposed = false;
|
||||
bool saveFailed = false;
|
||||
@@ -91,6 +96,16 @@ class MobileChatNavigationController extends ChangeNotifier {
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
/// Sets [mode] without saving it (a test's starting point).
|
||||
@visibleForTesting
|
||||
void debugUse(MobileChatNavigation mode) {
|
||||
_revision++;
|
||||
saveFailed = false;
|
||||
if (mode == _value) return;
|
||||
_value = mode;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_disposed = true;
|
||||
|
||||
@@ -27,8 +27,9 @@ class SettingsChatNavigationSection extends StatelessWidget {
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
const Text(
|
||||
'Saved on this device. Applies on a phone-width window; a wide '
|
||||
'window keeps the chat list beside the chats.',
|
||||
'Saved on this device. Applies on a phone-width window; the '
|
||||
'Chat stack also stays on a wide phone or tablet layout (an '
|
||||
'unfolded foldable), beside the chat list.',
|
||||
),
|
||||
if (navigation.saveFailed)
|
||||
Text(
|
||||
|
||||
Reference in New Issue
Block a user