Files
SwiftUI/Examples/InterfacingWithUIKit/StartingPoint/Landmarks/Landmarks/HikeView.swift
2019-06-06 11:16:28 +03:00

69 lines
1.8 KiB
Swift
Executable File
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/*
See LICENSE folder for this samples licensing information.
Abstract:
A view displaying inforamtion about a hike, including an elevation graph.
*/
import SwiftUI
struct HikeView: View {
var hike: Hike
@State private var showDetail = false
var transition: AnyTransition {
let insertion = AnyTransition.move(edge: .trailing)
.combined(with: .opacity)
let removal = AnyTransition.scale()
.combined(with: .opacity)
return .asymmetric(insertion: insertion, removal: removal)
}
var body: some View {
VStack {
HStack {
HikeGraph(hike: hike, path: \.elevation)
.frame(width: 50, height: 30)
.animation(nil)
VStack(alignment: .leading) {
Text(verbatim: hike.name)
.font(.headline)
Text(verbatim: hike.distanceText)
}
Spacer()
Button(action: {
withAnimation {
self.showDetail.toggle()
}
}) {
Image(systemName: "chevron.right.circle")
.imageScale(.large)
.rotationEffect(.degrees(showDetail ? 90 : 0))
.scaleEffect(showDetail ? 1.5 : 1)
.padding()
}
}
if showDetail {
HikeDetail(hike: hike)
.transition(transition)
}
}
}
}
#if DEBUG
struct HikeView_Previews: PreviewProvider {
static var previews: some View {
VStack {
HikeView(hike: hikeData[0])
.padding()
Spacer()
}
}
}
#endif