-
Notifications
You must be signed in to change notification settings - Fork 0
/
TestResultView.swift
140 lines (118 loc) · 4.61 KB
/
TestResultView.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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
//
// TestResultView.swift
// Features
//
// Created by 고도현 on 2023/08/18.
// Copyright © 2023 team.humanwave. All rights reserved.
//
import SwiftUI
import ComposableArchitecture
import Core
import DSKit
import Domain
import Network
public struct TestResultView: View {
@State var sharedURL: ActivityViewController.SharedURL?
@Dependency(\.shortUrlAPIManager) private var shortURLManager
private let store: StoreOf<TestResultFeature>
public init(store: StoreOf<TestResultFeature>) {
self.store = store
}
public var body: some View {
WithViewStore(store, observe: { $0 }) { viewStore in
VStack {
closeButton(viewStore)
Spacer()
resultTitle(viewStore)
Spacer()
resultCardView(viewStore)
Spacer()
indexDisplay(viewStore)
Spacer()
Spacer()
bottomButton(viewStore)
}
.background(DSKitAsset.Color.keymeBlack.swiftUIColor)
.padding(Padding.insets(top: 58, bottom: 54))
.onAppear {
viewStore.send(.viewWillAppear)
}
}
}
// 상단 X 버튼
func closeButton(_ viewStore: ViewStore<TestResultFeature.State, TestResultFeature.Action>) -> some View {
DSKitAsset.Image.close.swiftUIImage
.resizable()
.aspectRatio(contentMode: .fit)
.frame(width: 24, height: 24)
.frame(maxWidth: .infinity, alignment: .trailing)
.padding(Padding.insets(trailing: 17))
.onTapGesture {
viewStore.send(.closeButtonDidTap(testId: viewStore.testId))
}
}
// 결과 확인 텍스트
func resultTitle(_ viewStore: ViewStore<TestResultFeature.State, TestResultFeature.Action>) -> some View {
Text.keyme("결과 확인", font: .heading1)
.foregroundColor(DSKitAsset.Color.keymeWhite.swiftUIColor)
.frame(maxWidth: .infinity, alignment: .leading)
.padding(Padding.insets(leading: 16))
}
// 결과 확인 카드 뷰
@MainActor func resultCardView(
_ viewStore: ViewStore<TestResultFeature.State, TestResultFeature.Action>
) -> some View {
ZStack {
TabView(selection: viewStore.$testResult) {
ForEach(viewStore.testResults, id:\.self) {
KeymeCardView(nickname: viewStore.nickname, testResult: $0)
.tag($0)
}
}
.tabViewStyle(.page(indexDisplayMode: .never))
}
}
// 결과 확인 카드 하단 인덱스 뷰
func indexDisplay(_ viewStore: ViewStore<TestResultFeature.State, TestResultFeature.Action>) -> some View {
HStack(spacing: 4) {
ForEach(viewStore.testResults, id: \.self) {
Circle()
.frame(width: 6, height: 6)
.foregroundColor(
($0 == viewStore.testResult) ? .white : .white.opacity(0.3))
}
}
.background(DSKitAsset.Color.keymeBlack.swiftUIColor)
.padding(.bottom, 12)
}
// 하단 버튼 (공유하기)
func bottomButton(_ viewStore: ViewStore<TestResultFeature.State, TestResultFeature.Action>) -> some View {
ZStack {
Rectangle()
.cornerRadius(16)
.foregroundColor(DSKitAsset.Color.keymeWhite.swiftUIColor)
Text("공유하기")
.font(Font(DSKitFontFamily.Pretendard.bold.font(size: 18)))
.foregroundColor(.black)
}
.padding(Padding.insets(leading: 16, trailing: 16))
.frame(height: 60)
.onTapGesture {
Task {
// TODO: url 주석단거로 바꾸기
let url = "https://keyme-frontend.vercel.app/test/\(17)"
let shortURL = try await shortURLManager.request(
.shortenURL(longURL: url),
object: BitlyResponse.self).link
sharedURL = ActivityViewController.SharedURL(shortURL)
}
}
.sheet(item: $sharedURL) { item in
ActivityViewController(
isPresented: Binding<Bool>(
get: { sharedURL != nil },
set: { if !$0 { sharedURL = nil } }),
activityItems: [item.sharedURL])
}
}
}