Browse Source

les prémices d'une navbar

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

45
NavigationExemple/ContentView.swift

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

Loading…
Cancel
Save