Skip to content

Instantly share code, notes, and snippets.

@heath-hwang
Created June 26, 2020 11:01
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save heath-hwang/d268ec5dba9c1b77d1a0efcf9708743e to your computer and use it in GitHub Desktop.
Save heath-hwang/d268ec5dba9c1b77d1a0efcf9708743e to your computer and use it in GitHub Desktop.
swiftui test 1
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