Use presentationMode environment property to dismiss sheet

This commit is contained in:
Angelo Stavrow 2020-09-11 13:53:11 -04:00
parent a31e0e2d4b
commit 428fb6cd6f
No known key found for this signature in database
GPG Key ID: 1A49C7064E060EEE
2 changed files with 5 additions and 7 deletions

View File

@ -1,7 +1,7 @@
import SwiftUI
struct SettingsHeaderView: View {
@Binding var isPresented: Bool
@Environment(\.presentationMode) var presentationMode
var body: some View {
HStack {
@ -10,7 +10,7 @@ struct SettingsHeaderView: View {
.fontWeight(.bold)
Spacer()
Button(action: {
isPresented = false
presentationMode.wrappedValue.dismiss()
}, label: {
Image(systemName: "xmark.circle")
})
@ -21,6 +21,6 @@ struct SettingsHeaderView: View {
struct SettingsHeaderView_Previews: PreviewProvider {
static var previews: some View {
SettingsHeaderView(isPresented: .constant(true))
SettingsHeaderView()
}
}

View File

@ -3,11 +3,9 @@ import SwiftUI
struct SettingsView: View {
@EnvironmentObject var model: WriteFreelyModel
@Binding var isPresented: Bool
var body: some View {
VStack {
SettingsHeaderView(isPresented: $isPresented)
SettingsHeaderView()
Form {
Section(header: Text("Login Details")) {
AccountView()
@ -23,7 +21,7 @@ struct SettingsView: View {
struct SettingsView_Previews: PreviewProvider {
static var previews: some View {
SettingsView(isPresented: .constant(true))
SettingsView()
.environmentObject(WriteFreelyModel())
}
}