fix: Added useArtboardSize functionality (#2294)

This commit is contained in:
Anas
2023-01-28 20:25:36 +05:30
committed by GitHub
parent 7662118d14
commit 00b0dbef0d
2 changed files with 33 additions and 4 deletions

View File

@@ -17,13 +17,19 @@ class RiveComponent extends PositionComponent {
RiveComponent({ RiveComponent({
required this.artboard, required this.artboard,
bool antialiasing = true, bool antialiasing = true,
@Deprecated(
"Will be removed in v1.8.0, use size's default value for ArtboardSize",
)
bool useArtboardSize = true, bool useArtboardSize = true,
BoxFit fit = BoxFit.contain, BoxFit fit = BoxFit.contain,
Alignment alignment = Alignment.center, Alignment alignment = Alignment.center,
// position component arguments // position component arguments
super.position, super.position,
super.size,
/// The logical size of the component.
/// Default value is ArtboardSize
Vector2? size,
super.scale, super.scale,
double super.angle = 0.0, double super.angle = 0.0,
Anchor super.anchor = Anchor.topLeft, Anchor super.anchor = Anchor.topLeft,
@@ -35,7 +41,8 @@ class RiveComponent extends PositionComponent {
fit: fit, fit: fit,
alignment: alignment, alignment: alignment,
artboard: artboard, artboard: artboard,
); ),
super(size: size ?? Vector2(artboard.width, artboard.height));
@override @override
void render(ui.Canvas canvas) { void render(ui.Canvas canvas) {

View File

@@ -125,6 +125,28 @@ void main() {
expect(riveComponent.artboard.antialiasing, isFalse); expect(riveComponent.artboard.antialiasing, isFalse);
}); });
}); });
group('Component size', () {
test('use specifiy size', () async {
final skillsArtboard = await loadArtboard(riveFile);
final riveComponent = RiveComponent(
artboard: skillsArtboard,
size: Vector2.all(250.0),
);
expect(riveComponent.size, Vector2.all(250.0));
});
test('deafult value (ArtboardSize)', () async {
final skillsArtboard = await loadArtboard(riveFile);
final riveComponent = RiveComponent(artboard: skillsArtboard);
expect(
riveComponent.size,
Vector2(skillsArtboard.width, skillsArtboard.height),
);
});
});
}); });
} }