Skip to content

Commit

Permalink
[Fix] Text Widget
Browse files Browse the repository at this point in the history
  • Loading branch information
thize committed Dec 15, 2020
1 parent 1437392 commit 95c7d9c
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 25 deletions.
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,5 @@
}
}
],
"version": "3.3.0"
"version": "3.3.1"
}
50 changes: 28 additions & 22 deletions src/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,30 +162,36 @@ function applyRegex(str) {
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++;
str = _applyTextStyle(str, methodName, 'TextStyle');
str = _applyTextStyle(str, methodName, 'GoogleFonts');
}
return str;
}

function _applyTextStyle(str, methodName, tag) {
let indexOf = str.indexOf(tag);
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--;
}
let fix = str.substring(ini, end);
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);
if (qtdParentheses == 0) {
end = index;
}
index++;
}
let fix = str.substring(ini, end);
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(tag, end);
}
return str;
}
Expand Down
13 changes: 11 additions & 2 deletions src/widgets/text.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,20 @@ class TextWidget {
if (o.areaBox) {
let w = o.localBounds.width;
let h = o.localBounds.height;
str = `${str}.w(${w}).h(${h})`
let withStyledWidget = document.querySelector('input[name="simpleType"]');
withStyledWidget = withStyledWidget != null ? withStyledWidget.checked : null;
if (withStyledWidget) {
str = `${str}.w(${w}).h(${h})`
} else {
str = `SizedBox(
width: ${w},
height: ${h},
child: ${str},
)`
}
}
return str;
}

}

exports.TextWidget = TextWidget;
Expand Down

0 comments on commit 95c7d9c

Please sign in to comment.