Skip to content

Commit

Permalink
Scrumdinger现在在两次发射之间保留数据。在下一章中,您将为会议计时器视图构建进度环,以向应用程序添加一些修饰。
Browse files Browse the repository at this point in the history
  • Loading branch information
mona-lisa-octo-ue5 committed Jan 6, 2021
1 parent dffd8a0 commit c985339
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 5 deletions.
Binary file not shown.
1 change: 0 additions & 1 deletion SwiftUIPro/SwiftUIPro/EditView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ struct EditView: View {
}
ColorPicker("Color",selection:$scrumData.color)
}

Section(header: Text("Attendees")) {
ForEach(scrumData.attendees,id:\.self){ attendee in
Text(attendee)
Expand Down
8 changes: 6 additions & 2 deletions SwiftUIPro/SwiftUIPro/ScrumsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ import SwiftUI

struct ScrumsView: View {
@Binding var scrums:[DailyScrum]
@Environment(\.scenePhase) private var scenePhase
@State private var isPresented=false
@State private var newScrumData=DailyScrum.Data()
let saveAction:()->Void
var body: some View {
List{
ForEach(scrums){ scrum in
Expand Down Expand Up @@ -38,8 +40,10 @@ struct ScrumsView: View {
})
}
}
.onChange(of: scenePhase) { phase in
if phase == .inactive { saveAction() }
}
}

private func binding(for scrum:DailyScrum)->Binding<DailyScrum>{
guard let scrumIndex = scrums.firstIndex(where: { $0.id==scrum.id}) else { fatalError("Can't find scrum in array") }
return $scrums[scrumIndex]
Expand All @@ -49,7 +53,7 @@ struct ScrumsView: View {
struct ScrumsView_Previews: PreviewProvider {
static var previews: some View {
NavigationView{
ScrumsView(scrums: .constant(DailyScrum.data))
ScrumsView(scrums: .constant(DailyScrum.data), saveAction: {})
}
}
}
9 changes: 7 additions & 2 deletions SwiftUIPro/SwiftUIPro/SwiftUIProApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,16 @@ import SwiftUI

@main
struct SwiftUIProApp: App {
@State private var scrums = DailyScrum.data
@ObservedObject private var data=ScrumData()
var body: some Scene {
WindowGroup {
NavigationView{
ScrumsView(scrums: $scrums)
ScrumsView(scrums: $data.scrums){
data.save()
}
}
.onAppear{
data.load()
}
}
}
Expand Down

0 comments on commit c985339

Please sign in to comment.