Browse Source

les prémices d'une navbar

main
art.dambrine 4 years ago
parent
commit
6ab7d61067
  1. 37
      NavigationExemple/ContentView.swift

37
NavigationExemple/ContentView.swift

@ -7,42 +7,31 @@
import SwiftUI import SwiftUI
class User: ObservableObject {
@Published var score = 0
}
struct ChangeView: View {
@EnvironmentObject var user: User
var body: some View {
VStack{
Text("Score : \(user.score)")
Button("Increase"){
self.user.score += 1
}
}
}
}
struct ContentView: View { struct ContentView: View {
@ObservedObject var user = User() @State private var score = 0
var body: some View { var body: some View {
NavigationView{ NavigationView{
VStack(alignment: /*@START_MENU_TOKEN@*/.center/*@END_MENU_TOKEN@*/, spacing: 20){ Text("Score: \(score)")
Text("Score: \(user.score)") .navigationTitle("Menu principal")
.navigationBarItems(
NavigationLink(destination: ChangeView()){ trailing:
Text("Show detail view") HStack{
Button("Add"){
self.score += 1
} }
Button("Sub"){
self.score -= 1
}
}
}.navigationTitle("Menu principal") )
} }
// Important à ajouter
.environmentObject(user)
} }
} }

Loading…
Cancel
Save