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,106 @@
|
||||
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),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user