code-connect icon indicating copy to clipboard operation
code-connect copied to clipboard

Using hideDefault can cause errors rendering Code Connect snippets for SwiftUI

Open tylerjdoyle opened this issue 1 year ago • 0 comments

  • Code Connect CLI version [use npx figma -V if using React, or figma -V otherwise, 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:

  1. A variant with a "true" and "false" value
  2. 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 image


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)
    }

tylerjdoyle avatar Nov 29 '24 16:11 tylerjdoyle