mirror of
https://github.com/ivanvorobei/SwiftUI.git
synced 2026-04-26 02:28:36 +02:00
Add examples project
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
See LICENSE folder for this sample’s licensing information.
|
||||
|
||||
Abstract:
|
||||
A view showing the details for a hike.
|
||||
*/
|
||||
|
||||
import SwiftUI
|
||||
|
||||
struct HikeDetail: View {
|
||||
let hike: Hike
|
||||
@State var dataToShow = \Hike.Observation.elevation
|
||||
|
||||
var buttons = [
|
||||
("Elevation", \Hike.Observation.elevation),
|
||||
("Heart Rate", \Hike.Observation.heartRate),
|
||||
("Pace", \Hike.Observation.pace),
|
||||
]
|
||||
|
||||
var body: some View {
|
||||
return VStack {
|
||||
HikeGraph(hike: hike, path: dataToShow)
|
||||
.frame(height: 200, alignment: .center)
|
||||
|
||||
HStack(spacing: 25) {
|
||||
ForEach(buttons.identified(by: \.0)) { value in
|
||||
Button(action: {
|
||||
self.dataToShow = value.1
|
||||
}) {
|
||||
Text(verbatim: value.0)
|
||||
.font(.system(size: 15))
|
||||
.color(value.1 == self.dataToShow
|
||||
? Color.gray
|
||||
: Color.accentColor)
|
||||
.animation(nil)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#if DEBUG
|
||||
struct HikeDetail_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
HikeDetail(hike: hikeData[0])
|
||||
}
|
||||
}
|
||||
#endif
|
||||
Reference in New Issue
Block a user