Skip to content

Commit 825e39c

Browse files
authored
Fix/bottom safe area (#37)
* fix: horizontal safe area layout * fix: Make TabView work with automaticallyAdjustScrollInsets * sync podfile * fix: TabView layouting
1 parent caa5e7b commit 825e39c

File tree

5 files changed

+42
-32
lines changed

5 files changed

+42
-32
lines changed

example/ios/Podfile.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1209,7 +1209,7 @@ PODS:
12091209
- ReactCommon/turbomodule/bridging
12101210
- ReactCommon/turbomodule/core
12111211
- Yoga
1212-
- react-native-bottom-tabs (0.1.0):
1212+
- react-native-bottom-tabs (0.0.9):
12131213
- DoubleConversion
12141214
- glog
12151215
- RCT-Folly (= 2024.01.01.00)
@@ -1793,7 +1793,7 @@ SPEC CHECKSUMS:
17931793
React-logger: 4072f39df335ca443932e0ccece41fbeb5ca8404
17941794
React-Mapbuffer: 714f2fae68edcabfc332b754e9fbaa8cfc68fdd4
17951795
React-microtasksnativemodule: 618b64238e43ef3154079f193aa6649e5320ae19
1796-
react-native-bottom-tabs: 5662b5e3b5968bec6258b9d6f1a0a834bd3f7553
1796+
react-native-bottom-tabs: 6b4dff8469797a3bf8758594832955a2214e2e0d
17971797
react-native-safe-area-context: 851c62c48dce80ccaa5637b6aa5991a1bc36eca9
17981798
React-nativeconfig: 4a9543185905fe41014c06776bf126083795aed9
17991799
React-NativeModulesApple: 651670a799672bd54469f2981d91493dda361ddf

ios/Extensions.swift

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
11
import Foundation
2+
import SwiftUI
23

34
extension Collection {
4-
// Returns the element at the specified index if it is within bounds, otherwise nil.
5-
subscript(safe index: Index) -> Element? {
6-
return indices.contains(index) ? self[index] : nil
7-
}
5+
// Returns the element at the specified index if it is within bounds, otherwise nil.
6+
subscript(safe index: Index) -> Element? {
7+
return indices.contains(index) ? self[index] : nil
8+
}
89
}
910

1011
extension UIView {
11-
func pinEdges(to other: UIView) {
12-
leadingAnchor.constraint(equalTo: other.leadingAnchor).isActive = true
13-
trailingAnchor.constraint(equalTo: other.trailingAnchor).isActive = true
14-
topAnchor.constraint(equalTo: other.topAnchor).isActive = true
15-
bottomAnchor.constraint(equalTo: other.bottomAnchor).isActive = true
16-
}
12+
func pinEdges(to other: UIView) {
13+
NSLayoutConstraint.activate([
14+
leadingAnchor.constraint(equalTo: other.leadingAnchor),
15+
trailingAnchor.constraint(equalTo: other.trailingAnchor),
16+
topAnchor.constraint(equalTo: other.topAnchor),
17+
bottomAnchor.constraint(equalTo: other.bottomAnchor)
18+
])
19+
}
1720
}

ios/TabViewImpl.swift

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,12 @@ class TabViewProps: ObservableObject {
2020
*/
2121
struct RepresentableView: UIViewRepresentable {
2222
var view: UIView
23+
2324
func makeUIView(context: Context) -> UIView {
2425
return view
2526
}
26-
func updateUIView(_ uiView: UIView, context: Context) {
27-
}
27+
28+
func updateUIView(_ uiView: UIView, context: Context) {}
2829
}
2930

3031
/**
@@ -120,13 +121,19 @@ extension View {
120121
}
121122

122123
@ViewBuilder
123-
func ignoresTopSafeArea(_ flag: Bool, frame: CGRect) -> some View {
124+
func ignoresTopSafeArea(
125+
_ flag: Bool,
126+
frame: CGRect
127+
) -> some View {
124128
if flag {
125129
self
126-
.ignoresSafeArea(.container, edges: .top)
127-
.frame(width: frame.width)
130+
.ignoresSafeArea(.container, edges: .all)
131+
.frame(idealWidth: frame.width, idealHeight: frame.height)
128132
} else {
129133
self
134+
.ignoresSafeArea(.container, edges: .horizontal)
135+
.ignoresSafeArea(.container, edges: .bottom)
136+
.frame(idealWidth: frame.width, idealHeight: frame.height)
130137
}
131138
}
132139
}

ios/TabViewProvider.swift

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,21 @@ struct TabData: Codable {
2020
private var eventDispatcher: RCTEventDispatcherProtocol?
2121
private var imageLoader: RCTImageLoaderProtocol?
2222
private var iconSize = CGSize(width: 27, height: 27)
23-
23+
2424
@objc var onPageSelected: RCTDirectEventBlock?
25-
25+
2626
@objc var icons: NSArray? {
2727
didSet {
2828
loadIcons(icons)
2929
}
3030
}
31-
31+
3232
@objc var sidebarAdaptable: Bool = false {
3333
didSet {
3434
props.sidebarAdaptable = sidebarAdaptable
3535
}
3636
}
37-
37+
3838
@objc var labeled: Bool = true {
3939
didSet {
4040
props.labeled = labeled
@@ -46,35 +46,35 @@ struct TabData: Codable {
4646
props.ignoresTopSafeArea = ignoresTopSafeArea
4747
}
4848
}
49-
49+
5050
@objc var selectedPage: NSString? {
5151
didSet {
5252
props.selectedPage = selectedPage as? String
5353
}
5454
}
55-
55+
5656
@objc var items: NSArray? {
5757
didSet {
5858
props.items = parseTabData(from: items)
5959
}
6060
}
61-
61+
6262
@objc public convenience init(eventDispatcher: RCTEventDispatcherProtocol, imageLoader: RCTImageLoader) {
6363
self.init()
6464
self.eventDispatcher = eventDispatcher
6565
self.imageLoader = imageLoader
6666
}
67-
67+
6868
public override func didUpdateReactSubviews() {
6969
props.children = reactSubviews()
7070
}
71-
71+
7272
public override func layoutSubviews() {
7373
super.layoutSubviews()
7474
setupView()
7575
props.children = reactSubviews()
7676
}
77-
77+
7878
private func setupView() {
7979
if self.hostingController != nil {
8080
return
@@ -92,7 +92,7 @@ struct TabData: Codable {
9292
hostingController.didMove(toParent: parentViewController)
9393
}
9494
}
95-
95+
9696
private func loadIcons(_ icons: NSArray?) {
9797
// TODO: Diff the arrays and update only changed items.
9898
// Now if the user passes `unfocusedIcon` we update every item.
@@ -120,11 +120,11 @@ struct TabData: Codable {
120120
}
121121
}
122122
}
123-
123+
124124
private func parseTabData(from array: NSArray?) -> TabData? {
125125
guard let array else { return nil }
126126
var items: [TabInfo] = []
127-
127+
128128
for value in array {
129129
if let itemDict = value as? [String: Any] {
130130
items.append(
@@ -137,7 +137,7 @@ struct TabData: Codable {
137137
)
138138
}
139139
}
140-
140+
141141
return TabData(tabs: items)
142142
}
143143
}

src/TabView.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ const TabView = <Route extends BaseRoute>({
178178
if (Platform.OS === 'android') {
179179
return null;
180180
}
181-
return <View key={route.key} />;
181+
return <View key={route.key} style={styles.fullWidth} />;
182182
}
183183

184184
return (

0 commit comments

Comments
 (0)