Reduce quick switch layout churn and flatten planar depth transforms
This commit is contained in:
@@ -12,10 +12,12 @@ class ChatPanePresentation extends InheritedWidget {
|
||||
super.key,
|
||||
required this.peek,
|
||||
required this.barReveal,
|
||||
this.fixedChromeLayout = false,
|
||||
required super.child,
|
||||
});
|
||||
|
||||
final bool peek;
|
||||
final bool fixedChromeLayout;
|
||||
final Animation<double> barReveal;
|
||||
|
||||
static ChatPanePresentation? maybeOf(BuildContext context) =>
|
||||
@@ -23,7 +25,9 @@ class ChatPanePresentation extends InheritedWidget {
|
||||
|
||||
@override
|
||||
bool updateShouldNotify(ChatPanePresentation oldWidget) =>
|
||||
peek != oldWidget.peek || barReveal != oldWidget.barReveal;
|
||||
peek != oldWidget.peek ||
|
||||
barReveal != oldWidget.barReveal ||
|
||||
fixedChromeLayout != oldWidget.fixedChromeLayout;
|
||||
}
|
||||
|
||||
/// The conversation's bar under a [ChatPanePresentation].
|
||||
@@ -60,7 +64,9 @@ class ChatPaneBarReveal extends StatelessWidget {
|
||||
ignoring: peek,
|
||||
child: SizeTransition(
|
||||
alignment: Alignment.topCenter,
|
||||
sizeFactor: reveal,
|
||||
sizeFactor: presentation.fixedChromeLayout
|
||||
? const AlwaysStoppedAnimation(1.0)
|
||||
: reveal,
|
||||
child: FadeTransition(
|
||||
opacity: reveal,
|
||||
child: SlideTransition(
|
||||
|
||||
@@ -67,6 +67,7 @@ class ChatMobilePaneViewport extends StatelessWidget {
|
||||
required this.peek,
|
||||
required this.active,
|
||||
required this.barReveal,
|
||||
this.fixedChromeLayout = false,
|
||||
required this.child,
|
||||
required this.onActivate,
|
||||
required this.label,
|
||||
@@ -75,6 +76,7 @@ class ChatMobilePaneViewport extends StatelessWidget {
|
||||
|
||||
final bool peek;
|
||||
final bool active;
|
||||
final bool fixedChromeLayout;
|
||||
|
||||
/// The bar's reveal for this pane's role (see [ChatPanePresentation]).
|
||||
final Animation<double> barReveal;
|
||||
@@ -103,6 +105,7 @@ class ChatMobilePaneViewport extends StatelessWidget {
|
||||
child: ChatPanePresentation(
|
||||
peek: peek,
|
||||
barReveal: barReveal,
|
||||
fixedChromeLayout: fixedChromeLayout,
|
||||
child: child,
|
||||
),
|
||||
),
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
import 'package:flutter/widgets.dart';
|
||||
|
||||
/// Keeps the expensive transcript layout at one useful size while its card's
|
||||
/// painted rectangle moves. Resting peek constraints remain the real viewport.
|
||||
class ChatMotionViewport extends StatelessWidget {
|
||||
const ChatMotionViewport({
|
||||
super.key,
|
||||
required this.size,
|
||||
required this.child,
|
||||
});
|
||||
final Size? size;
|
||||
final Widget child;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => LayoutBuilder(
|
||||
builder: (context, constraints) {
|
||||
final viewport = size ?? constraints.biggest;
|
||||
return ClipRect(
|
||||
child: OverflowBox(
|
||||
alignment: Alignment.topLeft,
|
||||
minWidth: viewport.width,
|
||||
maxWidth: viewport.width,
|
||||
minHeight: viewport.height,
|
||||
maxHeight: viewport.height,
|
||||
child: child,
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
@@ -259,6 +259,7 @@ class _ChatWorkspaceState extends State<ChatWorkspace>
|
||||
peek: peek,
|
||||
active: active,
|
||||
barReveal: _motion.revealFor(pane.id),
|
||||
fixedChromeLayout: _motion.isAnimating && !_motion.isTape,
|
||||
label: widget.paneTitle?.call(pane) ?? pane.sessionId,
|
||||
paneId: pane.id,
|
||||
onActivate: () {
|
||||
|
||||
@@ -7,6 +7,7 @@ import 'chat_pane_backdrop.dart';
|
||||
import 'chat_pane_switch_motion.dart';
|
||||
import 'chat_tape_exit.dart';
|
||||
import 'chat_switch_card.dart';
|
||||
import 'chat_motion_viewport.dart';
|
||||
import 'chat_workspace_controller.dart';
|
||||
import 'chat_workspace_divider.dart';
|
||||
import 'chat_workspace_geometry.dart';
|
||||
@@ -87,7 +88,12 @@ Widget chatWorkspaceSurface({
|
||||
child: ChatSwitchCard(
|
||||
motion: motion,
|
||||
outgoing: motion.isRetainedOutgoing(pane.id),
|
||||
child: child!,
|
||||
child: ChatMotionViewport(
|
||||
size: mobile != null && motion.isAnimating && !motion.isTape
|
||||
? motion.viewportRectFor(pane.id)?.size
|
||||
: null,
|
||||
child: child!,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
@@ -18,18 +18,34 @@ class QuickSwitchPose {
|
||||
final Offset translation;
|
||||
final double scale, rotationX, rotationY, rotationZ, depth, opacity, shadow;
|
||||
|
||||
Matrix4 transform(Size size) => Matrix4.identity()
|
||||
..setEntry(3, 2, rotationX != 0 || rotationY != 0 || depth != 0 ? .0012 : 0)
|
||||
..translateByDouble(
|
||||
translation.dx * size.width,
|
||||
translation.dy * size.height,
|
||||
depth,
|
||||
1,
|
||||
)
|
||||
..rotateX(rotationX)
|
||||
..rotateY(rotationY)
|
||||
..rotateZ(rotationZ)
|
||||
..scaleByDouble(scale, scale, scale, 1);
|
||||
Matrix4 transform(Size size) {
|
||||
// A flat card at constant depth projects to a uniform 2D scale. Keep it
|
||||
// affine so backdrop filters do not enter the renderer's 3D path.
|
||||
if (rotationX == 0 && rotationY == 0) {
|
||||
final projection = 1 / (1 + .0012 * depth);
|
||||
return Matrix4.identity()
|
||||
..translateByDouble(
|
||||
translation.dx * size.width * projection,
|
||||
translation.dy * size.height * projection,
|
||||
0,
|
||||
1,
|
||||
)
|
||||
..rotateZ(rotationZ)
|
||||
..scaleByDouble(scale * projection, scale * projection, 1, 1);
|
||||
}
|
||||
return Matrix4.identity()
|
||||
..setEntry(3, 2, .0012)
|
||||
..translateByDouble(
|
||||
translation.dx * size.width,
|
||||
translation.dy * size.height,
|
||||
depth,
|
||||
1,
|
||||
)
|
||||
..rotateX(rotationX)
|
||||
..rotateY(rotationY)
|
||||
..rotateZ(rotationZ)
|
||||
..scaleByDouble(scale, scale, scale, 1);
|
||||
}
|
||||
}
|
||||
|
||||
bool quickSwitchOutgoingOnTop(QuickSwitchAnimation style, double progress) =>
|
||||
|
||||
Reference in New Issue
Block a user