1
1
/**
2
2
* @module @nativescript -community/ui-material-core/tab-navigation-base/tab-strip-item
3
- */
4
- import { AddChildFromBuilder , CSSType , Color , Image , Label , PropertyChangeData , PseudoClassHandler , View , ViewBase , Enums } from '@nativescript/core' ;
3
+ */
4
+ import { AddChildFromBuilder , CSSType , Color , Enums , Image , Label , PropertyChangeData , PseudoClassHandler , View , ViewBase } from '@nativescript/core' ;
5
5
import { backgroundColorProperty , backgroundInternalProperty } from '@nativescript/core/ui/styling/style-properties' ;
6
6
import { textTransformProperty } from '@nativescript/core/ui/text-base' ;
7
7
import { TabStripItem as TabStripItemDefinition } from '.' ;
8
8
import { TabNavigationBase } from '../tab-navigation-base' ;
9
9
import { TabStrip } from '../tab-strip' ;
10
10
11
-
12
11
@CSSType ( 'MDTabStripItem' )
13
12
export class TabStripItem extends View implements TabStripItemDefinition , AddChildFromBuilder {
14
13
public static tapEvent = 'tap' ;
@@ -102,73 +101,73 @@ export class TabStripItem extends View implements TabStripItemDefinition, AddChi
102
101
super . onLoaded ( ) ;
103
102
104
103
this . _labelColorHandler =
105
- this . _labelColorHandler ||
106
- ( ( args : PropertyChangeData ) => {
107
- const parent = this . parent as TabStrip ;
108
- const tabStripParent = parent && parent . parent as TabNavigationBase ;
104
+ this . _labelColorHandler ||
105
+ ( ( args : PropertyChangeData ) => {
106
+ const parent = this . parent as TabStrip ;
107
+ const tabStripParent = parent && ( parent . parent as TabNavigationBase ) ;
109
108
110
- return tabStripParent && tabStripParent . setTabBarItemColor ( this , args . value ) ;
111
- } ) ;
109
+ return tabStripParent && tabStripParent . setTabBarItemColor ( this , args . value ) ;
110
+ } ) ;
112
111
this . label . style . on ( 'colorChange' , this . _labelColorHandler ) ;
113
112
114
113
this . _labelFontHandler =
115
- this . _labelFontHandler ||
116
- ( ( args : PropertyChangeData ) => {
117
- const parent = this . parent as TabStrip ;
118
- const tabStripParent = parent && parent . parent as TabNavigationBase ;
114
+ this . _labelFontHandler ||
115
+ ( ( args : PropertyChangeData ) => {
116
+ const parent = this . parent as TabStrip ;
117
+ const tabStripParent = parent && ( parent . parent as TabNavigationBase ) ;
119
118
120
- return tabStripParent && tabStripParent . setTabBarItemFontInternal ( this , args . value ) ;
121
- } ) ;
119
+ return tabStripParent && tabStripParent . setTabBarItemFontInternal ( this , args . value ) ;
120
+ } ) ;
122
121
this . label . style . on ( 'fontInternalChange' , this . _labelFontHandler ) ;
123
122
124
123
this . _labelTextTransformHandler =
125
- this . _labelTextTransformHandler ||
126
- ( ( args : PropertyChangeData ) => {
127
- const parent = this . parent as TabStrip ;
128
- const tabStripParent = parent && parent . parent as TabNavigationBase ;
124
+ this . _labelTextTransformHandler ||
125
+ ( ( args : PropertyChangeData ) => {
126
+ const parent = this . parent as TabStrip ;
127
+ const tabStripParent = parent && ( parent . parent as TabNavigationBase ) ;
129
128
130
- return tabStripParent && tabStripParent . setTabBarItemTextTransform ( this , args . value ) ;
131
- } ) ;
129
+ return tabStripParent && tabStripParent . setTabBarItemTextTransform ( this , args . value ) ;
130
+ } ) ;
132
131
this . label . style . on ( 'textTransformChange' , this . _labelTextTransformHandler ) ;
133
132
134
133
this . _labelTextHandler =
135
- this . _labelTextHandler ||
136
- ( ( args : PropertyChangeData ) => {
137
- const parent = this . parent as TabStrip ;
138
- const tabStripParent = parent && parent . parent as TabNavigationBase ;
134
+ this . _labelTextHandler ||
135
+ ( ( args : PropertyChangeData ) => {
136
+ const parent = this . parent as TabStrip ;
137
+ const tabStripParent = parent && ( parent . parent as TabNavigationBase ) ;
139
138
140
- return tabStripParent && tabStripParent . setTabBarItemTitle ( this , args . value ) ;
141
- } ) ;
139
+ return tabStripParent && tabStripParent . setTabBarItemTitle ( this , args . value ) ;
140
+ } ) ;
142
141
this . label . on ( 'textChange' , this . _labelTextHandler ) ;
143
142
144
143
this . _imageColorHandler =
145
- this . _imageColorHandler ||
146
- ( ( args : PropertyChangeData ) => {
147
- const parent = this . parent as TabStrip ;
148
- const tabStripParent = parent && parent . parent as TabNavigationBase ;
144
+ this . _imageColorHandler ||
145
+ ( ( args : PropertyChangeData ) => {
146
+ const parent = this . parent as TabStrip ;
147
+ const tabStripParent = parent && ( parent . parent as TabNavigationBase ) ;
149
148
150
- return tabStripParent && tabStripParent . setTabBarIconColor ( this , args . value ) ;
151
- } ) ;
149
+ return tabStripParent && tabStripParent . setTabBarIconColor ( this , args . value ) ;
150
+ } ) ;
152
151
this . image . style . on ( 'colorChange' , this . _imageColorHandler ) ;
153
152
154
153
this . _imageFontHandler =
155
- this . _imageFontHandler ||
156
- ( ( args : PropertyChangeData ) => {
157
- const parent = this . parent as TabStrip ;
158
- const tabStripParent = parent && parent . parent as TabNavigationBase ;
154
+ this . _imageFontHandler ||
155
+ ( ( args : PropertyChangeData ) => {
156
+ const parent = this . parent as TabStrip ;
157
+ const tabStripParent = parent && ( parent . parent as TabNavigationBase ) ;
159
158
160
- return tabStripParent && tabStripParent . setTabBarIconColor ( this , args . value ) ;
161
- } ) ;
159
+ return tabStripParent && tabStripParent . setTabBarIconColor ( this , args . value ) ;
160
+ } ) ;
162
161
this . image . style . on ( 'fontInternalChange' , this . _imageFontHandler ) ;
163
162
164
163
this . _imageSrcHandler =
165
- this . _imageSrcHandler ||
166
- ( ( args : PropertyChangeData ) => {
167
- const parent = this . parent as TabStrip ;
168
- const tabStripParent = parent && parent . parent as TabNavigationBase ;
164
+ this . _imageSrcHandler ||
165
+ ( ( args : PropertyChangeData ) => {
166
+ const parent = this . parent as TabStrip ;
167
+ const tabStripParent = parent && ( parent . parent as TabNavigationBase ) ;
169
168
170
- return tabStripParent && tabStripParent . setTabBarIconSource ( this , args . value ) ;
171
- } ) ;
169
+ return tabStripParent && tabStripParent . setTabBarIconSource ( this , args . value ) ;
170
+ } ) ;
172
171
this . image . on ( 'srcChange' , this . _imageSrcHandler ) ;
173
172
}
174
173
@@ -198,15 +197,15 @@ export class TabStripItem extends View implements TabStripItemDefinition, AddChi
198
197
public _addChildFromBuilder ( name : string , value : any ) : void {
199
198
if ( value instanceof Image ) {
200
199
this . image = value ;
201
- this . iconSource = ( value ) . src ;
202
- this . iconClass = ( value ) . className ;
200
+ this . iconSource = value . src ;
201
+ this . iconClass = value . className ;
203
202
this . _addView ( value ) ;
204
203
// selectedIndexProperty.coerce(this);
205
204
}
206
205
207
206
if ( value instanceof Label ) {
208
207
this . label = value ;
209
- this . title = ( value ) . text ;
208
+ this . title = value . text ;
210
209
this . _addView ( value ) ;
211
210
// selectedIndexProperty.coerce(this);
212
211
}
@@ -224,22 +223,22 @@ export class TabStripItem extends View implements TabStripItemDefinition, AddChi
224
223
_updateTabStateChangeHandler ( subscribe : boolean ) {
225
224
if ( subscribe ) {
226
225
this . _highlightedHandler =
227
- this . _highlightedHandler ||
228
- ( ( ) => {
229
- this . _goToVisualState ( 'highlighted' ) ;
230
- } ) ;
226
+ this . _highlightedHandler ||
227
+ ( ( ) => {
228
+ this . _goToVisualState ( 'highlighted' ) ;
229
+ } ) ;
231
230
232
231
this . _normalHandler =
233
- this . _normalHandler ||
234
- ( ( ) => {
235
- this . _goToVisualState ( 'normal' ) ;
236
- } ) ;
232
+ this . _normalHandler ||
233
+ ( ( ) => {
234
+ this . _goToVisualState ( 'normal' ) ;
235
+ } ) ;
237
236
238
237
this . on ( TabStripItem . selectEvent , this . _highlightedHandler ) ;
239
238
this . on ( TabStripItem . unselectEvent , this . _normalHandler ) ;
240
239
241
240
const parent = this . parent as TabStrip ;
242
- const tabStripParent = parent && parent . parent as TabNavigationBase ;
241
+ const tabStripParent = parent && ( parent . parent as TabNavigationBase ) ;
243
242
if ( this . _index === tabStripParent . selectedIndex && ! ( global . isIOS && tabStripParent . cssType . toLowerCase ( ) === 'tabs' ) ) {
244
243
// HACK: tabStripParent instanceof Tabs creates a circular dependency
245
244
// HACK: tabStripParent.cssType === "Tabs" is a hacky workaround
@@ -253,26 +252,26 @@ export class TabStripItem extends View implements TabStripItemDefinition, AddChi
253
252
254
253
[ backgroundColorProperty . getDefault ] ( ) : Color {
255
254
const parent = this . parent as TabStrip ;
256
- const tabStripParent = parent && parent . parent as TabNavigationBase ;
255
+ const tabStripParent = parent && ( parent . parent as TabNavigationBase ) ;
257
256
258
257
return tabStripParent && tabStripParent . getTabBarBackgroundColor ( ) ;
259
258
}
260
259
[ backgroundColorProperty . setNative ] ( value : Color ) {
261
260
const parent = this . parent as TabStrip ;
262
- const tabStripParent = parent && parent . parent as TabNavigationBase ;
261
+ const tabStripParent = parent && ( parent . parent as TabNavigationBase ) ;
263
262
264
263
return tabStripParent && tabStripParent . setTabBarItemBackgroundColor ( this , value ) ;
265
264
}
266
265
267
266
[ textTransformProperty . getDefault ] ( ) : Enums . TextTransformType {
268
267
const parent = this . parent as TabStrip ;
269
- const tabStripParent = parent && parent . parent as TabNavigationBase ;
268
+ const tabStripParent = parent && ( parent . parent as TabNavigationBase ) ;
270
269
271
270
return tabStripParent && tabStripParent . getTabBarItemTextTransform ( this ) ;
272
271
}
273
272
[ textTransformProperty . setNative ] ( value : Enums . TextTransformType ) {
274
273
const parent = this . parent as TabStrip ;
275
- const tabStripParent = parent && parent . parent as TabNavigationBase ;
274
+ const tabStripParent = parent && ( parent . parent as TabNavigationBase ) ;
276
275
277
276
return tabStripParent && tabStripParent . setTabBarItemTextTransform ( this , value ) ;
278
277
}
0 commit comments