Created
June 26, 2020 11:01
-
-
Save heath-hwang/d268ec5dba9c1b77d1a0efcf9708743e to your computer and use it in GitHub Desktop.
swiftui test 1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct EventDetailView: View { | |
let id: Int | |
@State private var isEditing: Bool = false | |
var body: some View { | |
ZStack { | |
HStack { | |
VStack { | |
List { | |
Text("Hello detail \(id)") | |
} | |
.navigationBarTitle("detail") | |
.navigationBarItems(trailing: navigationBarButton()) | |
} | |
} | |
} | |
} | |
private func navigationBarButton() -> some View { | |
return self.isEditing ? | |
AnyView(Button("Cancel") { | |
self.isEditing = false | |
}) | |
: | |
AnyView(Button("Edit") { | |
self.isEditing.toggle() | |
}) | |
} | |
} | |
struct Event: Identifiable { | |
var id: Int | |
} | |
struct ContentView: View { | |
@State private var isPlaying = false | |
@State private var showingAddEventView = false | |
private let theDay = "hello" | |
let events: [Event] = [ | |
.init(id: 1), | |
.init(id: 2) | |
] | |
var body: some View { | |
NavigationView { | |
ZStack { | |
List { | |
ForEach(self.events) { event in | |
NavigationLink(destination: | |
EventDetailView(id: event.id) | |
) { | |
Text("row") | |
} | |
} | |
} | |
.navigationBarTitle(self.theDay) | |
.navigationBarItems(trailing: | |
Button (action: { | |
self.showingAddEventView.toggle() | |
}) { | |
Image(systemName: "square.and.pencil") | |
} | |
) | |
} | |
} | |
} | |
} | |
struct ContentView_Previews: PreviewProvider { | |
static var previews: some View { | |
ContentView() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment