@@ -5,10 +5,6 @@ import { TabContentItem, TabStrip, TabStripItem, Tabs } from '../tabs';
5
5
import { TabNavigationBaseAttributes } from '@nativescript-community/ui-material-core/tab-navigation-base/tab-navigation-base/react' ;
6
6
import { SelectedIndexChangedEventData } from '@nativescript-community/ui-material-core/tab-navigation-base/tab-navigation-base' ;
7
7
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
-
12
8
// ui/tabs/tabs.d.ts
13
9
export type TabsAttributes = TabNavigationBaseAttributes & {
14
10
android ?: any ;
@@ -75,7 +71,13 @@ declare global {
75
71
}
76
72
let installed : boolean = false ;
77
73
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
+
79
81
if ( installed ) {
80
82
return ;
81
83
}
@@ -91,7 +93,7 @@ export function registerTabs(): void {
91
93
92
94
if ( child . nodeRole === 'items' ) {
93
95
if ( child . nativeView instanceof TabStripItem === false ) {
94
- if ( __DEV__ ) {
96
+ if ( enableDebugLogging ) {
95
97
warn ( `Unable to add child "${ child . nativeView . constructor . name } " to the items of <tabStrip> as it is not an instance of TabStripItem.` ) ;
96
98
}
97
99
return ;
@@ -110,11 +112,11 @@ export function registerTabs(): void {
110
112
tabStrip . items = itemsClone ;
111
113
}
112
114
} else if ( child . nodeRole === 'item' ) {
113
- if ( __DEV__ ) {
115
+ if ( enableDebugLogging ) {
114
116
warn ( `Unable to add child "${ child . nativeView . constructor . name } " to <tabStrip> as it had the nodeRole "item"; please correct it to "items".` ) ;
115
117
}
116
118
} else {
117
- if ( __DEV__ ) {
119
+ if ( enableDebugLogging ) {
118
120
warn (
119
121
`Unable to add child "${ child . nativeView . constructor . name } " to <tabStrip> as it does not have a nodeRole specified; ` +
120
122
'please set a nodeRole of "tabStrip", or "items".'
@@ -128,11 +130,11 @@ export function registerTabs(): void {
128
130
if ( child . nodeRole === 'items' ) {
129
131
tabStrip . items = ( tabStrip . items || [ ] ) . filter ( ( i ) => i !== child . nativeView ) ;
130
132
} else if ( child . nodeRole === 'item' ) {
131
- if ( __DEV__ ) {
133
+ if ( enableDebugLogging ) {
132
134
warn ( `Unable to remove child "${ child . nativeView . constructor . name } " from <tabStrip> as it had the nodeRole "item"; please correct it to "items".` ) ;
133
135
}
134
136
} else {
135
- if ( __DEV__ ) {
137
+ if ( enableDebugLogging ) {
136
138
warn (
137
139
`Unable to remove child "${ child . nativeView . constructor . name } " from <tabStrip> as it does not have a nodeRole specified; ` +
138
140
'please set a nodeRole of "tabStrip", or "items"'
@@ -159,7 +161,7 @@ export function registerTabs(): void {
159
161
if ( child . nodeRole === 'label' ) {
160
162
console . log ( `[tabStripItem.insert] LABEL [${ parent } > ${ child } @${ atIndex } ] => [${ parent . childNodes } ]` ) ;
161
163
if ( child . nativeView instanceof Label === false ) {
162
- if ( __DEV__ ) {
164
+ if ( enableDebugLogging ) {
163
165
warn ( `Unable to add child "${ child . nativeView . constructor . name } " to the items of <tabStripItem> as it is not an instance of Label.` ) ;
164
166
}
165
167
return ;
@@ -169,7 +171,7 @@ export function registerTabs(): void {
169
171
} else if ( child . nodeRole === 'image' ) {
170
172
console . log ( `[tabStripItem.insert] IMAGE [${ parent } > ${ child } @${ atIndex } ] => [${ parent . childNodes } ]` ) ;
171
173
if ( child . nativeView instanceof Image === false ) {
172
- if ( __DEV__ ) {
174
+ if ( enableDebugLogging ) {
173
175
warn ( `Unable to add child "${ child . nativeView . constructor . name } " to the items of <tabStripItem> as it is not an instance of Image.` ) ;
174
176
}
175
177
return ;
@@ -178,7 +180,7 @@ export function registerTabs(): void {
178
180
tabStripItem . image = child . nativeView as Image ;
179
181
} else {
180
182
console . log ( `[tabStripItem.insert] OTHER [${ parent } > ${ child } @${ atIndex } ] => [${ parent . childNodes } ]` ) ;
181
- if ( __DEV__ ) {
183
+ if ( enableDebugLogging ) {
182
184
warn (
183
185
`Unable to add child "${ child . nativeView . constructor . name } " to <tabStripItem> as it does not have a nodeRole specified; ` +
184
186
'please set a nodeRole of "label", or "image".'
@@ -196,7 +198,7 @@ export function registerTabs(): void {
196
198
// WARNING: It is not evident from the implementation that TabStripItem supports removing image at all!
197
199
tabStripItem . image = null ;
198
200
} else {
199
- if ( __DEV__ ) {
201
+ if ( enableDebugLogging ) {
200
202
warn (
201
203
`Unable to remove child "${ child . nativeView . constructor . name } " from <tabStripItem> as it does not have a nodeRole specified; ` +
202
204
'please set a nodeRole of "label", or "image"'
@@ -222,13 +224,13 @@ export function registerTabs(): void {
222
224
if ( child . nativeView instanceof TabStrip ) {
223
225
tabs . tabStrip = child . nativeView ;
224
226
} else {
225
- if ( __DEV__ ) {
227
+ if ( enableDebugLogging ) {
226
228
warn ( `Unable to add child "${ child . nativeView . constructor . name } " as the tabStrip of <tabs> as it is not an instance of TabStrip.` ) ;
227
229
}
228
230
}
229
231
} else if ( child . nodeRole === 'items' ) {
230
232
if ( child . nativeView instanceof TabContentItem === false ) {
231
- if ( __DEV__ ) {
233
+ if ( enableDebugLogging ) {
232
234
warn ( `Unable to add child "${ child . nativeView . constructor . name } " to the items of <tabs> as it is not an instance of TabContentItem.` ) ;
233
235
}
234
236
return ;
@@ -243,11 +245,11 @@ export function registerTabs(): void {
243
245
tabs . items = itemsClone ;
244
246
}
245
247
} else if ( child . nodeRole === 'item' ) {
246
- if ( __DEV__ ) {
248
+ if ( enableDebugLogging ) {
247
249
warn ( `Unable to add child "${ child . nativeView . constructor . name } " to <tabs> as it had the nodeRole "item"; please correct it to "items".` ) ;
248
250
}
249
251
} else {
250
- if ( __DEV__ ) {
252
+ if ( enableDebugLogging ) {
251
253
warn (
252
254
`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".'
253
255
) ;
@@ -262,11 +264,11 @@ export function registerTabs(): void {
262
264
} else if ( child . nodeRole === 'items' ) {
263
265
tabs . items = ( tabs . items || [ ] ) . filter ( ( i ) => i !== child . nativeView ) ;
264
266
} else if ( child . nodeRole === 'item' ) {
265
- if ( __DEV__ ) {
267
+ if ( enableDebugLogging ) {
266
268
warn ( `Unable to remove child "${ child . nativeView . constructor . name } " from <tabs> as it had the nodeRole "item"; please correct it to "items".` ) ;
267
269
}
268
270
} else {
269
- if ( __DEV__ ) {
271
+ if ( enableDebugLogging ) {
270
272
warn (
271
273
`Unable to remove child "${ child . nativeView . constructor . name } " from <tabs> as it does not have a nodeRole specified; ` +
272
274
'please set a nodeRole of "tabStrip", or "items"'
0 commit comments