Skip to content

Commit 340e483

Browse files
committed
fix: change ignoresTopSafeArea to true in order to match JS Tabs
1 parent 63fa844 commit 340e483

File tree

6 files changed

+66
-63
lines changed

6 files changed

+66
-63
lines changed

docs/docs/docs/guides/usage-with-react-navigation.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ function SettingsScreen() {
3535
export default function App() {
3636
return (
3737
<NavigationContainer>
38-
<Tab.Navigator ignoresTopSafeArea>
38+
<Tab.Navigator>
3939
<Tab.Screen
4040
name="Home"
4141
component={HomeScreen}
@@ -70,7 +70,7 @@ The name of the route to render on first load of the navigator.
7070

7171
#### `ignoresTopSafeArea` <Badge text="iOS" type="info" />
7272

73-
Whether to ignore the top safe area.
73+
Whether to ignore the top safe area. Defaults to `true`.
7474

7575
#### `screenOptions`
7676

example/src/Examples/NativeBottomTabsEmbeddedStacks.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ function ChatStackScreen() {
6767

6868
function NativeBottomTabsEmbeddedStacks() {
6969
return (
70-
<Tab.Navigator ignoresTopSafeArea>
70+
<Tab.Navigator>
7171
<Tab.Screen
7272
name="Article"
7373
component={ArticleStackScreen}

ios/TabViewImpl.swift

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,22 @@ class TabViewProps: ObservableObject {
1212
@Published var icons: [Int: UIImage] = [:]
1313
@Published var sidebarAdaptable: Bool?
1414
@Published var labeled: Bool?
15-
@Published var ignoresTopSafeArea: Bool?
16-
@Published var disablePageAnimations: Bool = false
1715
@Published var scrollEdgeAppearance: String?
18-
@Published var translucent: Bool = true
1916
@Published var barTintColor: UIColor?
2017
@Published var activeTintColor: UIColor?
2118
@Published var inactiveTintColor: UIColor?
19+
@Published var translucent: Bool = true
20+
@Published var ignoresTopSafeArea: Bool = true
21+
@Published var disablePageAnimations: Bool = false
2222
@Published var hapticFeedbackEnabled: Bool = true
23-
23+
2424
var selectedActiveTintColor: UIColor? {
2525
if let selectedPage = selectedPage,
2626
let tabData = items.findByKey(selectedPage),
2727
let activeTintColor = tabData.activeTintColor {
2828
return activeTintColor
2929
}
30-
30+
3131
return activeTintColor
3232
}
3333
}
@@ -37,11 +37,11 @@ class TabViewProps: ObservableObject {
3737
*/
3838
struct RepresentableView: UIViewRepresentable {
3939
var view: UIView
40-
40+
4141
func makeUIView(context: Context) -> UIView {
4242
return view
4343
}
44-
44+
4545
func updateUIView(_ uiView: UIView, context: Context) {}
4646
}
4747

@@ -52,17 +52,17 @@ struct TabViewImpl: View {
5252
@ObservedObject var props: TabViewProps
5353
var onSelect: (_ key: String) -> Void
5454
var onLongPress: (_ key: String) -> Void
55-
55+
5656
var body: some View {
5757
TabView(selection: $props.selectedPage) {
5858
ForEach(props.children.indices, id: \.self) { index in
5959
let child = props.children[safe: index] ?? UIView()
6060
let tabData = props.items[safe: index]
6161
let icon = props.icons[index]
62-
62+
6363
RepresentableView(view: child)
6464
.ignoresTopSafeArea(
65-
props.ignoresTopSafeArea ?? false,
65+
props.ignoresTopSafeArea,
6666
frame: child.frame
6767
)
6868
.tabItem {
@@ -89,7 +89,7 @@ struct TabViewImpl: View {
8989
}
9090
#endif
9191
}
92-
92+
9393
}
9494
.onTabItemEvent({ index, isLongPress in
9595
if let key = props.items[safe: index]?.key {
@@ -114,13 +114,13 @@ struct TabViewImpl: View {
114114
}
115115
}
116116
}
117-
117+
118118
func emitHapticFeedback(longPress: Bool = false) {
119119
#if os(iOS)
120120
if !props.hapticFeedbackEnabled {
121121
return
122122
}
123-
123+
124124
if longPress {
125125
UINotificationFeedbackGenerator().notificationOccurred(.success)
126126
} else {
@@ -135,16 +135,16 @@ private func configureAppearance(for appearanceType: String, appearance: UITabBa
135135
if (appearanceType == "transparent") {
136136
return appearance
137137
}
138-
138+
139139
switch appearanceType {
140140
case "opaque":
141141
appearance.configureWithOpaqueBackground()
142142
default:
143143
appearance.configureWithDefaultBackground()
144144
}
145-
145+
146146
UITabBar.appearance().scrollEdgeAppearance = appearance
147-
147+
148148
return appearance
149149
}
150150

@@ -160,7 +160,7 @@ private func configureAppearance(inactiveTint inactiveTintColor: UIColor?, appea
160160
setTabBarItemColors(appearance.inlineLayoutAppearance, inactiveColor: inactiveTintColor)
161161
setTabBarItemColors(appearance.compactInlineLayoutAppearance, inactiveColor: inactiveTintColor)
162162
}
163-
163+
164164
return appearance
165165
}
166166

@@ -170,23 +170,23 @@ private func updateTabBarAppearance(props: TabViewProps) {
170170
inactiveTint: props.inactiveTintColor,
171171
appearance: appearance
172172
)
173-
174-
173+
174+
175175
if #available(iOS 15.0, *) {
176176
appearance = configureAppearance(for: props.scrollEdgeAppearance ?? "", appearance: appearance)
177-
177+
178178
if props.translucent == false {
179179
appearance.configureWithOpaqueBackground()
180180
}
181-
181+
182182
if props.barTintColor != nil {
183183
appearance.backgroundColor = props.barTintColor
184184
}
185185
} else {
186186
UITabBar.appearance().barTintColor = props.barTintColor
187187
UITabBar.appearance().isTranslucent = props.translucent
188188
}
189-
189+
190190
UITabBar.appearance().standardAppearance = appearance
191191
}
192192

@@ -195,7 +195,7 @@ struct TabItem: View {
195195
var icon: UIImage?
196196
var sfSymbol: String?
197197
var labeled: Bool?
198-
198+
199199
var body: some View {
200200
if let icon {
201201
Image(uiImage: icon)
@@ -224,7 +224,7 @@ extension View {
224224
self
225225
}
226226
}
227-
227+
228228
@ViewBuilder
229229
func tabBadge(_ data: String?) -> some View {
230230
if #available(iOS 15.0, macOS 15.0, visionOS 2.0, tvOS 15.0, *) {
@@ -241,7 +241,7 @@ extension View {
241241
self
242242
}
243243
}
244-
244+
245245
@ViewBuilder
246246
func ignoresTopSafeArea(
247247
_ flag: Bool,
@@ -258,7 +258,7 @@ extension View {
258258
.frame(idealWidth: frame.width, idealHeight: frame.height)
259259
}
260260
}
261-
261+
262262
@ViewBuilder
263263
func configureAppearance(props: TabViewProps) -> some View {
264264
self
@@ -281,7 +281,7 @@ extension View {
281281
updateTabBarAppearance(props: props)
282282
}
283283
}
284-
284+
285285
@ViewBuilder
286286
func tintColor(_ color: UIColor?) -> some View {
287287
if let color {
@@ -295,7 +295,7 @@ extension View {
295295
self
296296
}
297297
}
298-
298+
299299
// Allows TabView to use unfilled SFSymbols.
300300
// By default they are always filled.
301301
@ViewBuilder

0 commit comments

Comments
 (0)