Add opposing arc swap animation for chat quick switch
This commit is contained in:
@@ -159,51 +159,63 @@ void main() {
|
||||
});
|
||||
}
|
||||
|
||||
testWidgets('card stack cycles all added panes and settles reduced motion', (
|
||||
tester,
|
||||
) async {
|
||||
phone(tester);
|
||||
SharedPreferences.setMockInitialValues({});
|
||||
await QuickSwitchAnimationController.instance.setAnimation(
|
||||
QuickSwitchAnimation.cardStack,
|
||||
);
|
||||
addTearDown(
|
||||
() => QuickSwitchAnimationController.instance.setAnimation(
|
||||
QuickSwitchAnimation.tape,
|
||||
),
|
||||
);
|
||||
final controller = ChatWorkspaceController()..open('a');
|
||||
for (final id in ['b', 'c']) {
|
||||
controller.splitActive(id, ChatSplitAxis.horizontal);
|
||||
}
|
||||
await tester.pumpWidget(_host(controller));
|
||||
await tester.pumpAndSettle();
|
||||
final states = {
|
||||
for (final id in ['a', 'b', 'c'])
|
||||
id: tester.state<_DraftState>(
|
||||
find.byKey(ValueKey(id), skipOffstage: false),
|
||||
),
|
||||
};
|
||||
for (final id in ['a', 'b', 'c', 'a']) {
|
||||
final pane = controller.panes.firstWhere((p) => p.sessionId == id);
|
||||
await tester.tap(find.byKey(ValueKey('chat-peek-${pane.id}')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(controller.activePane!.sessionId, id);
|
||||
for (final entry in states.entries) {
|
||||
expect(
|
||||
tester.state(find.byKey(ValueKey(entry.key), skipOffstage: false)),
|
||||
same(entry.value),
|
||||
for (final ringStyle in [
|
||||
QuickSwitchAnimation.cardStack,
|
||||
QuickSwitchAnimation.arcSwap,
|
||||
]) {
|
||||
testWidgets(
|
||||
'${ringStyle.name} cycles all added panes and settles reduced motion',
|
||||
(tester) async {
|
||||
phone(tester);
|
||||
SharedPreferences.setMockInitialValues({});
|
||||
await QuickSwitchAnimationController.instance.setAnimation(ringStyle);
|
||||
addTearDown(
|
||||
() => QuickSwitchAnimationController.instance.setAnimation(
|
||||
QuickSwitchAnimation.tape,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
await tester.pumpWidget(_host(controller, reduced: true));
|
||||
controller.activate(
|
||||
controller.panes.firstWhere((p) => p.sessionId == 'b').id,
|
||||
final controller = ChatWorkspaceController()..open('a');
|
||||
for (final id in ['b', 'c']) {
|
||||
controller.splitActive(id, ChatSplitAxis.horizontal);
|
||||
}
|
||||
await tester.pumpWidget(_host(controller));
|
||||
await tester.pumpAndSettle();
|
||||
final states = {
|
||||
for (final id in ['a', 'b', 'c'])
|
||||
id: tester.state<_DraftState>(
|
||||
find.byKey(ValueKey(id), skipOffstage: false),
|
||||
),
|
||||
};
|
||||
controller.resizeMobilePeek(.12);
|
||||
for (final entry in states.entries) {
|
||||
entry.value.controller.text = 'Draft ${entry.key}';
|
||||
}
|
||||
for (final id in ['a', 'b', 'c', 'a']) {
|
||||
final pane = controller.panes.firstWhere((p) => p.sessionId == id);
|
||||
await tester.tap(find.byKey(ValueKey('chat-peek-${pane.id}')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(controller.activePane!.sessionId, id);
|
||||
for (final entry in states.entries) {
|
||||
expect(
|
||||
tester.state(
|
||||
find.byKey(ValueKey(entry.key), skipOffstage: false),
|
||||
),
|
||||
same(entry.value),
|
||||
);
|
||||
expect(entry.value.controller.text, 'Draft ${entry.key}');
|
||||
}
|
||||
expect(controller.mobilePeekFraction, .12);
|
||||
}
|
||||
await tester.pumpWidget(_host(controller, reduced: true));
|
||||
controller.activate(
|
||||
controller.panes.firstWhere((p) => p.sessionId == 'b').id,
|
||||
);
|
||||
await tester.pump();
|
||||
expect(tester.getRect(rect(controller.activePaneId!)).top, 0);
|
||||
expect(find.byKey(const ValueKey('chat-swap-exit')), findsNothing);
|
||||
await tester.pumpWidget(const SizedBox());
|
||||
controller.dispose();
|
||||
},
|
||||
);
|
||||
await tester.pump();
|
||||
expect(tester.getRect(rect(controller.activePaneId!)).top, 0);
|
||||
expect(find.byKey(const ValueKey('chat-swap-exit')), findsNothing);
|
||||
await tester.pumpWidget(const SizedBox());
|
||||
controller.dispose();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ void main() {
|
||||
await tester.pumpAndSettle();
|
||||
expect(workspace.controller.activePaneId, isNot(active));
|
||||
expect(tester.binding.transientCallbackCount, 0);
|
||||
await tester.pumpWidget(_host(QuickSwitchAnimation.swap));
|
||||
await tester.pumpWidget(_host(QuickSwitchAnimation.arcSwap));
|
||||
await tester.pumpAndSettle();
|
||||
expect(
|
||||
tester.widget<ChatWorkspace>(find.byType(ChatWorkspace)).controller,
|
||||
@@ -35,7 +35,7 @@ void main() {
|
||||
);
|
||||
expect(
|
||||
tester.widget<ChatWorkspace>(find.byType(ChatWorkspace)).animationStyle,
|
||||
QuickSwitchAnimation.swap,
|
||||
QuickSwitchAnimation.arcSwap,
|
||||
);
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
|
||||
@@ -39,6 +39,50 @@ void main() {
|
||||
}
|
||||
});
|
||||
|
||||
test(
|
||||
'arc swap bows to opposite sides while both cards travel vertically',
|
||||
() {
|
||||
const style = QuickSwitchAnimation.arcSwap;
|
||||
for (final t in [.25, .5, .75]) {
|
||||
final outgoing = quickSwitchPose(style, t, outgoing: true);
|
||||
final incoming = quickSwitchPose(style, t, outgoing: false);
|
||||
expect(outgoing.translation.dx, lessThan(0));
|
||||
expect(incoming.translation.dx, greaterThan(0));
|
||||
expect(
|
||||
outgoing.translation.dx,
|
||||
closeTo(-incoming.translation.dx, 1e-9),
|
||||
);
|
||||
expect(outgoing.rotationX, 0);
|
||||
expect(outgoing.rotationY, 0);
|
||||
expect(outgoing.transform(full.size).entry(3, 2), 0);
|
||||
expect(outgoing.opacity, 1);
|
||||
expect(incoming.opacity, 1);
|
||||
expect(
|
||||
quickSwitchRect(style, t, full, peek, outgoing: true),
|
||||
Rect.lerp(full, peek, t),
|
||||
);
|
||||
expect(
|
||||
quickSwitchRect(style, t, peek, full, outgoing: false),
|
||||
Rect.lerp(peek, full, t),
|
||||
);
|
||||
}
|
||||
final quarter = quickSwitchPose(
|
||||
style,
|
||||
.25,
|
||||
outgoing: false,
|
||||
).translation.dx;
|
||||
final middle = quickSwitchPose(style, .5, outgoing: false).translation.dx;
|
||||
final threeQuarter = quickSwitchPose(
|
||||
style,
|
||||
.75,
|
||||
outgoing: false,
|
||||
).translation.dx;
|
||||
expect(quarter, closeTo(threeQuarter, 1e-9));
|
||||
expect(middle, greaterThan(quarter));
|
||||
expect(middle, closeTo(.38, 1e-9));
|
||||
},
|
||||
);
|
||||
|
||||
test('every style settles without residual transforms or missing cards', () {
|
||||
for (final style in QuickSwitchAnimation.values) {
|
||||
for (final outgoing in [true, false]) {
|
||||
|
||||
Reference in New Issue
Block a user