code-connect
code-connect copied to clipboard
Using hideDefault can cause errors rendering Code Connect snippets for SwiftUI
-
Code Connect CLI version [use
npx figma -Vif using React, orfigma -Votherwise, to get the version of your CLI]1.2.2 -
Operating system
Sonoma 14.7.1 -
Code Connect file, Figma design and/or relevant code snippet that could help us get more context
I set up a basic component on Figma with 2 props:
- A variant with a "true" and "false" value
- A variant with "First", "Second", and "Third" values
And here is my code connect file:
import Figma
import SwiftUI
enum ComponentValue {
case first
case second
case third
}
struct Component_doc: FigmaConnect {
let component = Text.self
let figmaNodeUrl = "<component_url>"
@FigmaEnum("test?", mapping: ["false": false, "true": true])
var test: Bool
@FigmaEnum("Value", mapping: ["First": .first, "Second": .second, "Third": .third], hideDefault: true)
var value: ComponentValue = .first
var body: some View {
Text("Hello, world!")
.applyValue(self.value)
.disabled(self.test)
}
}
extension Text {
func applyValue(_ value: ComponentValue) -> Text {
// do some configuration
return self
}
}
If using the hideDefault on the test var or both, there are no issues. However, using hideDefault on only the value var causes a Code Connect rendering error
I also noticed that if using multiple views or even a variable and a view in the view body as below, the same error occurs no matter the value of test's hideDefault when value has hideDefault: true
var body: some View {
VStack {
Text(self.test)
Text("Hello, world!")
.applyValue(self.value)
}
}
OR
var body: some View {
let val = self.test
Text("Hello, world!")
.applyValue(self.value)
}