Skip to content

Commit d62df37

Browse files
Do not change the Android layer types (hardware/software) (NativeScript#4625)
1 parent ab42715 commit d62df37

File tree

4 files changed

+2
-61
lines changed

4 files changed

+2
-61
lines changed

tns-core-modules/ui/animation/animation.android.ts

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
translateXProperty, translateYProperty, scaleXProperty, scaleYProperty
99
} from "../styling/style-properties";
1010

11-
import { CacheLayerType, layout } from "../../utils/utils";
11+
import { layout } from "../../utils/utils";
1212
import lazy from "../../utils/lazy";
1313

1414
export * from "./animation-common";
@@ -161,8 +161,6 @@ export class Animation extends AnimationBase {
161161
}
162162
}
163163

164-
this._enableHardwareAcceleration();
165-
166164
if (traceEnabled()) {
167165
traceWrite("Starting " + this._nativeAnimatorsArray.length + " animations " + (this._playSequentially ? "sequentially." : "together."), traceCategories.Animation);
168166
}
@@ -190,7 +188,6 @@ export class Animation extends AnimationBase {
190188
}
191189

192190
this._propertyUpdateCallbacks.forEach(v => v());
193-
this._disableHardwareAcceleration();
194191
this._resolveAnimationFinishedPromise();
195192

196193
if (this._target) {
@@ -200,7 +197,6 @@ export class Animation extends AnimationBase {
200197

201198
private _onAndroidAnimationCancel() { // tslint:disable-line
202199
this._propertyResetCallbacks.forEach(v => v());
203-
this._disableHardwareAcceleration();
204200
this._rejectAnimationFinishedPromise();
205201

206202
if (this._target) {
@@ -465,27 +461,4 @@ export class Animation extends AnimationBase {
465461
private static _getAndroidRepeatCount(iterations: number): number {
466462
return (iterations === Number.POSITIVE_INFINITY) ? android.view.animation.Animation.INFINITE : iterations - 1;
467463
}
468-
469-
private _enableHardwareAcceleration() {
470-
for (let i = 0, length = this._propertyAnimations.length; i < length; i++) {
471-
let cache = <CacheLayerType>this._propertyAnimations[i].target.nativeViewProtected;
472-
if (cache) {
473-
let layerType = cache.getLayerType();
474-
if (layerType !== android.view.View.LAYER_TYPE_HARDWARE) {
475-
cache.layerType = layerType;
476-
cache.setLayerType(android.view.View.LAYER_TYPE_HARDWARE, null);
477-
}
478-
}
479-
}
480-
}
481-
482-
private _disableHardwareAcceleration() {
483-
for (let i = 0, length = this._propertyAnimations.length; i < length; i++) {
484-
let cache = <CacheLayerType>this._propertyAnimations[i].target.nativeViewProtected;
485-
if (cache && cache.layerType !== undefined) {
486-
cache.setLayerType(cache.layerType, null);
487-
cache.layerType = undefined;
488-
}
489-
}
490-
}
491464
}

tns-core-modules/ui/core/view/view.android.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// Definitions.
22
import { Point, CustomLayoutView as CustomLayoutViewDefinition, dip } from ".";
33
import { GestureTypes, GestureEventData } from "../../gestures";
4-
import { CacheLayerType } from "../../../utils/utils";
54

65
// Types.
76
import { Background, ad as androidBackground } from "../../styling/background";
@@ -510,11 +509,6 @@ export class View extends ViewCommon {
510509
}
511510

512511
(<any>nativeView).background = undefined;
513-
const cache = <CacheLayerType><any>nativeView;
514-
if (cache.layerType !== undefined) {
515-
cache.setLayerType(cache.layerType, null);
516-
cache.layerType = undefined;
517-
}
518512
}
519513
}
520514
}

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

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { View } from "../core/view";
2-
import { CacheLayerType, isDataURI, isFileOrResourcePath, layout, RESOURCE_PREFIX, FILE_PREFIX } from "../../utils/utils";
2+
import { isDataURI, isFileOrResourcePath, layout, RESOURCE_PREFIX, FILE_PREFIX } from "../../utils/utils";
33
import { parse } from "../../css-value";
44
import { path, knownFolders } from "../../file-system";
55
import * as application from "../../application";
@@ -38,7 +38,6 @@ export module ad {
3838
}
3939

4040
const background = view.style.backgroundInternal;
41-
const cache = <CacheLayerType>view.nativeViewProtected;
4241
const drawable = nativeView.getBackground();
4342
const androidView = <any>view as AndroidView;
4443
// use undefined as not set. getBackground will never return undefined only Drawable or null;
@@ -68,16 +67,6 @@ export module ad {
6867
} else {
6968
refreshBorderDrawable(view, backgroundDrawable);
7069
}
71-
72-
// This should be done only when backgroundImage is set!!!
73-
if ((background.hasBorderWidth() || background.hasBorderRadius() || background.clipPath) && getSDK() < 18) {
74-
// Switch to software because of unsupported canvas methods if hardware acceleration is on:
75-
// http://developer.android.com/guide/topics/graphics/hardware-accel.html
76-
if (cache.layerType === undefined) {
77-
cache.layerType = cache.getLayerType();
78-
cache.setLayerType(android.view.View.LAYER_TYPE_SOFTWARE, null);
79-
}
80-
}
8170
} else {
8271
const cachedDrawable = androidView._cachedDrawable;
8372
let defaultDrawable: android.graphics.drawable.Drawable;
@@ -92,11 +81,6 @@ export module ad {
9281
org.nativescript.widgets.ViewHelper.setBackground(nativeView, defaultDrawable);
9382
// TODO: Do we need to clear the drawable here? Can't we just reuse it again?
9483
androidView._cachedDrawable = undefined;
95-
96-
if (cache.layerType !== undefined) {
97-
cache.setLayerType(cache.layerType, null);
98-
cache.layerType = undefined;
99-
}
10084
}
10185

10286
// TODO: Can we move BorderWidths as separate native setter?

tns-core-modules/utils/utils.d.ts

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,6 @@ export const FILE_PREFIX: string;
1515
interface Owned {
1616
owner: any;
1717
}
18-
19-
/**
20-
* Used to cache and restore Android views' layer type, i.e. android.view.View.getLayerType and android.view.View.setLayerType.
21-
* @private
22-
*/
23-
interface CacheLayerType {
24-
layerType: number;
25-
setLayerType(layerType: number, paint: any): void;
26-
getLayerType(): number;
27-
}
2818
//@endprivate
2919

3020
/**

0 commit comments

Comments
 (0)