@@ -176,128 +176,127 @@ export function getRippleColor(color: string | Color) {
176
176
return null ;
177
177
}
178
178
179
- class ViewWithElevationAndRipple extends View {
180
- @cssProperty elevation = 0 ;
181
- @cssProperty dynamicElevationOffset = 0 ;
182
- @cssProperty rippleColor : Color ;
183
- rippleDrawable : android . graphics . drawable . Drawable ;
184
- getRippleColor ( ) {
185
- if ( this . rippleColor ) {
186
- return getRippleColor ( this . rippleColor ) ;
179
+ let mixinInstalled = false ;
180
+ export function overrideViewBase ( ) {
181
+ const NSView = require ( '@nativescript/core' ) . View ;
182
+ class ViewWithElevationAndRipple extends View {
183
+ @cssProperty elevation = 0 ;
184
+ @cssProperty dynamicElevationOffset = 0 ;
185
+ @cssProperty rippleColor : Color ;
186
+ rippleDrawable : android . graphics . drawable . Drawable ;
187
+ getRippleColor ( ) {
188
+ if ( this . rippleColor ) {
189
+ return getRippleColor ( this . rippleColor ) ;
190
+ }
191
+ return getRippleColor ( themer . getAccentColor ( ) ) ;
187
192
}
188
- return getRippleColor ( themer . getAccentColor ( ) ) ;
189
- }
190
193
191
- setRippleDrawable ( view : android . view . View , radius = 0 ) {
192
- if ( ! this . rippleDrawable ) {
193
- this . rippleDrawable = createRippleDrawable ( this . getRippleColor ( ) , radius ) ;
194
- if ( isPostMarshmallow ( ) ) {
195
- view . setForeground ( this . rippleDrawable ) ;
194
+ setRippleDrawable ( view : android . view . View , radius = 0 ) {
195
+ if ( ! this . rippleDrawable ) {
196
+ this . rippleDrawable = createRippleDrawable ( this . getRippleColor ( ) , radius ) ;
197
+ if ( isPostMarshmallow ( ) ) {
198
+ view . setForeground ( this . rippleDrawable ) ;
199
+ }
196
200
}
197
201
}
198
- }
199
- [ rippleColorProperty . setNative ] ( color : Color ) {
200
- const rippleColor = getRippleColor ( color ) ;
201
- const nativeViewProtected = this . nativeViewProtected ;
202
- if ( this instanceof Button && isPostMarshmallow ( ) ) {
203
- const foreground = ( nativeViewProtected as android . widget . Button ) . getForeground ( ) ;
204
- if ( foreground instanceof android . graphics . drawable . RippleDrawable ) {
205
- foreground . setColor ( getColorStateList ( rippleColor ) ) ;
206
- return ;
207
- }
208
- const background = ( nativeViewProtected as android . widget . Button ) . getBackground ( ) ;
209
- if ( background instanceof android . graphics . drawable . RippleDrawable ) {
210
- background . setColor ( getColorStateList ( rippleColor ) ) ;
211
- return ;
202
+ [ rippleColorProperty . setNative ] ( color : Color ) {
203
+ const rippleColor = getRippleColor ( color ) ;
204
+ const nativeViewProtected = this . nativeViewProtected ;
205
+ if ( this instanceof Button && isPostMarshmallow ( ) ) {
206
+ const foreground = ( nativeViewProtected as android . widget . Button ) . getForeground ( ) ;
207
+ if ( foreground instanceof android . graphics . drawable . RippleDrawable ) {
208
+ foreground . setColor ( getColorStateList ( rippleColor ) ) ;
209
+ return ;
210
+ }
211
+ const background = ( nativeViewProtected as android . widget . Button ) . getBackground ( ) ;
212
+ if ( background instanceof android . graphics . drawable . RippleDrawable ) {
213
+ background . setColor ( getColorStateList ( rippleColor ) ) ;
214
+ return ;
215
+ }
212
216
}
213
- }
214
- nativeViewProtected . setClickable ( this . isUserInteractionEnabled ) ;
215
- const rippleDrawable = this . rippleDrawable ;
216
- if ( ! rippleDrawable ) {
217
- this . setRippleDrawable ( nativeViewProtected , Length . toDevicePixels ( this . style . borderTopLeftRadius ) ) ;
218
- } else {
219
- if ( isPostLollipop ( ) ) {
220
- ( rippleDrawable as android . graphics . drawable . RippleDrawable ) . setColor ( getColorStateList ( rippleColor ) ) ;
221
- } else if ( ( rippleDrawable as any ) . rippleShape ) {
222
- ( rippleDrawable as any ) . rippleShape . getPaint ( ) . setColor ( rippleColor ) ;
217
+ nativeViewProtected . setClickable ( this . isUserInteractionEnabled ) ;
218
+ const rippleDrawable = this . rippleDrawable ;
219
+ if ( ! rippleDrawable ) {
220
+ this . setRippleDrawable ( nativeViewProtected , Length . toDevicePixels ( this . style . borderTopLeftRadius ) ) ;
221
+ } else {
222
+ if ( isPostLollipop ( ) ) {
223
+ ( rippleDrawable as android . graphics . drawable . RippleDrawable ) . setColor ( getColorStateList ( rippleColor ) ) ;
224
+ } else if ( ( rippleDrawable as any ) . rippleShape ) {
225
+ ( rippleDrawable as any ) . rippleShape . getPaint ( ) . setColor ( rippleColor ) ;
226
+ }
223
227
}
224
228
}
225
- }
226
229
227
- [ backgroundInternalProperty . setNative ] ( value : android . graphics . drawable . Drawable | Background ) {
228
- if ( this . nativeViewProtected ) {
229
- if ( value instanceof android . graphics . drawable . Drawable ) {
230
- } else {
231
- // we recreate the ripple drawable if necessary.
232
- // native button have on the background. Setting color will remove the ripple!
233
- if ( this . rippleDrawable || ( value . color && this instanceof Button && this . rippleColor ) ) {
234
- this . rippleDrawable = null ;
235
- this . setRippleDrawable ( this . nativeViewProtected , value . borderTopLeftRadius ) ;
230
+ [ backgroundInternalProperty . setNative ] ( value : android . graphics . drawable . Drawable | Background ) {
231
+ if ( this . nativeViewProtected ) {
232
+ if ( value instanceof android . graphics . drawable . Drawable ) {
233
+ } else {
234
+ // we recreate the ripple drawable if necessary.
235
+ // native button have on the background. Setting color will remove the ripple!
236
+ if ( this . rippleDrawable || ( value . color && this instanceof Button && this . rippleColor ) ) {
237
+ this . rippleDrawable = null ;
238
+ this . setRippleDrawable ( this . nativeViewProtected , value . borderTopLeftRadius ) ;
239
+ }
236
240
}
237
241
}
238
242
}
239
- }
240
- public requestFocus ( ) {
241
- this . focus ( ) ;
242
- }
243
- public clearFocus ( ) {
244
- handleClearFocus ( this . nativeViewProtected ) ;
245
- ad . dismissSoftInput ( this . nativeViewProtected ) ;
246
- }
243
+ public requestFocus ( ) {
244
+ this . focus ( ) ;
245
+ }
246
+ public clearFocus ( ) {
247
+ handleClearFocus ( this . nativeViewProtected ) ;
248
+ ad . dismissSoftInput ( this . nativeViewProtected ) ;
249
+ }
247
250
248
- getDefaultElevation ( ) : number {
249
- const result = this instanceof Button ? 2 : 0 ;
250
- return result ;
251
- }
251
+ getDefaultElevation ( ) : number {
252
+ const result = this instanceof Button ? 2 : 0 ;
253
+ return result ;
254
+ }
252
255
253
- getDefaultDynamicElevationOffset ( ) {
254
- const result = this instanceof Button ? 6 : 0 ;
255
- return result ;
256
- }
256
+ getDefaultDynamicElevationOffset ( ) {
257
+ const result = this instanceof Button ? 6 : 0 ;
258
+ return result ;
259
+ }
257
260
258
- [ elevationProperty . setNative ] ( value : number ) {
259
- if ( isPostLollipop ( ) ) {
260
- this . createStateListAnimator ( ) ;
261
- } else {
262
- const newValue = Length . toDevicePixels ( typeof value === 'string' ? Length . parse ( value ) : value , 0 ) ;
263
- androidx . core . view . ViewCompat . setElevation ( this . nativeViewProtected , newValue ) ;
261
+ [ elevationProperty . setNative ] ( value : number ) {
262
+ if ( isPostLollipop ( ) ) {
263
+ this . createStateListAnimator ( ) ;
264
+ } else {
265
+ const newValue = Length . toDevicePixels ( typeof value === 'string' ? Length . parse ( value ) : value , 0 ) ;
266
+ androidx . core . view . ViewCompat . setElevation ( this . nativeViewProtected , newValue ) ;
267
+ }
264
268
}
265
- }
266
269
267
- createStateListAnimatorTimeout ;
268
- createStateListAnimator ( ) {
269
- if ( ! this . createStateListAnimatorTimeout ) {
270
- this . createStateListAnimatorTimeout = setTimeout ( ( ) => {
271
- this . createStateListAnimatorTimeout = null ;
272
- createStateListAnimator ( this , this . nativeViewProtected ) ;
273
- } ) ;
270
+ createStateListAnimatorTimeout ;
271
+ createStateListAnimator ( ) {
272
+ if ( ! this . createStateListAnimatorTimeout ) {
273
+ this . createStateListAnimatorTimeout = setTimeout ( ( ) => {
274
+ this . createStateListAnimatorTimeout = null ;
275
+ createStateListAnimator ( this , this . nativeViewProtected ) ;
276
+ } ) ;
277
+ }
274
278
}
275
- }
276
- [ dynamicElevationOffsetProperty . setNative ] ( value : number ) {
277
- this . nativeViewProtected . setClickable ( this . isUserInteractionEnabled ) ;
278
- if ( isPostLollipop ( ) ) {
279
- this . createStateListAnimator ( ) ;
280
- } else {
281
- const newValue = Length . toDevicePixels ( typeof value === 'string' ? Length . parse ( value ) : value , 0 ) ;
282
- androidx . core . view . ViewCompat . setTranslationZ ( this . nativeViewProtected , newValue ) ;
279
+ [ dynamicElevationOffsetProperty . setNative ] ( value : number ) {
280
+ this . nativeViewProtected . setClickable ( this . isUserInteractionEnabled ) ;
281
+ if ( isPostLollipop ( ) ) {
282
+ this . createStateListAnimator ( ) ;
283
+ } else {
284
+ const newValue = Length . toDevicePixels ( typeof value === 'string' ? Length . parse ( value ) : value , 0 ) ;
285
+ androidx . core . view . ViewCompat . setTranslationZ ( this . nativeViewProtected , newValue ) ;
286
+ }
283
287
}
284
288
}
285
- }
286
- class ViewOverride extends View {
287
- [ androidElevationProperty . setNative ] ( value : number ) {
288
- // override to prevent override of dynamicElevationOffset
289
- this [ elevationProperty . setNative ] ( value ) ;
290
- }
291
- [ androidDynamicElevationOffsetProperty . setNative ] ( value : number ) {
292
- // override to prevent override of elevation
293
- this [ dynamicElevationOffsetProperty . setNative ] ( value ) ;
294
- }
295
- }
296
-
297
- let mixinInstalled = false ;
298
- export function overrideViewBase ( ) {
299
- const NSView = require ( '@nativescript/core' ) . View ;
300
289
applyMixins ( NSView , [ ViewWithElevationAndRipple ] ) ;
290
+ class ViewOverride extends View {
291
+ [ androidElevationProperty . setNative ] ( value : number ) {
292
+ // override to prevent override of dynamicElevationOffset
293
+ this [ elevationProperty . setNative ] ( value ) ;
294
+ }
295
+ [ androidDynamicElevationOffsetProperty . setNative ] ( value : number ) {
296
+ // override to prevent override of elevation
297
+ this [ dynamicElevationOffsetProperty . setNative ] ( value ) ;
298
+ }
299
+ }
301
300
applyMixins ( NSView , [ ViewOverride ] , { override : true } ) ;
302
301
}
303
302
0 commit comments