Skip to content

Commit a5f014c

Browse files
authored
[NL-51]: 히스토리 웹뷰 구현 (#42)
1 parent 609916f commit a5f014c

File tree

6 files changed

+120
-2
lines changed

6 files changed

+120
-2
lines changed

App/Sources/AppDependencyHandler.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import Base
99
import Fortune
1010
import Foundation
11+
import History
1112
import Home
1213
import Lib
1314
import Setting
@@ -28,7 +29,7 @@ struct AppDependencyHandler: DependencyRegistrable {
2829
tabBarController.viewControllers = [
2930
HomeViewController(viewModel: HomeViewModel()),
3031
FortuneViewController(viewModel: FortuneViewModel()),
31-
UIViewController(), // TODO: 뭐 나왔지
32+
HistoryWebViewController(viewModel: HistoryWebViewModel()),
3233
MyPageViewController(viewModel: MyPageViewModel()),
3334
]
3435
UIApplication.shared.activeWindow?.rootViewController = tabBarController

Common/Base/Sources/BaseViewController.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ open class BaseViewController: UIViewController {
3030
setupNavigationBar()
3131
setNavigationBarHidden(false)
3232
}
33+
34+
open override func viewDidLayoutSubviews() {
35+
super.viewDidLayoutSubviews()
36+
updateBottomSafeArea()
37+
}
3338

3439
public func setNavigationBarHidden(_ isHidden: Bool) {
3540
navigationBar.isHidden = isHidden
@@ -53,4 +58,13 @@ open class BaseViewController: UIViewController {
5358
make.horizontalEdges.equalToSuperview()
5459
}
5560
}
61+
62+
private func updateBottomSafeArea() {
63+
guard let tabBarController = tabBarController as? BaseTabBarController,
64+
tabBarController.customTabBar.isHidden == false else {
65+
additionalSafeAreaInsets.bottom = .zero
66+
return
67+
}
68+
additionalSafeAreaInsets.bottom = TabBarView.Constant.tabBarHeight
69+
}
5670
}

Common/Base/Sources/TabBar/BaseTabBarController.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import UIKit
1313

1414
public final class BaseTabBarController: UITabBarController {
1515

16-
private lazy var customTabBar = TabBarView().then {
16+
lazy var customTabBar = TabBarView().then {
1717
$0.backgroundColor = STColors.white.color
1818
}
1919
private var cancellables = Set<AnyCancellable>()
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
//
2+
// HistoryWebViewController.swift
3+
// History
4+
//
5+
// Created by ttozzi on 8/17/25.
6+
//
7+
8+
import Base
9+
import DesignSystem
10+
import UIKit
11+
import SnapKit
12+
import WebKit
13+
14+
public final class HistoryWebViewController: BaseViewController {
15+
16+
private lazy var webView = WKWebView().then {
17+
$0.navigationDelegate = self
18+
}
19+
private let viewModel: HistoryWebViewModel
20+
21+
public init(viewModel: HistoryWebViewModel) {
22+
self.viewModel = viewModel
23+
super.init(nibName: nil, bundle: nil)
24+
}
25+
26+
required init?(coder: NSCoder) {
27+
fatalError("init(coder:) has not been implemented")
28+
}
29+
30+
public override func viewDidLoad() {
31+
super.viewDidLoad()
32+
setupUI()
33+
setupBinding()
34+
viewModel.send(input: .viewDidLoad)
35+
}
36+
37+
private func setupUI() {
38+
setNavigationBarHidden(true)
39+
view.backgroundColor = STColors.primary9.color
40+
webView.backgroundColor = STColors.primary9.color
41+
42+
view.addSubview(webView)
43+
webView.snp.makeConstraints { make in
44+
make.top.equalTo(view.safeAreaLayoutGuide.snp.top)
45+
make.horizontalEdges.equalToSuperview()
46+
make.bottom.equalTo(view.safeAreaLayoutGuide.snp.bottom)
47+
}
48+
}
49+
50+
private func setupBinding() {
51+
viewModel.output.loadURL
52+
.receive(on: DispatchQueue.main)
53+
.sink { [weak self] request in
54+
self?.webView.load(request)
55+
}
56+
.store(in: &cancellables)
57+
}
58+
}
59+
60+
extension HistoryWebViewController: WKNavigationDelegate {
61+
public func webView(_ webView: WKWebView, didFail navigation: WKNavigation!, withError error: any Error) {
62+
print(error)
63+
// TODO: 에러 처리
64+
}
65+
66+
public func webView(_ webView: WKWebView, didFailProvisionalNavigation navigation: WKNavigation!, withError error: any Error) {
67+
print(error)
68+
// TODO: 에러 처리
69+
}
70+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
//
2+
// HistoryWebViewModel.swift
3+
// History
4+
//
5+
// Created by ttozzi on 8/17/25.
6+
//
7+
8+
import Combine
9+
import Foundation
10+
11+
public final class HistoryWebViewModel {
12+
13+
enum Input {
14+
case viewDidLoad
15+
}
16+
17+
struct Output {
18+
let loadURL = PassthroughSubject<URLRequest, Never>()
19+
}
20+
21+
let output = Output()
22+
23+
public init() {}
24+
25+
func send(input: Input) {
26+
switch input {
27+
case .viewDidLoad:
28+
let url = URL(string: "https://clever-kataifi-dcedaf.netlify.app/lotto-history")!
29+
let request = URLRequest(url: url)
30+
output.loadURL.send(request)
31+
}
32+
}
33+
}

Feature/History/Sources/empty.swift

Whitespace-only changes.

0 commit comments

Comments
 (0)