Chat stack: hold and drag to reorder the open chats, or onto x to remove
A 300 ms hold lifts a chat in the open column; dragging opens a gap and dropping commits through ChatWorkspaceController.movePane, the pane order the server syncs. An x comes in at the bottom while dragging; dropping on it removes the chat with Undo, which restores its place. Escape, a cancelled pointer or a drop away from the column put it back. Move up, Move down and Remove are semantic actions. Repaint-only motion; reduced motion swaps at once. Also keep floating-layout tracking out of initState, and let the capture kit hold a press before a drag. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,230 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/semantics.dart';
|
||||
|
||||
import '../../../ui/theme/app_design_tokens.dart';
|
||||
import 'chat_stack_column.dart';
|
||||
import 'chat_stack_disc.dart';
|
||||
import 'chat_stack_drag.dart';
|
||||
import 'chat_stack_drag_shift.dart';
|
||||
import 'chat_stack_entry.dart';
|
||||
import 'chat_stack_handles.dart';
|
||||
import 'chat_stack_motion.dart';
|
||||
import 'chat_stack_pose.dart';
|
||||
|
||||
/// The open column's avatars and name pills, each placed at the stack's
|
||||
/// slot and moved by the open motion ([ChatStackPoseTransition]) and by a
|
||||
/// drag ([ChatStackDragShift]), painted in [order].
|
||||
class ChatStackColumnItems extends StatelessWidget {
|
||||
const ChatStackColumnItems({
|
||||
super.key,
|
||||
required this.motion,
|
||||
required this.entries,
|
||||
required this.order,
|
||||
required this.labelMax,
|
||||
required this.drag,
|
||||
required this.draggable,
|
||||
required this.onOpen,
|
||||
required this.onAdd,
|
||||
required this.onDragStart,
|
||||
required this.onDragMove,
|
||||
required this.onDragEnd,
|
||||
this.onRemove,
|
||||
this.onReorder,
|
||||
});
|
||||
|
||||
final ChatStackMotion motion;
|
||||
final List<ChatStackEntry> entries;
|
||||
|
||||
/// Item indices in paint order, the last on top.
|
||||
final List<int> order;
|
||||
final double labelMax;
|
||||
final ChatStackDrag drag;
|
||||
|
||||
/// Whether a hold lifts a chat.
|
||||
final bool draggable;
|
||||
final ValueChanged<ChatStackEntry> onOpen;
|
||||
final VoidCallback onAdd;
|
||||
final ValueChanged<ChatStackEntry> onDragStart;
|
||||
final ValueChanged<LongPressMoveUpdateDetails> onDragMove;
|
||||
final ValueChanged<ChatStackEntry> onDragEnd;
|
||||
final ValueChanged<ChatStackEntry>? onRemove;
|
||||
final void Function(ChatStackEntry entry, int index)? onReorder;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => Stack(
|
||||
clipBehavior: Clip.none,
|
||||
children: [
|
||||
for (final i in order) ...[_label(context, i), _item(context, i)],
|
||||
],
|
||||
);
|
||||
|
||||
ChatStackEntry? _entry(int i) => i < entries.length ? entries[i] : null;
|
||||
|
||||
/// [child] lifted by a hold when [entry] can be dragged.
|
||||
Widget _handle(ChatStackEntry? entry, Widget child) => ChatStackDragHandle(
|
||||
onStart: entry == null || !draggable ? null : () => onDragStart(entry),
|
||||
onMove: onDragMove,
|
||||
onEnd: entry == null ? null : () => onDragEnd(entry),
|
||||
onCancel: drag.cancel,
|
||||
child: child,
|
||||
);
|
||||
|
||||
/// [child] where the drag paints [entry]'s item; Add chat never moves.
|
||||
Widget _shift(ChatStackEntry? entry, Widget child, {bool scales = true}) =>
|
||||
entry == null
|
||||
? child
|
||||
: ChatStackDragShift(
|
||||
item: drag.item(entry.paneId),
|
||||
scales: scales,
|
||||
child: child,
|
||||
);
|
||||
|
||||
Animation<double>? _lift(ChatStackEntry? entry) =>
|
||||
entry != null && entry.paneId == drag.lifted ? drag.lift : null;
|
||||
|
||||
Widget _item(BuildContext context, int i) {
|
||||
final entry = _entry(i);
|
||||
return PositionedDirectional(
|
||||
key: ValueKey('chat-stack-item-${entry?.paneId ?? 'add'}'),
|
||||
end: 0,
|
||||
bottom: 0,
|
||||
// The transforms are outermost: the boxes under them sit at the
|
||||
// stack's slot, and only a transform passes hits on to where it paints
|
||||
// them.
|
||||
child: ChatStackPoseTransition(
|
||||
progress: motion.move[i],
|
||||
from: motion.from[i],
|
||||
to: motion.target[i],
|
||||
child: _shift(
|
||||
entry,
|
||||
FadeTransition(
|
||||
opacity: motion.fade[i],
|
||||
child: KeyedSubtree(
|
||||
key: ValueKey('chat-stack-button-${entry?.paneId ?? 'add'}'),
|
||||
child: entry == null
|
||||
? _addButton(context)
|
||||
: _chatButton(context, entry, i),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _label(BuildContext context, int i) {
|
||||
final entry = _entry(i);
|
||||
return PositionedDirectional(
|
||||
key: ValueKey('chat-stack-label-${entry?.paneId ?? 'add'}'),
|
||||
end: kChatStackSlot + kChatStackLabelGap,
|
||||
bottom: 0,
|
||||
height: kChatStackSlot,
|
||||
child: ChatStackPoseTransition(
|
||||
progress: motion.label[i],
|
||||
from: motion.labelFrom[i],
|
||||
to: motion.target[i],
|
||||
// The pill moves with its avatar but keeps its size, so the gap
|
||||
// between them stays even.
|
||||
child: _shift(
|
||||
entry,
|
||||
scales: false,
|
||||
ExcludeSemantics(
|
||||
child: FadeTransition(
|
||||
opacity: motion.label[i],
|
||||
child: Align(
|
||||
alignment: AlignmentDirectional.centerEnd,
|
||||
widthFactor: 1,
|
||||
child: ConstrainedBox(
|
||||
constraints: BoxConstraints(maxWidth: labelMax),
|
||||
child: _handle(
|
||||
entry,
|
||||
GestureDetector(
|
||||
onTap: entry == null ? onAdd : () => onOpen(entry),
|
||||
child: ChatStackLabel(
|
||||
text: entry?.title ?? ChatStackColumn.addLabel,
|
||||
color: entry?.color(context),
|
||||
emphasized: entry?.current ?? false,
|
||||
lift: _lift(entry),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _chatButton(BuildContext context, ChatStackEntry entry, int index) {
|
||||
final remove = onRemove;
|
||||
final reorder = onReorder;
|
||||
final last = entries.length - 1;
|
||||
final ring = entry.current
|
||||
? entry.color(context) ?? Theme.of(context).colorScheme.primary
|
||||
: null;
|
||||
// Up is toward the top of the column: a later place in the order.
|
||||
final actions = <CustomSemanticsAction, VoidCallback>{
|
||||
if (reorder != null && index < last)
|
||||
const CustomSemanticsAction(label: ChatStackColumn.moveUpLabel): () =>
|
||||
reorder(entry, index + 1),
|
||||
if (reorder != null && index > 0)
|
||||
const CustomSemanticsAction(label: ChatStackColumn.moveDownLabel): () =>
|
||||
reorder(entry, index - 1),
|
||||
if (remove != null)
|
||||
const CustomSemanticsAction(label: ChatStackColumn.removeLabel): () =>
|
||||
remove(entry),
|
||||
};
|
||||
return Semantics(
|
||||
container: true,
|
||||
button: true,
|
||||
selected: entry.current,
|
||||
label: entry.title,
|
||||
hint: entry.current ? 'Open now' : null,
|
||||
onTap: () => onOpen(entry),
|
||||
customSemanticsActions: actions.isEmpty ? null : actions,
|
||||
child: _handle(
|
||||
entry,
|
||||
ChatStackTappable(
|
||||
autofocus: entry.current,
|
||||
onTap: () => onOpen(entry),
|
||||
child: ChatStackDisc(
|
||||
ring: ring,
|
||||
lift: _lift(entry),
|
||||
child: chatStackAvatar(entry),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _addButton(BuildContext context) {
|
||||
final scheme = Theme.of(context).colorScheme;
|
||||
final tokens = AppDesignTokens.of(context);
|
||||
return Semantics(
|
||||
container: true,
|
||||
button: true,
|
||||
label: ChatStackColumn.addLabel,
|
||||
onTap: onAdd,
|
||||
child: ChatStackTappable(
|
||||
onTap: onAdd,
|
||||
child: ChatStackDisc(
|
||||
child: DecoratedBox(
|
||||
decoration: ShapeDecoration(
|
||||
color: tokens.flat ? null : scheme.primaryContainer,
|
||||
shape: chatStackShape(tokens).copyWith(
|
||||
side: tokens.flat
|
||||
? BorderSide(color: scheme.primary.withValues(alpha: .55))
|
||||
: BorderSide.none,
|
||||
),
|
||||
),
|
||||
child: Icon(
|
||||
Icons.add,
|
||||
color: tokens.flat ? scheme.primary : scheme.onPrimaryContainer,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user