@@ -6,9 +6,8 @@ import { parse } from '../../css-value';
66import { path , knownFolders } from '../../file-system' ;
77import * as application from '../../application' ;
88import { profile } from '../../profiling' ;
9- import { Color } from '../../color' ;
10- import { Screen } from '../../platform' ;
119import { CSSShadow } from './css-shadow' ;
10+ import { Length , LengthType } from './style-properties' ;
1211export * from './background-common' ;
1312
1413interface AndroidView {
@@ -28,8 +27,12 @@ export namespace ad {
2827 }
2928
3029 function isSetColorFilterOnlyWidget ( nativeView : android . view . View ) : boolean {
30+ // prettier-ignore
3131 return (
32- nativeView instanceof android . widget . Button || ( nativeView instanceof androidx . appcompat . widget . Toolbar && getSDK ( ) >= 21 ) // There is an issue with the DrawableContainer which was fixed for API version 21 and above: https://code.google.com/p/android/issues/detail?id=60183
32+ nativeView instanceof android . widget . Button
33+ || ( nativeView instanceof androidx . appcompat . widget . Toolbar && getSDK ( ) >= 21 )
34+ // There is an issue with the DrawableContainer which was fixed
35+ // for API version 21 and above: https://code.google.com/p/android/issues/detail?id=60183
3336 ) ;
3437 }
3538
@@ -48,7 +51,15 @@ export namespace ad {
4851 androidView . _cachedDrawable = constantState || drawable ;
4952 }
5053 const isBorderDrawable = drawable instanceof org . nativescript . widgets . BorderDrawable ;
51- const onlyColor = ! background . hasBorderWidth ( ) && ! background . hasBorderRadius ( ) && ! background . clipPath && ! background . image && ! ! background . color ;
54+
55+ // prettier-ignore
56+ const onlyColor = ! background . hasBorderWidth ( )
57+ && ! background . hasBorderRadius ( )
58+ && ! background . hasBoxShadow ( )
59+ && ! background . clipPath
60+ && ! background . image
61+ && ! ! background . color ;
62+
5263 if ( ! isBorderDrawable && drawable instanceof android . graphics . drawable . ColorDrawable && onlyColor ) {
5364 drawable . setColor ( background . color . android ) ;
5465 drawable . invalidateSelf ( ) ;
@@ -71,13 +82,19 @@ export namespace ad {
7182 // this is the fastest way to change only background color
7283 nativeView . setBackgroundColor ( background . color . android ) ;
7384 } else if ( ! background . isEmpty ( ) ) {
74- let backgroundDrawable = drawable as org . nativescript . widgets . BorderDrawable ;
75- if ( ! isBorderDrawable ) {
76- backgroundDrawable = new org . nativescript . widgets . BorderDrawable ( layout . getDisplayDensity ( ) , view . toString ( ) ) ;
85+ let backgroundDrawable = drawable ;
86+
87+ if ( drawable instanceof org . nativescript . widgets . BoxShadowDrawable ) {
88+ // if we have BoxShadow's we have to get the underlying drawable
89+ backgroundDrawable = drawable . getWrappedDrawable ( ) ;
90+ }
91+
92+ if ( backgroundDrawable instanceof org . nativescript . widgets . BorderDrawable ) {
7793 refreshBorderDrawable ( view , backgroundDrawable ) ;
78- nativeView . setBackground ( backgroundDrawable ) ;
7994 } else {
95+ backgroundDrawable = new org . nativescript . widgets . BorderDrawable ( layout . getDisplayDensity ( ) , view . toString ( ) ) ;
8096 refreshBorderDrawable ( view , backgroundDrawable ) ;
97+ nativeView . setBackground ( backgroundDrawable ) ;
8198 }
8299 } else {
83100 const cachedDrawable = androidView . _cachedDrawable ;
@@ -228,24 +245,19 @@ function createNativeCSSValueArray(css: string): androidNative.Array<org.natives
228245}
229246
230247function drawBoxShadow ( nativeView : android . view . View , view : View , boxShadow : CSSShadow ) {
231- const color = boxShadow . color ;
232- const shadowOpacity = color . a ;
233- const shadowColor = new Color ( shadowOpacity , color . r , color . g , color . b ) ;
234- const cornerRadius = view . borderRadius ; // this should be applied to the main view as well (try 20 with a transparent background on the xml to see the effect)
235248 const config = {
236- shadowColor : shadowColor . android ,
237- cornerRadius : cornerRadius ,
238- spreadRadius : boxShadow . spreadRadius ,
239- blurRadius : boxShadow . blurRadius ,
240- offsetX : boxShadow . offsetX ,
241- offsetY : boxShadow . offsetY ,
242- scale : Screen . mainScreen . scale ,
249+ shadowColor : boxShadow . color . android ,
250+ cornerRadius : Length . toDevicePixels ( view . borderRadius as LengthType , 0.0 ) ,
251+ spreadRadius : Length . toDevicePixels ( boxShadow . spreadRadius , 0.0 ) ,
252+ blurRadius : Length . toDevicePixels ( boxShadow . blurRadius , 0.0 ) ,
253+ offsetX : Length . toDevicePixels ( boxShadow . offsetX , 0.0 ) ,
254+ offsetY : Length . toDevicePixels ( boxShadow . offsetY , 0.0 ) ,
243255 } ;
244256 org . nativescript . widgets . Utils . drawBoxShadow ( nativeView , JSON . stringify ( config ) ) ;
245257}
246258
247259function clearBoxShadow ( nativeView : android . view . View ) {
248- // org.nativescript.widgets.Utils.clearBoxShadow(nativeView);
260+ org . nativescript . widgets . Utils . clearBoxShadow ( nativeView ) ;
249261}
250262
251263export enum CacheMode {
@@ -279,13 +291,13 @@ export function initImageCache(context: android.content.Context, mode = CacheMod
279291 imageFetcher . initCache ( ) ;
280292}
281293
282- function onLivesync ( args ) : void {
294+ function onLiveSync ( args ) : void {
283295 if ( imageFetcher ) {
284296 imageFetcher . clearCache ( ) ;
285297 }
286298}
287299
288- global . NativeScriptGlobals . events . on ( 'livesync' , onLivesync ) ;
300+ global . NativeScriptGlobals . events . on ( 'livesync' , onLiveSync ) ;
289301
290302global . NativeScriptGlobals . addEventWiring ( ( ) => {
291303 application . android . on ( 'activityStarted' , ( args ) => {
0 commit comments