Skip to content

Commit fb67897

Browse files
committed
Stop crash upon adding TabContentItem
1 parent 1660302 commit fb67897

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

src/bottom-navigation/react/index.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,17 @@ export function registerBottomNavigation(): void {
6464
const items = bottomNavigation.items || []; // Annoyingly, it's the consumer's responsibility to ensure there's an array there!
6565

6666
if (typeof atIndex === 'undefined' || atIndex === items.length) {
67-
bottomNavigation.items = items.concat(child.nativeView as TabContentItem);
67+
bottomNavigation._addChildFromBuilder('items', child.nativeView as TabContentItem);
6868
} else {
69-
bottomNavigation.items = items.slice().splice(atIndex, 0, child.nativeView as TabContentItem);
69+
items.forEach((item) => {
70+
bottomNavigation._removeView(item);
71+
});
72+
const itemsClone = items.slice();
73+
itemsClone.splice(atIndex, 0, child.nativeView as TabContentItem);
74+
bottomNavigation.items = itemsClone;
75+
itemsClone.forEach((item) => {
76+
bottomNavigation._addView(item);
77+
});
7078
}
7179
} else if (child.nodeRole === 'item') {
7280
if (__DEV__) {

src/tabs/react/index.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,9 +235,17 @@ export function registerTabs(): void {
235235

236236
const items = tabs.items || []; // Annoyingly, it's the consumer's responsibility to ensure there's an array there!
237237
if (typeof atIndex === 'undefined' || atIndex === items.length) {
238-
tabs.items = items.concat(child.nativeView as TabContentItem);
238+
tabs._addChildFromBuilder('items', child.nativeView as TabContentItem);
239239
} else {
240-
tabs.items = items.slice().splice(atIndex, 0, child.nativeView as TabContentItem);
240+
items.forEach((item) => {
241+
tabs._removeView(item);
242+
});
243+
const itemsClone = items.slice();
244+
itemsClone.splice(atIndex, 0, child.nativeView as TabContentItem);
245+
tabs.items = itemsClone;
246+
itemsClone.forEach((item) => {
247+
tabs._addView(item);
248+
});
241249
}
242250
} else if (child.nodeRole === 'item') {
243251
if (__DEV__) {
@@ -258,6 +266,7 @@ export function registerTabs(): void {
258266
tabs.tabStrip = null; // Anything falsy should work.
259267
} else if (child.nodeRole === 'items') {
260268
tabs.items = (tabs.items || []).filter((i) => i !== child.nativeView);
269+
tabs._removeView(child.nativeView);
261270
} else if (child.nodeRole === 'item') {
262271
if (__DEV__) {
263272
warn(`Unable to remove child "${child.nativeView.constructor.name}" from <tabs> as it had the nodeRole "item"; please correct it to "items".`);

0 commit comments

Comments
 (0)