Skip to content

Commit

Permalink
[Fix] Group, Svg, Alignment
Browse files Browse the repository at this point in the history
  • Loading branch information
thize committed Nov 11, 2020
1 parent ea92cd5 commit 911272d
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 15 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Adobe XD Flutter Code Generate - Plugin
<a href="https://github.com/thize/xd-to-flutter/releases"><img src="https://img.shields.io/badge/Xd%20to%20Flutter-v3.1.0-blue"/></a>
<a href="https://github.com/thize/xd-to-flutter/releases"><img src="https://img.shields.io/badge/Xd%20to%20Flutter-v3.1.1-blue"/></a>

⚠️ **If you encounter an issue or have any feedback which you think could improve Plugin, please open an issue [here](https://github.com/thize/xd-to-flutter/issues)**

Expand Down
33 changes: 31 additions & 2 deletions src/util.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
const scenegraph = require("scenegraph");
const { Path, Line, Group, Polygon, BooleanGroup, Artboard, ImageFill, RepeatGrid, SymbolInstance, Text } = require("scenegraph");
const { Path, Line, Group, Polygon, BooleanGroup, Artboard, RepeatGrid, SymbolInstance, Text } = require("scenegraph");
const { ArtboardWidget } = require("./widgets/artboard");
const { ComponentWidget } = require("./widgets/component");
const { ContainerWidget } = require("./widgets/container");
const { GroupWidget } = require("./widgets/group");
const { GridWidget } = require("./widgets/grid");
const { InkWellWidget } = require("./widgets/inkwell");
const { SvgWidget } = require("./widgets/svg");
const { TextWidget } = require("./widgets/text");
const { MaskWidget } = require("./widgets/mask");
Expand Down Expand Up @@ -158,6 +157,36 @@ function applyRegex(str) {
str = _applySCRegexWithTag(str, getNumberRegex, null, 'Offset');
str = _applySCRegexWithTag(str, getNumberRegex, null, 'elliptical');
str = _applySCRegexWithTag(str, getNumberRegex, null, 'circular');
const element = document.getElementById('numbersMethodName');
let methodName = element != null ? element.value : element;
methodName = methodName ? methodName : '';
if (methodName != "") {
let indexOf = str.indexOf("TextStyle");
while (indexOf != -1) {
let ini = indexOf + 10;
let index = ini;
let qtdParentheses = 1;
let end;
while (end == null) {
if (str[index] == '(') {
qtdParentheses++
} else if (str[index] == ')') {
qtdParentheses--;
}
if (qtdParentheses == 0) {
end = index;
}
index++;
}
let fix = str.substring(ini, end);
console.log('fix height');
fix = fix.replace(new RegExp(`height: ${methodName}\(.*\)`, 'gm'), (value) => {
return value.replace(`${methodName}(`, '').replace(')', '');
});
str = str.substring(0, ini) + fix + str.substring(end)
indexOf = str.indexOf("TextStyle", end);
}
}
return str;
}

Expand Down
4 changes: 3 additions & 1 deletion src/widgets/group.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,16 @@ class GroupWidget {
const { removeItemsFromGroup } = require("../util");
const ungroupedItems = removeItemsFromGroup(this.xdNode.children);
const itemsDart = itemsToDart(ungroupedItems);
return `\n// Group: ${this.xdNode.name}\n${itemsDart}`;
/*
return `
Container(
// Group: ${this.xdNode.name}
alignment: Alignment.center,
width: ${this.xdNode.localBounds.width},
height: ${this.xdNode.localBounds.height},
child: ${itemsDart},
)`;
*/
}
}

Expand Down
21 changes: 10 additions & 11 deletions src/widgets/svg.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,7 @@ class SvgWidget {
const node = this.xdNode;
const path = new Path(node);
path.shapes = this.shapes;
let height = node.height;
height = height != null ? height : node.localBounds.height;
height = height == 0 ? 1 : height;
let width = node.width;
width = width != null ? width : node.localBounds.width;
width = width == 0 ? 1 : width;
return `SizedBox(
width: ${width},
height: ${height},
child: ${path.toString()},
)`;
return path.toString();
}


Expand Down Expand Up @@ -71,9 +61,18 @@ class Path {
toString() {
let svg;
svg = `'${this.toSvgString()}'`;
const node = this.xdNode;
let height = node.height;
height = height != null ? height : node.localBounds.height;
height = height == 0 ? 1 : height;
let width = node.width;
width = width != null ? width : node.localBounds.width;
width = width == 0 ? 1 : width;
return `SvgPicture.string(
// ${this.xdNode.name}
${svg},
width: ${width},
height: ${height},
)`;
}

Expand Down
3 changes: 3 additions & 0 deletions src/widgets/util/xd_alignment_to_dart_alignment.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ function xdAlignmentToDartAlignment(x, y) {
const dx = fix(fixAlignment(x));
const dy = fix(fixAlignment(y));
const align = `Alignment(${dx},${dy})`;
const dif = Math.abs(dx - dy);
if(dif < 0.02) return 'Alignment.center';
console.log(`dif = ${dif}`);
return nameAlignment[align] ? nameAlignment[align] : align;
}

Expand Down

0 comments on commit 911272d

Please sign in to comment.