Skip to content

Xcode preview support for custom views #63

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

Closed
merbula opened this issue Apr 18, 2024 · 4 comments
Closed

Xcode preview support for custom views #63

merbula opened this issue Apr 18, 2024 · 4 comments
Assignees
Labels
feature-request New feature or request

Comments

@merbula
Copy link

merbula commented Apr 18, 2024

Is there a way to get Xcode preview working when using custom views? For example custom login preview gives error: "'SignInState' initializer is inaccessible due to 'internal' protection level"

struct MyCustomLoginView: View {
@StateObject var state: SignInState

var body: some View {
    VStack {
    ...
    ...
    }
}

}

#Preview {
let state = SignInState(...)
return MyCustomLoginView(state: state)
}

@5d 5d added the question Further information is requested label Apr 18, 2024
@5d
Copy link

5d commented Apr 18, 2024

Hi @merbula, thank you for raising this issue. Our team will discuss and evaluate whether this should be considered an expected functionality or if it requires implementation as a new feature.

@sebaland
Copy link
Contributor

Using Xcode previews with custom views is currently not supported, as the states are not meant to be initialized outside the component.

In the meantime, you can workaround this restriction for custom Sign In, Sign Up and Reset Password views by using the Authenticator and setting the initialStep to one of those. For example:

#Preview {
    Authenticator(
        initialStep: .signIn,
        signInContent: { state in
            MyCustomLoginView(state: state)
        }
    ) { state in
        Text("Test")
    }
}

@sebaland sebaland added feature-request New feature or request and removed question Further information is requested labels Apr 22, 2024
@sebaland sebaland self-assigned this Apr 22, 2024
@sebaland
Copy link
Contributor

This has been addressed in version 1.1.2 with the introduction of a PreviewFactory utility that provides empty and no-opt states that you can use in previews.

For example:

import Authenticator

struct CustomSignInView: View {
    @ObservedObject var state: SignInState

    var body: some View { /*...*/ }
}

#Preview {
    CustomSignInView(
        state: PreviewFactory.States.signIn()
    )
}

Copy link

This issue is now closed. Comments on closed issues are hard for our team to see.
If you need more assistance, please open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants