I have a simple Button that opens a Modal when it's clicked. I know the modal can be closed by swiping it down, but I implemented a button to close it and this works.
The only thing that bothers me is that I can't preview my Modal (take a look at my code below)
// Button that opens the modal
struct ContentView: View {
@State private var willMoveToNextScreen = false
Button(action: {
self.willMoveToNextScreen = true
}, label: {
Image(systemName: "gear")
.font(.system(size: 30))
.padding(.leading, 15)
})
.sheet(isPresented: $willMoveToNextScreen, content: {
SettingsView(willMoveToNextScreen: $willMoveToNextScreen)
})
}
// Modal
struct SettingsView: View {
@Binding var willMoveToNextScreen: Bool
var body: some View {
VStack{
HStack {
Button(action: {
self.willMoveToNextScreen = false
}, label: {
Image(systemName: "xmark")
.font(.system(size: 30, weight: .semibold))
})
}
.frame(maxWidth: .infinity, alignment: .trailing)
.padding(15)
Spacer()
Text("Aye")
}
}
}
struct SettingsView_Previews: PreviewProvider {
static var previews: some View {
// I don't know which value I should provide, it expects a Binding<Bool> value
SettingsView(willMoveToNextScreen: ??)
}
}
willMoveToNextScreen
expects a BindingBoolean. How could I fix this?