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

View File

@@ -125,6 +125,28 @@ void main() {
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),
);
});
});
});
}