mirror of
https://github.com/ivanvorobei/SwiftUI.git
synced 2026-05-05 07:24:05 +02:00
Update
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
See LICENSE folder for this sample’s licensing information.
|
||||
|
||||
Abstract:
|
||||
An editable profile view.
|
||||
*/
|
||||
|
||||
import SwiftUI
|
||||
|
||||
struct ProfileEditor: View {
|
||||
@Binding var profile: Profile
|
||||
|
||||
var body: some View {
|
||||
List {
|
||||
HStack {
|
||||
Text("Username").bold()
|
||||
Divider()
|
||||
TextField($profile.username)
|
||||
}
|
||||
|
||||
Toggle(isOn: $profile.prefersNotifications) {
|
||||
Text("Enable Notifications")
|
||||
}
|
||||
|
||||
VStack(alignment: .leading, spacing: 20) {
|
||||
Text("Seasonal Photo").bold()
|
||||
|
||||
SegmentedControl(selection: $profile.seasonalPhoto) {
|
||||
ForEach(Profile.Season.allCases.identified(by: \.self)) { season in
|
||||
Text(season.rawValue).tag(season)
|
||||
}
|
||||
}
|
||||
}
|
||||
.padding(.top)
|
||||
|
||||
VStack(alignment: .leading, spacing: 20) {
|
||||
Text("Goal Date").bold()
|
||||
DatePicker(
|
||||
$profile.goalDate,
|
||||
minimumDate: Calendar.current.date(byAdding: .year, value: -1, to: profile.goalDate),
|
||||
maximumDate: Calendar.current.date(byAdding: .year, value: 1, to: profile.goalDate),
|
||||
displayedComponents: .date
|
||||
)
|
||||
}
|
||||
.padding(.top)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#if DEBUG
|
||||
struct ProfileEditor_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
ProfileEditor(profile: .constant(.default))
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
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?.value == .active {
|
||||
Button(action: {
|
||||
self.profile = self.draftProfile
|
||||
self.mode?.animation().value = .inactive
|
||||
}) {
|
||||
Text("Done")
|
||||
}
|
||||
}
|
||||
|
||||
Spacer()
|
||||
|
||||
EditButton()
|
||||
}
|
||||
if self.mode?.value == .inactive {
|
||||
ProfileSummary(profile: profile)
|
||||
} else {
|
||||
ProfileEditor(profile: $draftProfile)
|
||||
.onDisappear {
|
||||
self.draftProfile = self.profile
|
||||
}
|
||||
}
|
||||
}
|
||||
.padding()
|
||||
}
|
||||
}
|
||||
|
||||
#if DEBUG
|
||||
struct ProfileHost_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
ProfileHost()
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
See LICENSE folder for this sample’s licensing information.
|
||||
|
||||
Abstract:
|
||||
A view that summarizes a profile.
|
||||
*/
|
||||
|
||||
import SwiftUI
|
||||
|
||||
struct ProfileSummary: View {
|
||||
var profile: Profile
|
||||
|
||||
static var goalFormat: DateFormatter {
|
||||
let formatter = DateFormatter()
|
||||
formatter.dateFormat = "MMMM d, yyyy"
|
||||
return formatter
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
List {
|
||||
Text(profile.username)
|
||||
.bold()
|
||||
.font(.title)
|
||||
|
||||
Text("Notifications: \(self.profile.prefersNotifications ? "On": "Off" )")
|
||||
|
||||
Text("Seasonal Photos: \(self.profile.seasonalPhoto.rawValue)")
|
||||
|
||||
Text("Goal Date: \(self.profile.goalDate, formatter: Self.goalFormat)")
|
||||
|
||||
VStack(alignment: .leading) {
|
||||
Text("Completed Badges")
|
||||
.font(.headline)
|
||||
ScrollView {
|
||||
HStack {
|
||||
HikeBadge(name: "First Hike")
|
||||
|
||||
HikeBadge(name: "Earth Day")
|
||||
.hueRotation(Angle(degrees: 90))
|
||||
|
||||
HikeBadge(name: "Tenth Hike")
|
||||
.grayscale(0.5)
|
||||
.hueRotation(Angle(degrees: 45))
|
||||
}
|
||||
}
|
||||
.frame(height: 140)
|
||||
}
|
||||
|
||||
VStack(alignment: .leading) {
|
||||
Text("Recent Hikes")
|
||||
.font(.headline)
|
||||
|
||||
HikeView(hike: hikeData[0])
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#if DEBUG
|
||||
struct ProfileSummary_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
ProfileSummary(profile: Profile.default)
|
||||
}
|
||||
}
|
||||
#endif
|
||||
Reference in New Issue
Block a user