mirror of
https://github.com/ivanvorobei/SwiftUI.git
synced 2026-05-13 11:20:22 +02:00
51 lines
1.3 KiB
Swift
Executable File
51 lines
1.3 KiB
Swift
Executable File
/*
|
||
See LICENSE folder for this sample’s licensing information.
|
||
|
||
Abstract:
|
||
A view that hosts the profile viewer and editor.
|
||
*/
|
||
|
||
import SwiftUI
|
||
|
||
struct ProfileHost: View {
|
||
@Environment(\.editMode) var mode
|
||
@State var profile = Profile.default
|
||
@State var draftProfile = Profile.default
|
||
|
||
var body: some View {
|
||
VStack(alignment: .leading, spacing: 20) {
|
||
HStack {
|
||
if self.mode?.wrappedValue == .active {
|
||
Button(action: {
|
||
self.draftProfile = self.profile
|
||
self.mode?.animation().wrappedValue = .inactive
|
||
}) {
|
||
Text("Done")
|
||
}
|
||
}
|
||
|
||
Spacer()
|
||
|
||
EditButton()
|
||
}
|
||
if self.mode?.wrappedValue == .inactive {
|
||
ProfileSummary(profile: profile)
|
||
} else {
|
||
ProfileEditor(profile: $draftProfile)
|
||
.onDisappear {
|
||
self.profile = self.draftProfile
|
||
}
|
||
}
|
||
}
|
||
.padding()
|
||
}
|
||
}
|
||
|
||
#if DEBUG
|
||
struct ProfileHost_Previews: PreviewProvider {
|
||
static var previews: some View {
|
||
ProfileHost()
|
||
}
|
||
}
|
||
#endif
|