Do not change the Android layer types (hardware/software) (#4625)

This commit is contained in:
Panayot Cankov
2017-08-25 10:45:58 +03:00
committed by GitHub
parent ab42715089
commit d62df3789c
4 changed files with 2 additions and 61 deletions

View File

@ -8,7 +8,7 @@ import {
translateXProperty, translateYProperty, scaleXProperty, scaleYProperty
} from "../styling/style-properties";
import { CacheLayerType, layout } from "../../utils/utils";
import { layout } from "../../utils/utils";
import lazy from "../../utils/lazy";
export * from "./animation-common";
@ -161,8 +161,6 @@ export class Animation extends AnimationBase {
}
}
this._enableHardwareAcceleration();
if (traceEnabled()) {
traceWrite("Starting " + this._nativeAnimatorsArray.length + " animations " + (this._playSequentially ? "sequentially." : "together."), traceCategories.Animation);
}
@ -190,7 +188,6 @@ export class Animation extends AnimationBase {
}
this._propertyUpdateCallbacks.forEach(v => v());
this._disableHardwareAcceleration();
this._resolveAnimationFinishedPromise();
if (this._target) {
@ -200,7 +197,6 @@ export class Animation extends AnimationBase {
private _onAndroidAnimationCancel() { // tslint:disable-line
this._propertyResetCallbacks.forEach(v => v());
this._disableHardwareAcceleration();
this._rejectAnimationFinishedPromise();
if (this._target) {
@ -465,27 +461,4 @@ export class Animation extends AnimationBase {
private static _getAndroidRepeatCount(iterations: number): number {
return (iterations === Number.POSITIVE_INFINITY) ? android.view.animation.Animation.INFINITE : iterations - 1;
}
private _enableHardwareAcceleration() {
for (let i = 0, length = this._propertyAnimations.length; i < length; i++) {
let cache = <CacheLayerType>this._propertyAnimations[i].target.nativeViewProtected;
if (cache) {
let layerType = cache.getLayerType();
if (layerType !== android.view.View.LAYER_TYPE_HARDWARE) {
cache.layerType = layerType;
cache.setLayerType(android.view.View.LAYER_TYPE_HARDWARE, null);
}
}
}
}
private _disableHardwareAcceleration() {
for (let i = 0, length = this._propertyAnimations.length; i < length; i++) {
let cache = <CacheLayerType>this._propertyAnimations[i].target.nativeViewProtected;
if (cache && cache.layerType !== undefined) {
cache.setLayerType(cache.layerType, null);
cache.layerType = undefined;
}
}
}
}

View File

@ -1,7 +1,6 @@
// Definitions.
import { Point, CustomLayoutView as CustomLayoutViewDefinition, dip } from ".";
import { GestureTypes, GestureEventData } from "../../gestures";
import { CacheLayerType } from "../../../utils/utils";
// Types.
import { Background, ad as androidBackground } from "../../styling/background";
@ -510,11 +509,6 @@ export class View extends ViewCommon {
}
(<any>nativeView).background = undefined;
const cache = <CacheLayerType><any>nativeView;
if (cache.layerType !== undefined) {
cache.setLayerType(cache.layerType, null);
cache.layerType = undefined;
}
}
}
}

View File

@ -1,5 +1,5 @@
import { View } from "../core/view";
import { CacheLayerType, isDataURI, isFileOrResourcePath, layout, RESOURCE_PREFIX, FILE_PREFIX } from "../../utils/utils";
import { isDataURI, isFileOrResourcePath, layout, RESOURCE_PREFIX, FILE_PREFIX } from "../../utils/utils";
import { parse } from "../../css-value";
import { path, knownFolders } from "../../file-system";
import * as application from "../../application";
@ -38,7 +38,6 @@ export module ad {
}
const background = view.style.backgroundInternal;
const cache = <CacheLayerType>view.nativeViewProtected;
const drawable = nativeView.getBackground();
const androidView = <any>view as AndroidView;
// use undefined as not set. getBackground will never return undefined only Drawable or null;
@ -68,16 +67,6 @@ export module ad {
} else {
refreshBorderDrawable(view, backgroundDrawable);
}
// This should be done only when backgroundImage is set!!!
if ((background.hasBorderWidth() || background.hasBorderRadius() || background.clipPath) && getSDK() < 18) {
// Switch to software because of unsupported canvas methods if hardware acceleration is on:
// http://developer.android.com/guide/topics/graphics/hardware-accel.html
if (cache.layerType === undefined) {
cache.layerType = cache.getLayerType();
cache.setLayerType(android.view.View.LAYER_TYPE_SOFTWARE, null);
}
}
} else {
const cachedDrawable = androidView._cachedDrawable;
let defaultDrawable: android.graphics.drawable.Drawable;
@ -92,11 +81,6 @@ export module ad {
org.nativescript.widgets.ViewHelper.setBackground(nativeView, defaultDrawable);
// TODO: Do we need to clear the drawable here? Can't we just reuse it again?
androidView._cachedDrawable = undefined;
if (cache.layerType !== undefined) {
cache.setLayerType(cache.layerType, null);
cache.layerType = undefined;
}
}
// TODO: Can we move BorderWidths as separate native setter?

View File

@ -15,16 +15,6 @@ export const FILE_PREFIX: string;
interface Owned {
owner: any;
}
/**
* Used to cache and restore Android views' layer type, i.e. android.view.View.getLayerType and android.view.View.setLayerType.
* @private
*/
interface CacheLayerType {
layerType: number;
setLayerType(layerType: number, paint: any): void;
getLayerType(): number;
}
//@endprivate
/**