Skip to content

Commit 89a106c

Browse files
committed
Option to enable/disable debug logging
1 parent 37e6525 commit 89a106c

File tree

2 files changed

+35
-31
lines changed

2 files changed

+35
-31
lines changed

src/bottom-navigation/react/index.ts

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,6 @@ import { warn } from 'react-nativescript/dist/shared/Logger';
33
import { BottomNavigation, SelectedIndexChangedEventData, TabContentItem, TabStrip } from '../';
44
import { TabNavigationBaseAttributes } from '@nativescript-community/ui-material-core/tab-navigation-base/tab-navigation-base/react';
55

6-
// Global compile-time constant (for some reason not exported by RNS itself)
7-
// eslint-disable-next-line no-var
8-
declare var __DEV__: boolean;
9-
106
// ui/bottom-navigation/bottom-navigation.d.ts
117
export type BottomNavigationAttributes = TabNavigationBaseAttributes & {
128
android?: any;
@@ -31,7 +27,13 @@ declare global {
3127

3228
let installed: boolean = false;
3329

34-
export function registerBottomNavigation(): void {
30+
interface RegisterBottomNavigationOptions {
31+
enableDebugLogging?: boolean;
32+
}
33+
34+
export function registerBottomNavigation(opts: RegisterBottomNavigationOptions = {}): void {
35+
const { enableDebugLogging = false } = opts;
36+
3537
if (installed) {
3638
return;
3739
}
@@ -49,13 +51,13 @@ export function registerBottomNavigation(): void {
4951
if (child.nativeView instanceof TabStrip) {
5052
bottomNavigation.tabStrip = child.nativeView;
5153
} else {
52-
if (__DEV__) {
54+
if (enableDebugLogging) {
5355
warn(`Unable to add child "${child.nativeView.constructor.name}" as the tabStrip of <bottomNavigation> as it is not an instance of TabStrip.`);
5456
}
5557
}
5658
} else if (child.nodeRole === 'items') {
5759
if (child.nativeView instanceof TabContentItem === false) {
58-
if (__DEV__) {
60+
if (enableDebugLogging) {
5961
warn(`Unable to add child "${child.nativeView.constructor.name}" to the items of <bottomNavigation> as it is not an instance of TabContentItem.`);
6062
}
6163
return;
@@ -71,11 +73,11 @@ export function registerBottomNavigation(): void {
7173
bottomNavigation.items = itemsClone;
7274
}
7375
} else if (child.nodeRole === 'item') {
74-
if (__DEV__) {
76+
if (enableDebugLogging) {
7577
warn(`Unable to add child "${child.nativeView.constructor.name}" to <bottomNavigation> as it had the nodeRole "item"; please correct it to "items".`);
7678
}
7779
} else {
78-
if (__DEV__) {
80+
if (enableDebugLogging) {
7981
warn(
8082
`Unable to add child "${child.nativeView.constructor.name}" to <bottomNavigation> as it does not have a nodeRole specified; ` +
8183
'please set a nodeRole of "tabStrip", or "items".'
@@ -91,11 +93,11 @@ export function registerBottomNavigation(): void {
9193
} else if (child.nodeRole === 'items') {
9294
tabs.items = (tabs.items || []).filter((i) => i !== child.nativeView);
9395
} else if (child.nodeRole === 'item') {
94-
if (__DEV__) {
96+
if (enableDebugLogging) {
9597
warn(`Unable to remove child "${child.nativeView.constructor.name}" from <bottomNavigation> as it had the nodeRole "item"; please correct it to "items".`);
9698
}
9799
} else {
98-
if (__DEV__) {
100+
if (enableDebugLogging) {
99101
warn(
100102
`Unable to remove child "${child.nativeView.constructor.name}" from <bottomNavigation> as it does not have a nodeRole specified; ` +
101103
'please set a nodeRole of "tabStrip", or "items"'

src/tabs/react/index.ts

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,6 @@ import { TabContentItem, TabStrip, TabStripItem, Tabs } from '../tabs';
55
import { TabNavigationBaseAttributes } from '@nativescript-community/ui-material-core/tab-navigation-base/tab-navigation-base/react';
66
import { SelectedIndexChangedEventData } from '@nativescript-community/ui-material-core/tab-navigation-base/tab-navigation-base';
77

8-
// Global compile-time constant (for some reason not exported by RNS itself)
9-
// eslint-disable-next-line no-var
10-
declare var __DEV__: boolean;
11-
128
// ui/tabs/tabs.d.ts
139
export type TabsAttributes = TabNavigationBaseAttributes & {
1410
android?: any;
@@ -75,7 +71,13 @@ declare global {
7571
}
7672
let installed: boolean = false;
7773

78-
export function registerTabs(): void {
74+
interface RegisterTabsOptions {
75+
enableDebugLogging?: boolean;
76+
}
77+
78+
export function registerTabs(opts: RegisterTabsOptions): void {
79+
const { enableDebugLogging = false } = opts;
80+
7981
if (installed) {
8082
return;
8183
}
@@ -91,7 +93,7 @@ export function registerTabs(): void {
9193

9294
if (child.nodeRole === 'items') {
9395
if (child.nativeView instanceof TabStripItem === false) {
94-
if (__DEV__) {
96+
if (enableDebugLogging) {
9597
warn(`Unable to add child "${child.nativeView.constructor.name}" to the items of <tabStrip> as it is not an instance of TabStripItem.`);
9698
}
9799
return;
@@ -110,11 +112,11 @@ export function registerTabs(): void {
110112
tabStrip.items = itemsClone;
111113
}
112114
} else if (child.nodeRole === 'item') {
113-
if (__DEV__) {
115+
if (enableDebugLogging) {
114116
warn(`Unable to add child "${child.nativeView.constructor.name}" to <tabStrip> as it had the nodeRole "item"; please correct it to "items".`);
115117
}
116118
} else {
117-
if (__DEV__) {
119+
if (enableDebugLogging) {
118120
warn(
119121
`Unable to add child "${child.nativeView.constructor.name}" to <tabStrip> as it does not have a nodeRole specified; ` +
120122
'please set a nodeRole of "tabStrip", or "items".'
@@ -128,11 +130,11 @@ export function registerTabs(): void {
128130
if (child.nodeRole === 'items') {
129131
tabStrip.items = (tabStrip.items || []).filter((i) => i !== child.nativeView);
130132
} else if (child.nodeRole === 'item') {
131-
if (__DEV__) {
133+
if (enableDebugLogging) {
132134
warn(`Unable to remove child "${child.nativeView.constructor.name}" from <tabStrip> as it had the nodeRole "item"; please correct it to "items".`);
133135
}
134136
} else {
135-
if (__DEV__) {
137+
if (enableDebugLogging) {
136138
warn(
137139
`Unable to remove child "${child.nativeView.constructor.name}" from <tabStrip> as it does not have a nodeRole specified; ` +
138140
'please set a nodeRole of "tabStrip", or "items"'
@@ -159,7 +161,7 @@ export function registerTabs(): void {
159161
if (child.nodeRole === 'label') {
160162
console.log(`[tabStripItem.insert] LABEL [${parent} > ${child} @${atIndex}] => [${parent.childNodes}]`);
161163
if (child.nativeView instanceof Label === false) {
162-
if (__DEV__) {
164+
if (enableDebugLogging) {
163165
warn(`Unable to add child "${child.nativeView.constructor.name}" to the items of <tabStripItem> as it is not an instance of Label.`);
164166
}
165167
return;
@@ -169,7 +171,7 @@ export function registerTabs(): void {
169171
} else if (child.nodeRole === 'image') {
170172
console.log(`[tabStripItem.insert] IMAGE [${parent} > ${child} @${atIndex}] => [${parent.childNodes}]`);
171173
if (child.nativeView instanceof Image === false) {
172-
if (__DEV__) {
174+
if (enableDebugLogging) {
173175
warn(`Unable to add child "${child.nativeView.constructor.name}" to the items of <tabStripItem> as it is not an instance of Image.`);
174176
}
175177
return;
@@ -178,7 +180,7 @@ export function registerTabs(): void {
178180
tabStripItem.image = child.nativeView as Image;
179181
} else {
180182
console.log(`[tabStripItem.insert] OTHER [${parent} > ${child} @${atIndex}] => [${parent.childNodes}]`);
181-
if (__DEV__) {
183+
if (enableDebugLogging) {
182184
warn(
183185
`Unable to add child "${child.nativeView.constructor.name}" to <tabStripItem> as it does not have a nodeRole specified; ` +
184186
'please set a nodeRole of "label", or "image".'
@@ -196,7 +198,7 @@ export function registerTabs(): void {
196198
// WARNING: It is not evident from the implementation that TabStripItem supports removing image at all!
197199
tabStripItem.image = null;
198200
} else {
199-
if (__DEV__) {
201+
if (enableDebugLogging) {
200202
warn(
201203
`Unable to remove child "${child.nativeView.constructor.name}" from <tabStripItem> as it does not have a nodeRole specified; ` +
202204
'please set a nodeRole of "label", or "image"'
@@ -222,13 +224,13 @@ export function registerTabs(): void {
222224
if (child.nativeView instanceof TabStrip) {
223225
tabs.tabStrip = child.nativeView;
224226
} else {
225-
if (__DEV__) {
227+
if (enableDebugLogging) {
226228
warn(`Unable to add child "${child.nativeView.constructor.name}" as the tabStrip of <tabs> as it is not an instance of TabStrip.`);
227229
}
228230
}
229231
} else if (child.nodeRole === 'items') {
230232
if (child.nativeView instanceof TabContentItem === false) {
231-
if (__DEV__) {
233+
if (enableDebugLogging) {
232234
warn(`Unable to add child "${child.nativeView.constructor.name}" to the items of <tabs> as it is not an instance of TabContentItem.`);
233235
}
234236
return;
@@ -243,11 +245,11 @@ export function registerTabs(): void {
243245
tabs.items = itemsClone;
244246
}
245247
} else if (child.nodeRole === 'item') {
246-
if (__DEV__) {
248+
if (enableDebugLogging) {
247249
warn(`Unable to add child "${child.nativeView.constructor.name}" to <tabs> as it had the nodeRole "item"; please correct it to "items".`);
248250
}
249251
} else {
250-
if (__DEV__) {
252+
if (enableDebugLogging) {
251253
warn(
252254
`Unable to add child "${child.nativeView.constructor.name}" to <tabs> as it does not have a nodeRole specified; ` + 'please set a nodeRole of "tabStrip", or "items".'
253255
);
@@ -262,11 +264,11 @@ export function registerTabs(): void {
262264
} else if (child.nodeRole === 'items') {
263265
tabs.items = (tabs.items || []).filter((i) => i !== child.nativeView);
264266
} else if (child.nodeRole === 'item') {
265-
if (__DEV__) {
267+
if (enableDebugLogging) {
266268
warn(`Unable to remove child "${child.nativeView.constructor.name}" from <tabs> as it had the nodeRole "item"; please correct it to "items".`);
267269
}
268270
} else {
269-
if (__DEV__) {
271+
if (enableDebugLogging) {
270272
warn(
271273
`Unable to remove child "${child.nativeView.constructor.name}" from <tabs> as it does not have a nodeRole specified; ` +
272274
'please set a nodeRole of "tabStrip", or "items"'

0 commit comments

Comments
 (0)