efaa0d9fca
A chat dropped onto the middle of another makes a named group (asked at once, "Group N" by default); onto a group it joins, a group dropped onto a chat takes it in, groups merge. The top level shows each group as a small pile with its name and count; a tap opens it in place under a header that leads back (also the scrim, Back and Escape). In a group, dropping a chat on the header leaves the group; a group of one dissolves. The close button ungroups a dropped group with Undo. Rename, Ungroup, Close all (with Undo), Move to group and Remove from group are in the group menu and as semantic actions. Each open-chat entry carries its group name (protocol field "group", omitted when ungrouped; older clients ignore it), stored and pushed by the server like the order; names are trimmed, printable, at most 80 characters. Needs a server restart to keep groups. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
124 lines
4.0 KiB
Dart
124 lines
4.0 KiB
Dart
import 'dart:math' as math;
|
|
|
|
import 'package:flutter/animation.dart';
|
|
|
|
import 'chat_stack_disc.dart';
|
|
import 'chat_stack_pose.dart';
|
|
|
|
/// How long the stack takes to fan out into its column and to fold back.
|
|
const Duration chatStackOpenDuration = Duration(milliseconds: 280);
|
|
const Duration chatStackCloseDuration = Duration(milliseconds: 220);
|
|
|
|
/// Under reduced motion the column only fades in and out, in place.
|
|
const Duration chatStackFadeDuration = Duration(milliseconds: 120);
|
|
|
|
/// A short spring-like ease: a touch of overshoot on arrival, no bounce back.
|
|
const Curve chatStackRise = Cubic(.22, 1.18, .36, 1);
|
|
|
|
/// Folding plays the controller backwards: an ease-in in forward time leaves
|
|
/// the column briskly and settles gently into the pile.
|
|
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, 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,
|
|
required List<int?> depths,
|
|
required this.reduced,
|
|
required bool rtl,
|
|
int originSlot = 0,
|
|
double pileScale = 1,
|
|
}) : 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];
|
|
// 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) {
|
|
from.add(to);
|
|
move.add(parent);
|
|
fade.add(parent);
|
|
label.add(parent);
|
|
labelFrom.add(to);
|
|
continue;
|
|
}
|
|
// From its layer in the pile (a group's smaller pile [originSlot]
|
|
// slots up the column).
|
|
final pile = ChatStackPose(
|
|
offset:
|
|
layer.offset * pileScale + Offset(0, -originSlot * kChatStackPitch),
|
|
turn: layer.turn,
|
|
scale: layer.scale * pileScale,
|
|
);
|
|
from.add(rtl ? pile.mirrored() : pile);
|
|
move.add(
|
|
_curve(
|
|
parent,
|
|
Interval(start, end, curve: chatStackRise),
|
|
Interval(start, end, curve: chatStackFold),
|
|
),
|
|
);
|
|
// A chat that was not drawn in the pile appears as it leaves it.
|
|
fade.add(
|
|
depth != null
|
|
? kAlwaysCompleteAnimation
|
|
: _curve(parent, Interval(start, math.min(1, start + span * .5))),
|
|
);
|
|
final labelStart = start + span * .45;
|
|
label.add(
|
|
_curve(parent, Interval(labelStart, end, curve: Curves.easeOut)),
|
|
);
|
|
labelFrom.add(
|
|
ChatStackPose(offset: Offset(rtl ? -8 : 8, to.offset.dy), scale: .96),
|
|
);
|
|
}
|
|
}
|
|
|
|
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 = [];
|
|
final List<Animation<double>> fade = [];
|
|
final List<Animation<double>> label = [];
|
|
final List<ChatStackPose> labelFrom = [];
|
|
final List<CurvedAnimation> _owned = [];
|
|
|
|
Animation<double> _curve(
|
|
Animation<double> parent,
|
|
Curve curve, [
|
|
Curve? reverse,
|
|
]) {
|
|
final curved = CurvedAnimation(
|
|
parent: parent,
|
|
curve: curve,
|
|
reverseCurve: reverse,
|
|
);
|
|
_owned.add(curved);
|
|
return curved;
|
|
}
|
|
|
|
void dispose() {
|
|
for (final curved in _owned) {
|
|
curved.dispose();
|
|
}
|
|
_owned.clear();
|
|
}
|
|
}
|