Files
SwiftUI/Other Projects/Interfacing With UIKit/Complete/Landmarks/Landmarks/Profiles/ProfileHost.swift
John Holdsworth 7de7e1e47b Xcode 11 beta 6
2019-08-20 18:54:37 +02:00

51 lines
1.3 KiB
Swift
Executable File
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/*
See LICENSE folder for this samples 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