MCPcopy Create free account
hub / github.com/bernaferrari/FigmaToCode / swiftuiContainer

Function swiftuiContainer

packages/backend/src/swiftui/swiftuiMain.ts:107–139  ·  view source on GitHub ↗
(
  node: SceneNode,
  stack: string = "",
)

Source from the content-addressed store, hash-verified

105// properties named propSomething always take care of ","
106// sometimes a property might not exist, so it doesn't add ","
107export const swiftuiContainer = (
108 node: SceneNode,
109 stack: string = "",
110): string => {
111 // ignore the view when size is zero or less
112 // while technically it shouldn't get less than 0, due to rounding errors,
113 // it can get to values like: -0.000004196293048153166
114 if (node.width < 0 || node.height < 0) {
115 return stack;
116 }
117
118 let kind = "";
119 if (node.type === "RECTANGLE" || node.type === "LINE") {
120 kind = "Rectangle()";
121 } else if (node.type === "ELLIPSE") {
122 kind = "Ellipse()";
123 } else {
124 kind = stack;
125 }
126
127 const result = new SwiftuiDefaultBuilder(kind)
128 .shapeForeground(node)
129 .autoLayoutPadding(node)
130 .size(node)
131 .shapeBackground(node)
132 .cornerRadius(node)
133 .shapeBorder(node)
134 .commonPositionStyles(node)
135 .effects(node)
136 .build(kind === stack ? -2 : 0);
137
138 return result;
139};
140
141const swiftuiGroup = (
142 node: GroupNode | SectionNode,

Callers 3

swiftuiWidgetGeneratorFunction · 0.85
swiftuiGroupFunction · 0.85
swiftuiFrameFunction · 0.85

Calls 9

effectsMethod · 0.80
shapeBorderMethod · 0.80
cornerRadiusMethod · 0.80
shapeBackgroundMethod · 0.80
shapeForegroundMethod · 0.80
buildMethod · 0.45
commonPositionStylesMethod · 0.45
sizeMethod · 0.45
autoLayoutPaddingMethod · 0.45

Tested by

no test coverage detected