mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-16 11:42:04 +08:00
Fixed: Android layerType should not be changed if there is no need
Resolves #1899
This commit is contained in:
@ -24,6 +24,7 @@
|
|||||||
android:allowBackup="true"
|
android:allowBackup="true"
|
||||||
android:icon="@drawable/icon"
|
android:icon="@drawable/icon"
|
||||||
android:label="@string/app_name"
|
android:label="@string/app_name"
|
||||||
|
android:largeHeap="true"
|
||||||
android:theme="@style/AppTheme" >
|
android:theme="@style/AppTheme" >
|
||||||
<activity
|
<activity
|
||||||
android:name="com.tns.NativeScriptActivity"
|
android:name="com.tns.NativeScriptActivity"
|
||||||
|
@ -296,4 +296,49 @@ export function checkNativeBackgroundImage(v: view.View): boolean {
|
|||||||
var bkg = <background.ad.BorderDrawable>(<android.view.View>v.android).getBackground();
|
var bkg = <background.ad.BorderDrawable>(<android.view.View>v.android).getBackground();
|
||||||
|
|
||||||
return bkg && bkg.background && !types.isNullOrUndefined(bkg.background.image);
|
return bkg && bkg.background && !types.isNullOrUndefined(bkg.background.image);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let SDK: number;
|
||||||
|
function getSDK() {
|
||||||
|
if (!SDK) {
|
||||||
|
SDK = android.os.Build.VERSION.SDK_INT;
|
||||||
|
}
|
||||||
|
|
||||||
|
return SDK;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function test_AndroidLayerType_BorderWidth() {
|
||||||
|
helper.buildUIAndRunTest(new labelModule.Label(), (views: Array<view.View>) => {
|
||||||
|
let lbl = <labelModule.Label>(views[0]);
|
||||||
|
let androidView = <android.view.View>lbl.android;
|
||||||
|
let originalLayerType = androidView.getLayerType();
|
||||||
|
lbl.borderWidth = 5;
|
||||||
|
TKUnit.assertEqual(androidView.getLayerType(), getSDK() < 18 ? android.view.View.LAYER_TYPE_SOFTWARE : originalLayerType);
|
||||||
|
lbl.borderWidth = 0;
|
||||||
|
TKUnit.assertEqual(androidView.getLayerType(), originalLayerType);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
export function test_AndroidLayerType_BorderRadius() {
|
||||||
|
helper.buildUIAndRunTest(new labelModule.Label(), (views: Array<view.View>) => {
|
||||||
|
let lbl = <labelModule.Label>(views[0]);
|
||||||
|
let androidView = <android.view.View>lbl.android;
|
||||||
|
let originalLayerType = androidView.getLayerType();
|
||||||
|
lbl.borderRadius = 5;
|
||||||
|
TKUnit.assertEqual(androidView.getLayerType(), getSDK() < 18 ? android.view.View.LAYER_TYPE_SOFTWARE : originalLayerType);
|
||||||
|
lbl.borderRadius = 0;
|
||||||
|
TKUnit.assertEqual(androidView.getLayerType(), originalLayerType);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
export function test_AndroidLayerType_ClipPath() {
|
||||||
|
helper.buildUIAndRunTest(new labelModule.Label(), (views: Array<view.View>) => {
|
||||||
|
let lbl = <labelModule.Label>(views[0]);
|
||||||
|
let androidView = <android.view.View>lbl.android;
|
||||||
|
let originalLayerType = androidView.getLayerType();
|
||||||
|
lbl.style.clipPath = "rect(0, 0, 100%, 100%)";
|
||||||
|
TKUnit.assertEqual(androidView.getLayerType(), getSDK() < 18 ? android.view.View.LAYER_TYPE_SOFTWARE : originalLayerType);
|
||||||
|
lbl.style.clipPath = undefined;
|
||||||
|
TKUnit.assertEqual(androidView.getLayerType(), originalLayerType);
|
||||||
|
});
|
||||||
|
};
|
@ -225,8 +225,14 @@ export module ad {
|
|||||||
|
|
||||||
var _defaultBackgrounds = new Map<string, android.graphics.drawable.Drawable>();
|
var _defaultBackgrounds = new Map<string, android.graphics.drawable.Drawable>();
|
||||||
|
|
||||||
|
interface CacheLayerType {
|
||||||
|
layerType: number;
|
||||||
|
}
|
||||||
|
|
||||||
export function onBackgroundOrBorderPropertyChanged(v: view.View) {
|
export function onBackgroundOrBorderPropertyChanged(v: view.View) {
|
||||||
var nativeView = <android.view.View>v._nativeView;
|
var nativeView = <android.view.View>v._nativeView;
|
||||||
|
var cache = <CacheLayerType>v._nativeView;
|
||||||
|
|
||||||
if (!nativeView) {
|
if (!nativeView) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -265,14 +271,12 @@ export module ad {
|
|||||||
bkg.background = backgroundValue;
|
bkg.background = backgroundValue;
|
||||||
bkg.clipPath = clipPathValue;
|
bkg.clipPath = clipPathValue;
|
||||||
|
|
||||||
if (getSDK() < 18) {
|
if ((v.borderWidth !== 0 || v.borderRadius !== 0 || clipPathValue) && getSDK() < 18) {
|
||||||
// Switch to software because of unsupported canvas methods if hardware acceleration is on:
|
// Switch to software because of unsupported canvas methods if hardware acceleration is on:
|
||||||
// http://developer.android.com/guide/topics/graphics/hardware-accel.html
|
// http://developer.android.com/guide/topics/graphics/hardware-accel.html
|
||||||
|
cache.layerType = nativeView.getLayerType();
|
||||||
nativeView.setLayerType(android.view.View.LAYER_TYPE_SOFTWARE, null);
|
nativeView.setLayerType(android.view.View.LAYER_TYPE_SOFTWARE, null);
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
nativeView.setLayerType(android.view.View.LAYER_TYPE_HARDWARE, null);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// reset the value with the default native value
|
// reset the value with the default native value
|
||||||
@ -287,9 +291,10 @@ export module ad {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (getSDK() < 18) {
|
if (cache.layerType !== undefined) {
|
||||||
// Reset layer type to hardware
|
// Reset layer type
|
||||||
nativeView.setLayerType(android.view.View.LAYER_TYPE_HARDWARE, null);
|
nativeView.setLayerType(cache.layerType, null);
|
||||||
|
cache.layerType = undefined;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -405,9 +405,11 @@ function isPaddingValid(value: number): boolean {
|
|||||||
|
|
||||||
var supportedPaths = ["rect", "circle", "ellipse", "polygon"];
|
var supportedPaths = ["rect", "circle", "ellipse", "polygon"];
|
||||||
function isClipPathValid(value: string): boolean {
|
function isClipPathValid(value: string): boolean {
|
||||||
|
if (!value){
|
||||||
|
return true;
|
||||||
|
}
|
||||||
var functionName = value.substring(0, value.indexOf("(")).trim();
|
var functionName = value.substring(0, value.indexOf("(")).trim();
|
||||||
|
return supportedPaths.indexOf(functionName) !== -1;
|
||||||
return supportedPaths.indexOf(functionName) !== -1 || value === "";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function isMarginValid(value: number): boolean {
|
function isMarginValid(value: number): boolean {
|
||||||
@ -921,7 +923,7 @@ export class Style extends DependencyObservable implements styling.Style {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private _applyStyleProperty(property: Property, newValue: any) {
|
private _applyStyleProperty(property: Property, newValue: any) {
|
||||||
|
|
||||||
if (!this._view._shouldApplyStyleHandlers()) {
|
if (!this._view._shouldApplyStyleHandlers()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user