Skip to content

Commit

Permalink
fix: Added useArtboardSize functionality (#2294)
Browse files Browse the repository at this point in the history
  • Loading branch information
Anas35 authored Jan 28, 2023
1 parent 7662118 commit 00b0dbe
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 4 deletions.
15 changes: 11 additions & 4 deletions packages/flame_rive/lib/src/rive_component.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
22 changes: 22 additions & 0 deletions packages/flame_rive/test/flame_rive_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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),
);
});
});
});
}

Expand Down

0 comments on commit 00b0dbe

Please sign in to comment.