1
- import { registerElement , NSVElement , NativeScriptProps } from " react-nativescript" ;
2
- import { warn } from " react-nativescript/dist/shared/logger" ;
1
+ import { NSVElement , NativeScriptProps , registerElement } from ' react-nativescript' ;
2
+ import { warn } from ' react-nativescript/dist/shared/logger' ;
3
3
import { BottomNavigation , SelectedIndexChangedEventData , TabContentItem , TabStrip } from '../' ;
4
- import { TabNavigationBaseAttributes } from " ../../core/tab-navigation-base/tab-navigation-base/react" ;
4
+ import { TabNavigationBaseAttributes } from ' ../../core/tab-navigation-base/tab-navigation-base/react' ;
5
5
6
6
// Global compile-time constant (for some reason not exported by RNS itself)
7
+ // eslint-disable-next-line no-var
7
8
declare var __DEV__ : boolean ;
8
9
9
10
// ui/bottom-navigation/bottom-navigation.d.ts
10
- export type BottomNavigationAttributes = TabNavigationBaseAttributes & {
11
+ export type BottomNavigationAttributes = TabNavigationBaseAttributes & {
11
12
android ?: any ;
12
13
ios ?: any ;
13
14
items ?: TabContentItem [ ] ;
@@ -17,6 +18,7 @@ export type BottomNavigationAttributes = TabNavigationBaseAttributes & {
17
18
} ;
18
19
19
20
declare global {
21
+ // eslint-disable-next-line @typescript-eslint/prefer-namespace-keyword
20
22
module JSX {
21
23
interface IntrinsicElements {
22
24
bottomNavigation : NativeScriptProps < BottomNavigationAttributes , BottomNavigation > ;
@@ -30,7 +32,7 @@ declare global {
30
32
let installed : boolean = false ;
31
33
32
34
export function registerBottomNavigation ( ) : void {
33
- if ( installed ) {
35
+ if ( installed ) {
34
36
return ;
35
37
}
36
38
registerElement (
@@ -42,72 +44,60 @@ export function registerBottomNavigation(): void {
42
44
nodeOps : {
43
45
insert ( child : NSVElement , parent : NSVElement < BottomNavigation > , atIndex ?: number ) : void {
44
46
const bottomNavigation = parent . nativeView ;
45
-
46
- if ( child . nodeRole === " tabStrip" ) {
47
- if ( child . nativeView instanceof TabStrip ) {
47
+
48
+ if ( child . nodeRole === ' tabStrip' ) {
49
+ if ( child . nativeView instanceof TabStrip ) {
48
50
bottomNavigation . tabStrip = child . nativeView ;
49
51
} else {
50
52
if ( __DEV__ ) {
51
- warn (
52
- `Unable to add child "${ child . nativeView . constructor . name } " as the tabStrip of <bottomNavigation> as it is not an instance of TabStrip.`
53
- ) ;
53
+ warn ( `Unable to add child "${ child . nativeView . constructor . name } " as the tabStrip of <bottomNavigation> as it is not an instance of TabStrip.` ) ;
54
54
}
55
55
}
56
- } else if ( child . nodeRole === " items" ) {
57
- if ( child . nativeView instanceof TabContentItem === false ) {
56
+ } else if ( child . nodeRole === ' items' ) {
57
+ if ( child . nativeView instanceof TabContentItem === false ) {
58
58
if ( __DEV__ ) {
59
- warn (
60
- `Unable to add child "${ child . nativeView . constructor . name } " to the items of <bottomNavigation> as it is not an instance of TabContentItem.`
61
- ) ;
62
- } ;
59
+ warn ( `Unable to add child "${ child . nativeView . constructor . name } " to the items of <bottomNavigation> as it is not an instance of TabContentItem.` ) ;
60
+ }
63
61
return ;
64
62
}
65
-
63
+
66
64
const items = bottomNavigation . items || [ ] ; // Annoyingly, it's the consumer's responsibility to ensure there's an array there!
67
-
68
- if ( typeof atIndex === " undefined" || atIndex === items . length ) {
65
+
66
+ if ( typeof atIndex === ' undefined' || atIndex === items . length ) {
69
67
bottomNavigation . items = items . concat ( child . nativeView as TabContentItem ) ;
70
68
} else {
71
- bottomNavigation . items = items . slice ( ) . splice (
72
- atIndex ,
73
- 0 ,
74
- child . nativeView as TabContentItem
75
- ) ;
69
+ bottomNavigation . items = items . slice ( ) . splice ( atIndex , 0 , child . nativeView as TabContentItem ) ;
76
70
}
77
- } else if ( child . nodeRole === " item" ) {
71
+ } else if ( child . nodeRole === ' item' ) {
78
72
if ( __DEV__ ) {
79
- warn (
80
- `Unable to add child "${ child . nativeView . constructor . name } " to <bottomNavigation> as it had the nodeRole "item"; please correct it to "items".`
81
- ) ;
73
+ warn ( `Unable to add child "${ child . nativeView . constructor . name } " to <bottomNavigation> as it had the nodeRole "item"; please correct it to "items".` ) ;
82
74
}
83
75
} else {
84
76
if ( __DEV__ ) {
85
77
warn (
86
78
`Unable to add child "${ child . nativeView . constructor . name } " to <bottomNavigation> as it does not have a nodeRole specified; ` +
87
- ` please set a nodeRole of "tabStrip", or "items".`
88
- )
79
+ ' please set a nodeRole of "tabStrip", or "items".'
80
+ ) ;
89
81
}
90
82
}
91
83
} ,
92
84
remove ( child : NSVElement , parent : NSVElement < BottomNavigation > ) : void {
93
85
const tabs = parent . nativeView ;
94
-
95
- if ( child . nodeRole === " tabStrip" ) {
86
+
87
+ if ( child . nodeRole === ' tabStrip' ) {
96
88
tabs . tabStrip = null ; // Anything falsy should work.
97
- } else if ( child . nodeRole === " items" ) {
98
- tabs . items = ( tabs . items || [ ] ) . filter ( i => i !== child . nativeView ) ;
99
- } else if ( child . nodeRole === " item" ) {
89
+ } else if ( child . nodeRole === ' items' ) {
90
+ tabs . items = ( tabs . items || [ ] ) . filter ( ( i ) => i !== child . nativeView ) ;
91
+ } else if ( child . nodeRole === ' item' ) {
100
92
if ( __DEV__ ) {
101
- warn (
102
- `Unable to remove child "${ child . nativeView . constructor . name } " from <bottomNavigation> as it had the nodeRole "item"; please correct it to "items".`
103
- ) ;
93
+ warn ( `Unable to remove child "${ child . nativeView . constructor . name } " from <bottomNavigation> as it had the nodeRole "item"; please correct it to "items".` ) ;
104
94
}
105
95
} else {
106
96
if ( __DEV__ ) {
107
97
warn (
108
98
`Unable to remove child "${ child . nativeView . constructor . name } " from <bottomNavigation> as it does not have a nodeRole specified; ` +
109
- ` please set a nodeRole of "tabStrip", or "items"`
110
- )
99
+ ' please set a nodeRole of "tabStrip", or "items"'
100
+ ) ;
111
101
}
112
102
}
113
103
}
0 commit comments