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

SwiftUI Previews #70

Open
j-cheung opened this issue May 27, 2022 · 2 comments
Open

SwiftUI Previews #70

j-cheung opened this issue May 27, 2022 · 2 comments

Comments

@j-cheung
Copy link

Hi,

I've been searching through all the examples and haven't been able to find one which shows how we can use SwiftUI Previews with this? Or is it not possible?

Any help is appreciated, thanks!

Thanks.

@rundfunk47
Copy link
Owner

Hi! What exactly do you wish to accomplish with SwiftUI previews? Do you wish to be able to navigate through a preview just as you should with an app?

There shouldn't be any issues using previews...

@j-cheung
Copy link
Author

Hi!

Not much, i just want to be able to use preview as normal, not really needing to navigate.

It's telling me the following:

No ObservableObject of type NavigationRouter<AuthenticatedCoordinator> found. A View.environmentObject(_:) for NavigationRouter<AuthenticatedCoordinator> may be missing as an ancestor of this view.

----------------------------------------

CrashReportError: `fatalError` in EnvironmentObject.swift

(my app) crashed due to fatalError in EnvironmentObject.swift at line 70.

No ObservableObject of type NavigationRouter<AuthenticatedCoordinator> found. A View.environmentObject(_:) for NavigationRouter<AuthenticatedCoordinator> may be missing as an ancestor of this view.

because I don't know what i should pass in .environmentObject() for the preview.

this is the example which failed, i suspect it is because of the variable index which is trying to access authenticatedRouter.coordinator.tabIndex

import SwiftUI

struct ProcessingScreen: View {
    @EnvironmentObject var authenticatedRouter: AuthenticatedCoordinator.Router
    var index: Int {
        authenticatedRouter.coordinator.tabIndex
    }
    var body: some View {
        VStack {
            NavigationHeader(
                title:"處理中",
                subtitle: "\(index)",
                foregroundColor : .white,
                backgroundColor: .blue)
        }
    }
}

struct ProcessingScreen_Previews: PreviewProvider {
    static var previews: some View {
        ProcessingScreen()
.previewInterfaceOrientation(.landscapeLeft)
    }
}

and this works

import SwiftUI

struct ProcessingScreen: View {
    @EnvironmentObject var authenticatedRouter: AuthenticatedCoordinator.Router
//    @EnvironmentObject var store: AutomateProStore
    var body: some View {
        VStack {
            NavigationHeader(
                title:"處理中",
                subtitle: "hihi",
//                subtitle: "\(store.state.orderState.arrivingOrderIds.count)",
                foregroundColor : .white,
                backgroundColor: .blue)
//            HorizontalOrderList(orders:store.state.orderState.arrivingOrders)
        }
    }
}

struct ProcessingScreen_Previews: PreviewProvider {
    static var previews: some View {
        ProcessingScreen()
.previewInterfaceOrientation(.landscapeLeft)
    }
}

thanks!

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

No branches or pull requests

2 participants