Skip to content

Commit 7983895

Browse files
Alexander VakrilovSvetoslavTsenov
authored andcommitted
FIX: Background drawable cache conflicts with local property (#4633)
1 parent 2dbd1b1 commit 7983895

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

tests/app/ui/view/view-tests-common.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -961,6 +961,17 @@ export function testBackgroundImage() {
961961
});
962962
};
963963

964+
export function testBackgroundShorthand_With_EmptyBorder() {
965+
// Related to issue https://github.com/NativeScript/NativeScript/issues/4415
966+
const lbl = new Label();
967+
lbl.className = "test";
968+
const css = ".test { border-width: 0; background: transparent; }";
969+
970+
helper.buildUIAndRunTest(lbl, (views: Array<View>) => {
971+
helper.waitUntilLayoutReady(lbl);
972+
}, css);
973+
};
974+
964975
export function test_automation_text_default_value() {
965976
let view = new Button();
966977
TKUnit.assertTrue(view.automationText === undefined, "AutomationText default value should be UNDEFINED.");

tns-core-modules/ui/styling/background.android.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { android as androidApp } from "../../application";
66
export * from "./background-common"
77

88
interface AndroidView {
9-
background: android.graphics.drawable.Drawable.ConstantState;
9+
_cachedDrawableConstState: android.graphics.drawable.Drawable.ConstantState;
1010
}
1111

1212
// TODO: Change this implementation to use
@@ -41,8 +41,8 @@ export module ad {
4141
const drawable = nativeView.getBackground();
4242
const androidView = <any>view as AndroidView;
4343
// use undefined as not set. getBackground will never return undefined only Drawable or null;
44-
if (androidView.background === undefined && drawable) {
45-
androidView.background = drawable.getConstantState();
44+
if (androidView._cachedDrawableConstState === undefined && drawable) {
45+
androidView._cachedDrawableConstState = drawable.getConstantState();
4646
}
4747

4848
if (isSetColorFilterOnlyWidget(nativeView)
@@ -77,11 +77,11 @@ export module ad {
7777
}
7878
}
7979
} else {
80-
// TODO: newDrawable for BitmapDrawable will fail if we don't speicfy resource. Use the other overload.
81-
const defaultDrawable = androidView.background ? androidView.background.newDrawable(nativeView.getResources()) : null;
80+
// TODO: newDrawable for BitmapDrawable will fail if we don't specify resource. Use the other overload.
81+
const defaultDrawable = androidView._cachedDrawableConstState ? androidView._cachedDrawableConstState.newDrawable(nativeView.getResources()) : null;
8282
org.nativescript.widgets.ViewHelper.setBackground(nativeView, defaultDrawable);
83-
androidView.background = undefined;
84-
83+
androidView._cachedDrawableConstState = undefined;
84+
8585
if (cache.layerType !== undefined) {
8686
cache.setLayerType(cache.layerType, null);
8787
cache.layerType = undefined;

0 commit comments

Comments
 (0)