Skip to content

Commit

Permalink
Fix Flutter not allowing negative rotation.
Browse files Browse the repository at this point in the history
  • Loading branch information
bernaferrari committed Jul 20, 2020
1 parent cce80e8 commit d4af2f3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
14 changes: 14 additions & 0 deletions __tests__/flutter/builderImpl/flutterBlend.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,25 @@ describe("Flutter Blend", () => {
// undefined (unitialized, only happen on tests)
expect(flutterRotation(node, "")).toEqual("");

// test small negative value to check if output will be nothing
node.rotation = -7.0167096047110005e-15;
expect(flutterRotation(node, "")).toEqual("");

node.rotation = 45;
expect(flutterRotation(node, "test")).toEqual(
"Transform.rotate(angle: -0.79, child: test)"
);

node.rotation = 45;
expect(flutterRotation(node, "test")).toEqual(
"Transform.rotate(angle: -0.79, child: test)"
);

node.rotation = -45;
expect(flutterRotation(node, "test")).toEqual(
"Transform.rotate(angle: 0.79, child: test)"
);

node.rotation = 90;
expect(flutterRotation(node, "test")).toEqual(
"Transform.rotate(angle: -1.57, child: test)"
Expand Down
6 changes: 5 additions & 1 deletion src/flutter/builderImpl/flutterBlend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,11 @@ export const flutterRotation = (
node: AltLayoutMixin,
child: string
): string => {
if (node.rotation !== undefined && node.rotation > 0 && child !== "") {
if (
node.rotation !== undefined &&
child !== "" &&
Math.round(node.rotation) !== 0
) {
return `Transform.rotate(angle: ${numToAutoFixed(
node.rotation * (-3.14159 / 180)
)}, child: ${child})`;
Expand Down

0 comments on commit d4af2f3

Please sign in to comment.