public static NativeControlType ToControlType(this FigmaInstance figmaInstance) { if (figmaInstance.Component != null) { if (data.TryGetValue(figmaInstance.Component.key, out var nativeControls)) { return(nativeControls); } Console.WriteLine("Component Key not found: {0} - {1}", figmaInstance.Component.key, figmaInstance.Component.name); //throw new KeyNotFoundException(figmaInstance.Component.key); } return(NativeControlType.NotDefined); }
public bool TryGetMainComponent(FigmaInstance nodeInstance, out FigmaInstance result) { //Get the instance var componentNode = GetMainGeneratedLayers(); foreach (var item in componentNode) { if (item is FigmaInstance figmaInstance && figmaInstance.id == nodeInstance.componentId) { result = figmaInstance; return(true); } } result = null; return(false); }
public void BoxTest() { var node = new FigmaInstance() { Component = new FigmaComponent() { name = ControlTypeService.Components.Box }, children = new FigmaNode[] { new FigmaText() } }; var codeNode = new CodeNode(node, "testNode"); var boxConverter = new BoxConverter(); var data = boxConverter.ConvertToCode(codeNode, null, CodeService) .Split(new char[] { '\n' }, StringSplitOptions.RemoveEmptyEntries); AssertEquals(data, nameof(AppKit.NSBox.Title), string.Empty); AssertEquals(data, nameof(AppKit.NSBox.Hidden), true); AssertEquals(data, nameof(AppKit.NSBox.TranslatesAutoresizingMaskIntoConstraints), false); }
public static bool IsInstanceContent(this FigmaNode node, Services.IFigmaFileProvider provider, out FigmaInstance instanceDialog) { if (node.Parent != null && TryGetInstanceDialogParentContainer(node.Parent, provider, out instanceDialog) && node.IsNodeWindowContent()) { return(true); } instanceDialog = null; return(false); }
public static bool TryGetInstanceDialogParentContainer(this FigmaNode figmaNode, Services.IFigmaFileProvider provider, out FigmaInstance instanceDialog) { if (figmaNode is IFigmaNodeContainer container) { foreach (var item in container.children) { if (item is FigmaInstance figmaInstance && provider.TryGetMainComponent(figmaInstance, out instanceDialog)) { return(true); } } } instanceDialog = null; return(false); }