Skip to content
This repository has been archived by the owner on Jan 25, 2024. It is now read-only.

Commit

Permalink
Merge pull request #363 from Parabeac/hotfix/figmaHeadTooLarge
Browse files Browse the repository at this point in the history
Hotfix/figma head too large
  • Loading branch information
mergify[bot] committed Apr 9, 2021
2 parents d1b2a26 + 3d960d4 commit 0a9a5e8
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 40 deletions.
2 changes: 1 addition & 1 deletion lib/generation/generators/symbols/pb_instancesym_gen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class PBSymbolInstanceGenerator extends PBGenerator {
String generate(
PBIntermediateNode source, GeneratorContext generatorContext) {
if (source is PBSharedInstanceIntermediateNode) {
var method_signature = source.functionCallName.pascalCase;
var method_signature = source.functionCallName?.pascalCase;
if (method_signature == null) {
log.error(' Could not find master name on: $source');
return 'Container(/** This Symbol was not found **/)';
Expand Down
3 changes: 3 additions & 0 deletions lib/generation/prototyping/pb_prototype_linker_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ class PBPrototypeLinkerService {

while (stack.isNotEmpty) {
var currentNode = stack.removeLast();
if (currentNode == null) {
continue;
}
currentNode.attributes.forEach((attribute) {
attribute.attributeNodes.forEach(stack.add);
});
Expand Down
4 changes: 3 additions & 1 deletion lib/input/figma/entities/layers/group.dart
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,9 @@ class Group extends FigmaFrame implements AbstractFigmaNodeFactory, Image {
this.prototypeNodeUUID = tempPrototypeID;
}

boundaryRectangle = fitFrame();
if (children != null && children.isNotEmpty) {
boundaryRectangle = fitFrame();
}

children.clear();

Expand Down
91 changes: 58 additions & 33 deletions lib/input/figma/helper/figma_asset_processor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -63,41 +63,46 @@ class FigmaAssetProcessor extends AssetProcessingService {
{bool writeAsFile = true}) async {
// Call Figma API to get Image link
return Future(() async {
var response = await APICallService.makeAPICall(
'https://api.figma.com/v1/images/${MainInfo().figmaProjectID}?ids=${uuids.join(',')}&use_absolute_bounds=true',
MainInfo().figmaKey);

if (response != null &&
response.containsKey('images') &&
response['images'] != null &&
response['images'].values.isNotEmpty) {
Map images = response['images'];
// Download the images
for (var entry in images.entries) {
if (entry?.value != null && entry?.value?.isNotEmpty) {
response = await http.get(entry.value).then((imageRes) async {
// Check if the request was successful
if (imageRes == null || imageRes.statusCode != 200) {
log.error('Image ${entry.key} was not processed correctly');
}

if (writeAsFile) {
var file = File('${MainInfo().outputPath}pngs/${entry.key}.png'
.replaceAll(':', '_'))
..createSync(recursive: true);
file.writeAsBytesSync(imageRes.bodyBytes);
} else {
await super.uploadToStorage(imageRes.bodyBytes, entry.key);
}
// TODO: Only print out when verbose flag is active
// log.debug('File written to following path ${file.path}');
}).catchError((e) {
MainInfo().sentry.captureException(exception: e);
log.error(e.toString());
});
List<List<String>> uuidsChunks = _listToChunks(uuids, 50);

for (var list in uuidsChunks) {
var response = await APICallService.makeAPICall(
'https://api.figma.com/v1/images/${MainInfo().figmaProjectID}?ids=${list.join(',')}&use_absolute_bounds=true',
MainInfo().figmaKey);

if (response != null &&
response.containsKey('images') &&
response['images'] != null &&
response['images'].values.isNotEmpty) {
Map images = response['images'];
// Download the images
for (var entry in images.entries) {
if (entry?.value != null && entry?.value?.isNotEmpty) {
response = await http.get(entry.value).then((imageRes) async {
// Check if the request was successful
if (imageRes == null || imageRes.statusCode != 200) {
log.error('Image ${entry.key} was not processed correctly');
}

if (writeAsFile) {
var file = File(
'${MainInfo().outputPath}pngs/${entry.key}.png'
.replaceAll(':', '_'))
..createSync(recursive: true);
file.writeAsBytesSync(imageRes.bodyBytes);
} else {
await super.uploadToStorage(imageRes.bodyBytes, entry.key);
}
// TODO: Only print out when verbose flag is active
// log.debug('File written to following path ${file.path}');
}).catchError((e) {
MainInfo().sentry.captureException(exception: e);
log.error(e.toString());
});
}
}
return response;
}
return response;
}
});
}
Expand All @@ -107,4 +112,24 @@ class FigmaAssetProcessor extends AssetProcessingService {
_addImagesToQueue(uuids.keys.toList());
await processImageQueue(writeAsFile: false);
}

List _listToChunks(List currentList, int chuckSize) {
var temp = <String>[];
var counter = 0;
// ignore: omit_local_variable_types
List<List<String>> listOnChunks =
currentList.fold<List<List<String>>>([], (newList, i) {
counter++;
if (temp.length < chuckSize) {
temp.add(i);
}
if (temp.length >= chuckSize || currentList.length == counter) {
var newValue = List<String>.from(temp);
newList.add(newValue);
temp.clear();
}
return newList;
});
return listOnChunks;
}
}
12 changes: 7 additions & 5 deletions lib/interpret_and_optimize/entities/inherited_scaffold.dart
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,12 @@ class InheritedScaffold extends PBVisualIntermediateNode

@override
void alignChild() {
var align =
InjectedAlign(topLeftCorner, bottomRightCorner, currentContext, '');
align.addChild(child);
align.alignChild();
child = align;
if (child != null) {
var align =
InjectedAlign(topLeftCorner, bottomRightCorner, currentContext, '');
align.addChild(child);
align.alignChild();
child = align;
}
}
}
7 changes: 7 additions & 0 deletions lib/interpret_and_optimize/entities/inherited_text.dart
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ class InheritedText extends PBVisualIntermediateNode
generator = PBTextGen();

text = (originalRef as Text).content;
if (text.contains('\$')) {
text = _sanitizeText(text);
}
fontSize = originalRef.style.textStyle.fontDescriptor.fontSize;
auxiliaryData.color = toHex(originalRef.style.textStyle.fontColor);
fontName = originalRef.style.textStyle.fontDescriptor.fontName;
Expand All @@ -68,6 +71,10 @@ class InheritedText extends PBVisualIntermediateNode
}
}

String _sanitizeText(String text) {
return text.replaceAll('\$', '\\\$');
}

@override
void addChild(PBIntermediateNode node) {
assert(true, 'Adding a child to InheritedText should not be possible.');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ class PBAlignGenerationService implements PBGenerationService {
} else if (currentIntermediateNode is PBLayoutIntermediateNode) {
currentIntermediateNode.alignChildren();
}
if (currentIntermediateNode == null) {
continue;
}

currentIntermediateNode.attributes.forEach((attribute) {
attribute.attributeNodes.forEach((node) {
Expand Down

0 comments on commit 0a9a5e8

Please sign in to comment.