Skip to content

Commit ff65ab0

Browse files
committed
fix: Toast를 탭바 높이만큼 띄우도록 수정
1 parent 3609008 commit ff65ab0

1 file changed

Lines changed: 54 additions & 0 deletions

File tree

  • Application/DevLogPresentation/Sources/Common/Component

Application/DevLogPresentation/Sources/Common/Component/Toast.swift

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,19 @@ extension View {
8585
}
8686

8787
private struct ToastHostModifier: ViewModifier {
88+
@Environment(\.safeAreaInsets) private var safeAreaInsets
89+
@State private var tabBarHeight = CGFloat.zero
8890
private let toastPresenter = ToastPresenter.presenter
8991

9092
func body(content: Content) -> some View {
9193
content
9294
.frame(maxWidth: .infinity, maxHeight: .infinity)
95+
.onAppear {
96+
updateTabBarHeight()
97+
}
98+
.onChange(of: toastPresenter.item?.id) { _, _ in
99+
updateTabBarHeight()
100+
}
93101
.overlay(alignment: .bottom) {
94102
if let item = toastPresenter.item {
95103
ToastOverlayView(
@@ -109,9 +117,28 @@ private struct ToastHostModifier: ViewModifier {
109117
}
110118
.id(item.id)
111119
.padding(.horizontal, 12)
120+
.padding(.bottom, toastBottomInset)
112121
}
113122
}
114123
}
124+
125+
private var toastBottomInset: CGFloat {
126+
max(0, tabBarHeight - safeAreaInsets.bottom)
127+
}
128+
129+
@MainActor
130+
private func updateTabBarHeight() {
131+
let window = UIApplication.shared.connectedScenes
132+
.compactMap { $0 as? UIWindowScene }
133+
.flatMap(\.windows)
134+
.first { $0.isKeyWindow }
135+
136+
guard let window else {
137+
tabBarHeight = .zero
138+
return
139+
}
140+
tabBarHeight = window.rootViewController?.visibleTabBarHeight ?? .zero
141+
}
115142
}
116143

117144
private struct ToastItemLabel: View {
@@ -279,3 +306,30 @@ private struct ToastCardView<Label: View>: View {
279306
.shadow(color: Color(.systemGray2).opacity(0.4), radius: 18, x: 0, y: 10)
280307
}
281308
}
309+
310+
@MainActor
311+
private extension UIViewController {
312+
var visibleTabBarHeight: CGFloat {
313+
if let tabBarController = self as? UITabBarController {
314+
return tabBarController.tabBar.isHidden ? .zero : tabBarController.tabBar.frame.height
315+
}
316+
317+
if let tabBarController {
318+
return tabBarController.tabBar.isHidden ? .zero : tabBarController.tabBar.frame.height
319+
}
320+
321+
if let presentedViewController,
322+
0 < presentedViewController.visibleTabBarHeight {
323+
return presentedViewController.visibleTabBarHeight
324+
}
325+
326+
for child in children {
327+
let childHeight = child.visibleTabBarHeight
328+
if 0 < childHeight {
329+
return childHeight
330+
}
331+
}
332+
333+
return .zero
334+
}
335+
}

0 commit comments

Comments
 (0)