Animate retained mobile chat reopening without remounting panes

This commit is contained in:
2026-11-08 00:22:51 +00:00
parent 1a674297c1
commit d189f61eee
6 changed files with 240 additions and 4 deletions
@@ -0,0 +1,102 @@
import 'package:flutter/cupertino.dart';
import '../../../ui/motion/motion.dart';
/// Reopens a retained mobile workspace without moving it to another route.
/// Its child keeps the same element, scroll positions, panes and drafts.
class ChatWorkspaceEntrance extends StatefulWidget {
const ChatWorkspaceEntrance({
super.key,
required this.visible,
required this.cupertino,
required this.child,
});
final bool visible;
final bool cupertino;
final Widget child;
@override
State<ChatWorkspaceEntrance> createState() => _ChatWorkspaceEntranceState();
}
class _ChatWorkspaceEntranceState extends State<ChatWorkspaceEntrance>
with SingleTickerProviderStateMixin {
late final _controller = AnimationController(
vsync: this,
value: widget.visible ? 1 : 0,
);
late final _curve = CurvedAnimation(
parent: _controller,
curve: Motion.curve,
reverseCurve: Curves.easeInCubic,
);
@override
void didChangeDependencies() {
super.didChangeDependencies();
_controller.duration = Motion.of(context, Motion.tabEntranceDuration);
if (_controller.duration == Duration.zero) {
_controller.value = widget.visible ? 1 : 0;
}
}
@override
void didUpdateWidget(ChatWorkspaceEntrance oldWidget) {
super.didUpdateWidget(oldWidget);
if (oldWidget.visible != widget.visible) {
if (_controller.duration == Duration.zero) {
_controller.value = widget.visible ? 1 : 0;
} else if (widget.visible) {
_controller.forward();
} else {
_controller.reverse();
}
}
}
@override
void dispose() {
_curve.dispose();
_controller.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
final content = HeroMode(
// The initial pushed page has a native Hero. Here both surfaces share
// one route; only the workspace entrance animates, never duplicate tags.
enabled: false,
child: TickerMode(enabled: widget.visible, child: widget.child),
);
final transition = widget.cupertino
? CupertinoPageTransition(
primaryRouteAnimation: _controller,
secondaryRouteAnimation: const AlwaysStoppedAnimation(0),
linearTransition: false,
child: content,
)
: FadeTransition(
opacity: _curve,
child: SlideTransition(
position: Tween<Offset>(
begin: const Offset(0, 0.08),
end: Offset.zero,
).animate(_curve),
child: content,
),
);
return AnimatedBuilder(
animation: _controller,
child: transition,
builder: (context, child) => Offstage(
offstage: !widget.visible && _controller.isDismissed,
child: IgnorePointer(
ignoring: !widget.visible,
child: ExcludeSemantics(excluding: !widget.visible, child: child!),
),
),
);
}
}