130c1e6708
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>
114 lines
3.6 KiB
Dart
114 lines
3.6 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,
|
|
}) : 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.add(rtl ? layer.mirrored() : layer);
|
|
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();
|
|
}
|
|
}
|