Add quick switch motion library with true deck exchanges
This commit is contained in:
@@ -0,0 +1,72 @@
|
||||
import 'dart:math' as math;
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/ui/motion/quick_switch_animation.dart';
|
||||
import 'package:pipelines_app/ui/motion/quick_switch_effect.dart';
|
||||
|
||||
void main() {
|
||||
const full = Rect.fromLTWH(0, 0, 560, 635);
|
||||
const peek = Rect.fromLTWH(0, 641, 560, 159);
|
||||
|
||||
test('both deck styles leave the front before changing stacking order', () {
|
||||
for (final style in [
|
||||
QuickSwitchAnimation.cardStack,
|
||||
QuickSwitchAnimation.deckSlide,
|
||||
]) {
|
||||
expect(
|
||||
quickSwitchRect(style, .3, full, peek, outgoing: true).size,
|
||||
full.size,
|
||||
);
|
||||
expect(quickSwitchOutgoingOnTop(style, .49), isTrue);
|
||||
expect(quickSwitchOutgoingOnTop(style, .5), isFalse);
|
||||
final pose = quickSwitchPose(style, .5, outgoing: true);
|
||||
expect(pose.translation.dx.abs(), greaterThan(1));
|
||||
expect(pose.rotationX, 0);
|
||||
expect(pose.rotationY, 0);
|
||||
expect(pose.rotationZ.abs(), lessThan(math.pi / 12));
|
||||
expect(quickSwitchRect(style, 1, full, peek, outgoing: true), peek);
|
||||
}
|
||||
});
|
||||
|
||||
test('every style settles without residual transforms or missing cards', () {
|
||||
for (final style in QuickSwitchAnimation.values) {
|
||||
for (final outgoing in [true, false]) {
|
||||
for (final t in [0.0, 1.0]) {
|
||||
final pose = quickSwitchPose(style, t, outgoing: outgoing);
|
||||
expect(pose.translation, Offset.zero, reason: '$style at $t');
|
||||
expect(pose.scale, 1, reason: '$style at $t');
|
||||
expect(pose.opacity, 1, reason: '$style at $t');
|
||||
expect(
|
||||
pose.transform(full.size),
|
||||
Matrix4.identity(),
|
||||
reason: '$style at $t',
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
test('all choices have finite bounded geometry throughout a transition', () {
|
||||
for (final style in QuickSwitchAnimation.values) {
|
||||
for (final outgoing in [true, false]) {
|
||||
for (var i = 0; i <= 100; i++) {
|
||||
final pose = quickSwitchPose(style, i / 100, outgoing: outgoing);
|
||||
expect(pose.opacity, inInclusiveRange(0, 1));
|
||||
expect(pose.scale, greaterThan(0));
|
||||
expect(
|
||||
pose.transform(full.size).storage.every((v) => v.isFinite),
|
||||
isTrue,
|
||||
);
|
||||
final rect = quickSwitchRect(
|
||||
style,
|
||||
i / 100,
|
||||
full,
|
||||
peek,
|
||||
outgoing: outgoing,
|
||||
);
|
||||
expect(rect.height, inInclusiveRange(peek.height, full.height));
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user