-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLearnMoreView.swift
116 lines (97 loc) · 3.38 KB
/
LearnMoreView.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/*
See the LICENSE.txt file for this sample’s licensing information.
Abstract:
A view, used as an attachment, that gives information about a point of interest.
*/
import SwiftUI
import RealityKit
import RealityKitContent
public struct : View {
let name: String
let description: String
let imageNames: [String]
let trail: Entity?
let viewModel: ViewModel
@State private var showingMoreInfo = false
@Namespace private var animation
private var imagesFrame: Double {
showingMoreInfo ? 326 : 50
}
private var titleFont: Font {
.system(size: 48, weight: .semibold)
}
private var descriptionFont: Font {
.system(size: 36, weight: .regular)
}
public var body: some View {
VStack {
Spacer()
ZStack(alignment: .center) {
if !showingMoreInfo {
Text(name)
.matchedGeometryEffect(id: "Name", in: animation)
.font(titleFont)
.padding()
}
if showingMoreInfo {
VStack(alignment: .leading, spacing: 10) {
Text(name)
.matchedGeometryEffect(id: "Name", in: animation)
.font(titleFont)
Text(description)
.font(descriptionFont)
if !imageNames.isEmpty {
Spacer()
.frame(height: 10)
ImagesView(imageNames: imageNames)
}
}
}
}
.frame(width: 408)
.padding(24)
.greenBackground()
.onTapGesture {
withAnimation(.spring) {
showingMoreInfo.toggle()
if var trailOpacity = trail?.components[ControlledOpacityComponent.self] {
trailOpacity.shouldShow = showingMoreInfo
trail?.components.set(trailOpacity)
}
viewModel.updateRegionSpecificOpacity()
}
}
}
}
}
struct ImagesView: View {
let imageNames: [String]
var body: some View {
ScrollView(.horizontal) {
HStack {
ForEach(imageNames, id: \.self) { imageName in
Image(imageName)
.resizable()
.aspectRatio(contentMode: .fill)
.frame(width: 200, height: 250, alignment: .center)
.clipShape(RoundedRectangle(cornerRadius: 10, style: .continuous))
}
}
}
}
}
#Preview {
RealityView { content, attachments in
if let entity = attachments.entity(for: "z") {
content.add(entity)
}
} attachments: {
Attachment(id: "z") {
LearnMoreView(name: "Phoenix Lake",
description: "Lake · Northern California",
imageNames: ["Landscape_2_Sunset"],
trail: nil,
viewModel: ViewModel())
}
}
}