Skip to content

Commit 77db8d4

Browse files
committed
fix: improve subview foreach, use view as identifier
1 parent f564fde commit 77db8d4

File tree

2 files changed

+13
-12
lines changed

2 files changed

+13
-12
lines changed

packages/react-native-bottom-tabs/ios/TabView/LegacyTabView.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@ struct LegacyTabView: AnyTabView {
1010
@ViewBuilder
1111
var body: some View {
1212
TabView(selection: $props.selectedPage) {
13-
ForEach(props.children.indices, id: \.self) { index in
14-
renderTabItem(at: index)
13+
ForEach(props.children, id: \.self) { child in
14+
if let index = props.children.firstIndex(of: child) {
15+
renderTabItem(at: index)
16+
}
1517
}
1618
.measureView { size in
1719
onLayout(size)

packages/react-native-bottom-tabs/ios/TabView/NewTabView.swift

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,33 +3,32 @@ import SwiftUI
33
@available(iOS 18, macOS 15, visionOS 2, tvOS 18, *)
44
struct NewTabView: AnyTabView {
55
@ObservedObject var props: TabViewProps
6-
6+
77
var onLayout: (CGSize) -> Void
88
var onSelect: (String) -> Void
99
var updateTabBarAppearance: () -> Void
10-
10+
1111
@ViewBuilder
1212
var body: some View {
1313
TabView(selection: $props.selectedPage) {
14-
ForEach(props.children.indices, id: \.self) { index in
15-
if let tabData = props.items[safe: index] {
14+
ForEach(props.children, id: \.self) { child in
15+
if let index = props.children.firstIndex(of: child),
16+
let tabData = props.items[safe: index] {
1617
let isFocused = props.selectedPage == tabData.key
17-
18+
1819
if !tabData.hidden || isFocused {
1920
let icon = props.icons[index]
20-
21-
let platformChild = props.children[safe: index] ?? PlatformView()
22-
let child = RepresentableView(view: platformChild)
21+
2322
let context = TabAppearContext(
2423
index: index,
2524
tabData: tabData,
2625
props: props,
2726
updateTabBarAppearance: updateTabBarAppearance,
2827
onSelect: onSelect
2928
)
30-
29+
3130
Tab(value: tabData.key, role: tabData.role?.convert()) {
32-
child
31+
RepresentableView(view: child)
3332
.ignoresSafeArea(.container, edges: .all)
3433
.tabAppear(using: context)
3534
} label: {

0 commit comments

Comments
 (0)