Skip to content

Commit 05270de

Browse files
committed
feature: Tab bar safe area is defined by a top anchor point instead of bounds
This makes it easier to specify the safe area for a bar that has interactive or decorative elements extending upwards. BREAKING CHANGE: TabBarBoundsForSafeAreaKey is now TabBarTopForSafeAreaKey
1 parent 063a6f0 commit 05270de

File tree

4 files changed

+6
-6
lines changed

4 files changed

+6
-6
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ struct SampleTabBarView: View {
9494
}
9595
}
9696
}
97-
.anchorPreference(key: TabBarBoundsForSafeAreaKey.self, value: .bounds, transform: { $0 })
97+
.anchorPreference(key: TabBarTopForSafeAreaKey.self, value: .top, transform: { $0 })
9898
}
9999

100100
private func tabBarItem(for tab: Tab) -> some View {

Sources/CustomTabView/CustomTabView.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,9 @@ struct _TabBarLayoutView<TabBarView: View, Subviews>: View where Subviews: Rando
113113
#endif
114114
tabBarView
115115
.opacity(tabBarVisibility[selectedTabIndex] == .hidden ? 0 : 1)
116-
.onPreferenceChange(TabBarBoundsForSafeAreaKey.self) {
116+
.onPreferenceChange(TabBarTopForSafeAreaKey.self) {
117117
if let anchor = $0 {
118-
tabBarHeight = proxy[anchor].height
118+
tabBarHeight = max(0, -(proxy[anchor].y - proxy.size.height))
119119
}
120120
}
121121
})

Sources/CustomTabView/Example/BottomFloatingTabBarView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ struct BottomFloatingTabBarView: View {
3131
}
3232
#endif
3333
.clipShape(RoundedRectangle(cornerRadius: 25))
34-
.anchorPreference(key: TabBarBoundsForSafeAreaKey.self, value: .bounds, transform: { $0 })
34+
.anchorPreference(key: TabBarTopForSafeAreaKey.self, value: .top, transform: { $0 })
3535
.shadow(color: .secondary.opacity(0.3), radius: 10, y: 5)
3636
}
3737

Sources/CustomTabView/TabBarHeight.swift renamed to Sources/CustomTabView/TabBarTopForSafeAreaKey.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import SwiftUI
22

3-
public struct TabBarBoundsForSafeAreaKey: PreferenceKey {
4-
public static var defaultValue: Anchor<CGRect>? { nil }
3+
public struct TabBarTopForSafeAreaKey: PreferenceKey {
4+
public static var defaultValue: Anchor<CGPoint>? { nil }
55

66
public static func reduce(
77
value: inout Value,

0 commit comments

Comments
 (0)