Skip to content

Commit 37e6525

Browse files
committed
Remove redundant addView/removeView (it's handled internally upon setting items) and correct log messages
1 parent 522d34e commit 37e6525

File tree

2 files changed

+3
-23
lines changed

2 files changed

+3
-23
lines changed

src/bottom-navigation/react/index.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,15 +66,9 @@ export function registerBottomNavigation(): void {
6666
if (typeof atIndex === 'undefined' || atIndex === items.length) {
6767
bottomNavigation._addChildFromBuilder('items', child.nativeView as TabContentItem);
6868
} else {
69-
items.forEach((item) => {
70-
bottomNavigation._removeView(item);
71-
});
7269
const itemsClone = items.slice();
7370
itemsClone.splice(atIndex, 0, child.nativeView as TabContentItem);
7471
bottomNavigation.items = itemsClone;
75-
itemsClone.forEach((item) => {
76-
bottomNavigation._addView(item);
77-
});
7872
}
7973
} else if (child.nodeRole === 'item') {
8074
if (__DEV__) {

src/tabs/react/index.ts

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -105,15 +105,9 @@ export function registerTabs(): void {
105105
tabStrip._addChildFromBuilder('items', child.nativeView as TabStripItem);
106106
} else {
107107
// console.log(`[tabStrip.insert] 2b [${parent} > ${child} @${atIndex}] => [${parent.childNodes}]`);
108-
items.forEach((item) => {
109-
tabStrip._removeView(item);
110-
});
111108
const itemsClone = items.slice();
112109
itemsClone.splice(atIndex, 0, child.nativeView as TabStripItem);
113110
tabStrip.items = itemsClone;
114-
itemsClone.forEach((item) => {
115-
tabStrip._addView(item);
116-
});
117111
}
118112
} else if (child.nodeRole === 'item') {
119113
if (__DEV__) {
@@ -133,7 +127,6 @@ export function registerTabs(): void {
133127

134128
if (child.nodeRole === 'items') {
135129
tabStrip.items = (tabStrip.items || []).filter((i) => i !== child.nativeView);
136-
tabStrip._removeView(child.nativeView);
137130
} else if (child.nodeRole === 'item') {
138131
if (__DEV__) {
139132
warn(`Unable to remove child "${child.nativeView.constructor.name}" from <tabStrip> as it had the nodeRole "item"; please correct it to "items".`);
@@ -164,7 +157,7 @@ export function registerTabs(): void {
164157
// keep these good practices in case it's ever refactored.
165158

166159
if (child.nodeRole === 'label') {
167-
console.log(`[tabStrip.insert] LABEL [${parent} > ${child} @${atIndex}] => [${parent.childNodes}]`);
160+
console.log(`[tabStripItem.insert] LABEL [${parent} > ${child} @${atIndex}] => [${parent.childNodes}]`);
168161
if (child.nativeView instanceof Label === false) {
169162
if (__DEV__) {
170163
warn(`Unable to add child "${child.nativeView.constructor.name}" to the items of <tabStripItem> as it is not an instance of Label.`);
@@ -174,7 +167,7 @@ export function registerTabs(): void {
174167

175168
tabStripItem.label = child.nativeView as Label;
176169
} else if (child.nodeRole === 'image') {
177-
console.log(`[tabStrip.insert] IMAGE [${parent} > ${child} @${atIndex}] => [${parent.childNodes}]`);
170+
console.log(`[tabStripItem.insert] IMAGE [${parent} > ${child} @${atIndex}] => [${parent.childNodes}]`);
178171
if (child.nativeView instanceof Image === false) {
179172
if (__DEV__) {
180173
warn(`Unable to add child "${child.nativeView.constructor.name}" to the items of <tabStripItem> as it is not an instance of Image.`);
@@ -184,7 +177,7 @@ export function registerTabs(): void {
184177

185178
tabStripItem.image = child.nativeView as Image;
186179
} else {
187-
console.log(`[tabStrip.insert] OTHER [${parent} > ${child} @${atIndex}] => [${parent.childNodes}]`);
180+
console.log(`[tabStripItem.insert] OTHER [${parent} > ${child} @${atIndex}] => [${parent.childNodes}]`);
188181
if (__DEV__) {
189182
warn(
190183
`Unable to add child "${child.nativeView.constructor.name}" to <tabStripItem> as it does not have a nodeRole specified; ` +
@@ -245,15 +238,9 @@ export function registerTabs(): void {
245238
if (typeof atIndex === 'undefined' || atIndex === items.length) {
246239
tabs._addChildFromBuilder('items', child.nativeView as TabContentItem);
247240
} else {
248-
items.forEach((item) => {
249-
tabs._removeView(item);
250-
});
251241
const itemsClone = items.slice();
252242
itemsClone.splice(atIndex, 0, child.nativeView as TabContentItem);
253243
tabs.items = itemsClone;
254-
itemsClone.forEach((item) => {
255-
tabs._addView(item);
256-
});
257244
}
258245
} else if (child.nodeRole === 'item') {
259246
if (__DEV__) {
@@ -274,7 +261,6 @@ export function registerTabs(): void {
274261
tabs.tabStrip = null; // Anything falsy should work.
275262
} else if (child.nodeRole === 'items') {
276263
tabs.items = (tabs.items || []).filter((i) => i !== child.nativeView);
277-
tabs._removeView(child.nativeView);
278264
} else if (child.nodeRole === 'item') {
279265
if (__DEV__) {
280266
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)