Animate retained mobile chat reopening without remounting panes
This commit is contained in:
@@ -1334,7 +1334,8 @@ class _ChatThreadViewState extends State<ChatThreadView> {
|
||||
? null
|
||||
: ChatSessionAvatar(session: session, selected: true),
|
||||
identityHeroTag:
|
||||
session != null &&
|
||||
widget.useNativeBack &&
|
||||
session != null &&
|
||||
MediaQuery.sizeOf(context).width < kListDetailMinWidth &&
|
||||
!(MediaQuery.maybeDisableAnimationsOf(context) ?? false)
|
||||
? 'chat-identity-${widget.sessionId}'
|
||||
|
||||
@@ -24,6 +24,7 @@ import 'conversation/chat_add_pane_picker.dart';
|
||||
import 'conversation/chat_sidebar_controls.dart';
|
||||
import 'ui/sessions/chat_compact_sidebar.dart';
|
||||
import 'workspace/chat_workspace.dart';
|
||||
import 'workspace/chat_workspace_entrance.dart';
|
||||
import 'ui/sessions/chat_adaptive.dart';
|
||||
import 'conversation/chat_row_widgets.dart';
|
||||
import 'conversation/chat_scroll.dart';
|
||||
@@ -572,8 +573,10 @@ class _ChatScreenState extends State<ChatScreen>
|
||||
offstage: selected != null,
|
||||
child: ExcludeFocus(excluding: selected != null, child: list),
|
||||
),
|
||||
Offstage(
|
||||
offstage: selected == null,
|
||||
ChatWorkspaceEntrance(
|
||||
visible: selected != null,
|
||||
cupertino:
|
||||
chatControlsStyleOf(context) == ChatControlsStyle.cupertino,
|
||||
child: ExcludeFocus(
|
||||
excluding: selected == null,
|
||||
child: MediaQuery(
|
||||
|
||||
@@ -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!),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user