FIX: Background drawable cache conflicts with local property (#4633)

This commit is contained in:
Alexander Vakrilov
2017-08-01 11:53:42 +03:00
committed by SvetoslavTsenov
parent 2dbd1b19ea
commit 7983895c8e
2 changed files with 18 additions and 7 deletions

View File

@@ -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<View>) => {
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.");

View File

@@ -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 = <any>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;