Im having an issue using live previews on xcode. The project builds fine and works on a simulator. I have all my environmentobjects connected so I am a bit confused. And yes I also have the EO on the app file itself.
"Cannot preview in this file - Message send failure for send display message to agent"
struct AlertSettingsView: View {
@EnvironmentObject var avm: AlertsViewModel
private let width: CGFloat = UIScreen.main.bounds.width
private let height: CGFloat = UIScreen.main.bounds.height
var body: some View {
ZStack {
Color.theme.orange.ignoresSafeArea()
VStack {
ForEach(0..<8) { text in
Text("lakjsdfiojas;dfkljadskl;jfj")
}
}
}
.frame(width: width, height: height/2)
.animation(.spring())
.cornerRadius(15)
.offset(y: avm.settingsViewOffset) <-- commenting this line allows preview to work
}
}
struct AlertSettingsView_Previews: PreviewProvider {
@State static var avm = AlertsViewModel()
static var previews: some View {
AlertSettingsView()
.environmentObject(avm)
.preferredColorScheme(.dark)
}
}
class AlertsViewModel: ObservableObject {
@Published var showAlertsView: Bool = true
@Published var showSettingsView: Bool = false
@Published var settingsViewOffset: CGFloat = UIScreen.main.bounds.height/2
}