Skip to content

Commit 4585672

Browse files
authored
Merge pull request #209 from YAPP-Github/BOOK-307-fix/#208
feat: 로딩 인디케이터에 딜레이 적용
2 parents eab1f20 + 1c3eba8 commit 4585672

File tree

2 files changed

+44
-28
lines changed

2 files changed

+44
-28
lines changed

src/Projects/BKDesign/Sources/Components/BKLoading/BKLoadingIndicator.swift

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,48 @@
11
// Copyright © 2025 Booket. All rights reserved
22

3-
import UIKit
43
import SnapKit
4+
import UIKit
55

66
public final class LoadingIndicator {
77

88
private static let tag = 999999
9+
private static var delayedWorkItem: DispatchWorkItem?
910

1011
/// 로딩 인디케이터 보여주기
11-
public static func show() {
12+
public static func show(
13+
delay: TimeInterval = 0.5
14+
) {
1215
DispatchQueue.main.async {
13-
guard let window = getKeyWindow() else { return }
14-
15-
if window.viewWithTag(tag) != nil {
16-
return
16+
guard delayedWorkItem == nil else { return }
17+
18+
let workItem = DispatchWorkItem {
19+
defer { delayedWorkItem = nil }
20+
guard Self.delayedWorkItem?.isCancelled != true else { return }
21+
guard let window = getKeyWindow() else { return }
22+
guard window.viewWithTag(tag) == nil else { return }
23+
24+
let loadingIndicatorView = createLoadingView(frame: window.bounds)
25+
loadingIndicatorView.tag = tag
26+
window.addSubview(loadingIndicatorView)
27+
loadingIndicatorView.startAnimating()
1728
}
18-
19-
let loadingIndicatorView = createLoadingView(frame: window.bounds)
20-
loadingIndicatorView.tag = tag
21-
22-
window.addSubview(loadingIndicatorView)
23-
loadingIndicatorView.startAnimating()
29+
30+
delayedWorkItem = workItem
31+
DispatchQueue.main.asyncAfter(deadline: .now() + delay, execute: workItem)
2432
}
2533
}
2634

2735
/// 로딩 인디케이터 숨기기
2836
public static func hide() {
2937
DispatchQueue.main.async {
38+
delayedWorkItem?.cancel()
39+
delayedWorkItem = nil
40+
3041
guard let window = getKeyWindow() else { return }
3142

32-
window.subviews.filter({ $0.tag == tag }).forEach {
33-
$0.removeFromSuperview()
34-
}
43+
window.subviews
44+
.filter{ $0.tag == tag }
45+
.forEach { $0.removeFromSuperview() }
3546
}
3647
}
3748

src/Projects/BKPresentation/Sources/MainFlow/NoteCompletion/View/NoteCompletionViewController.swift

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ final class NoteCompletionViewController: BaseViewController<NoteCompletionView>
6060
}
6161
.store(in: &cancellable)
6262

63-
6463
viewModel.statePublisher
6564
.map { $0.isLoading }
6665
.removeDuplicates()
@@ -77,18 +76,8 @@ final class NoteCompletionViewController: BaseViewController<NoteCompletionView>
7776
viewModel.statePublisher
7877
.receive(on: DispatchQueue.main)
7978
.compactMap { $0.error }
80-
.sink { [weak self] error in
81-
// 에러 알림 표시 -> BKStyle로 교체 필요
82-
let alert = UIAlertController(
83-
title: "오류",
84-
message: "기록을 불러올 수 없습니다.",
85-
preferredStyle: .alert
86-
)
87-
alert.addAction(UIAlertAction(title: "확인", style: .default) { _ in
88-
self?.viewModel.send(.errorHandled)
89-
self?.dismiss(animated: true)
90-
})
91-
self?.present(alert, animated: true)
79+
.sink { [weak self] _ in
80+
self?.presentErrorDialog()
9281
}
9382
.store(in: &cancellable)
9483

@@ -175,6 +164,22 @@ final class NoteCompletionViewController: BaseViewController<NoteCompletionView>
175164
present(dialogViewController, animated: true)
176165
}
177166

167+
func presentErrorDialog() {
168+
let dialog = BKDialog(
169+
title: "오류",
170+
config: .init(
171+
leftButtonTitle: "기록을 불러올 수 없습니다.",
172+
leftButtonAction: { [weak self] in
173+
self?.dismiss(animated: true) { [weak self] in
174+
self?.viewModel.send(.errorHandled)
175+
}
176+
}
177+
)
178+
)
179+
let dialogViewController = BKDialogViewController(dialog: dialog)
180+
self.present(dialogViewController, animated: true)
181+
}
182+
178183
@objc private func customBackButtonTapped() {
179184
dismiss(animated: true)
180185
}

0 commit comments

Comments
 (0)