From 7983895c8e77e61854e9300b53c6a0b312e1918e Mon Sep 17 00:00:00 2001 From: Alexander Vakrilov Date: Tue, 1 Aug 2017 11:53:42 +0300 Subject: [PATCH] FIX: Background drawable cache conflicts with local property (#4633) --- tests/app/ui/view/view-tests-common.ts | 11 +++++++++++ tns-core-modules/ui/styling/background.android.ts | 14 +++++++------- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/tests/app/ui/view/view-tests-common.ts b/tests/app/ui/view/view-tests-common.ts index b3090744f..9e67ad9d2 100644 --- a/tests/app/ui/view/view-tests-common.ts +++ b/tests/app/ui/view/view-tests-common.ts @@ -961,6 +961,17 @@ export function testBackgroundImage() { }); }; +export function testBackgroundShorthand_With_EmptyBorder() { + // Related to issue https://github.com/NativeScript/NativeScript/issues/4415 + const lbl = new Label(); + lbl.className = "test"; + const css = ".test { border-width: 0; background: transparent; }"; + + helper.buildUIAndRunTest(lbl, (views: Array) => { + helper.waitUntilLayoutReady(lbl); + }, css); +}; + export function test_automation_text_default_value() { let view = new Button(); TKUnit.assertTrue(view.automationText === undefined, "AutomationText default value should be UNDEFINED."); diff --git a/tns-core-modules/ui/styling/background.android.ts b/tns-core-modules/ui/styling/background.android.ts index 23c3b8cca..486b84f36 100644 --- a/tns-core-modules/ui/styling/background.android.ts +++ b/tns-core-modules/ui/styling/background.android.ts @@ -6,7 +6,7 @@ import { android as androidApp } from "../../application"; export * from "./background-common" interface AndroidView { - background: android.graphics.drawable.Drawable.ConstantState; + _cachedDrawableConstState: android.graphics.drawable.Drawable.ConstantState; } // TODO: Change this implementation to use @@ -41,8 +41,8 @@ export module ad { const drawable = nativeView.getBackground(); const androidView = view as AndroidView; // use undefined as not set. getBackground will never return undefined only Drawable or null; - if (androidView.background === undefined && drawable) { - androidView.background = drawable.getConstantState(); + if (androidView._cachedDrawableConstState === undefined && drawable) { + androidView._cachedDrawableConstState = drawable.getConstantState(); } if (isSetColorFilterOnlyWidget(nativeView) @@ -77,11 +77,11 @@ export module ad { } } } else { - // TODO: newDrawable for BitmapDrawable will fail if we don't speicfy resource. Use the other overload. - const defaultDrawable = androidView.background ? androidView.background.newDrawable(nativeView.getResources()) : null; + // TODO: newDrawable for BitmapDrawable will fail if we don't specify resource. Use the other overload. + const defaultDrawable = androidView._cachedDrawableConstState ? androidView._cachedDrawableConstState.newDrawable(nativeView.getResources()) : null; org.nativescript.widgets.ViewHelper.setBackground(nativeView, defaultDrawable); - androidView.background = undefined; - + androidView._cachedDrawableConstState = undefined; + if (cache.layerType !== undefined) { cache.setLayerType(cache.layerType, null); cache.layerType = undefined;