Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using hideDefault can cause errors rendering Code Connect snippets for SwiftUI #217

Open
tylerjdoyle opened this issue Nov 29, 2024 · 0 comments

Comments

@tylerjdoyle
Copy link

  • 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)
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant