perf(core): android sdk check (#10084)

This commit is contained in:
farfromrefuge
2022-11-12 18:09:45 +00:00
committed by GitHub
parent e687e9d756
commit abd722cd3d
22 changed files with 69 additions and 90 deletions

View File

@@ -6,19 +6,17 @@ import { CoreTypes } from '../../core-types';
import { profile } from '../../profiling';
import { TouchGestureEventData, GestureTypes, TouchAction } from '../gestures';
import { Device } from '../../platform';
import { SDK_VERSION } from '../../utils';
import lazy from '../../utils/lazy';
import type { Background } from '../styling/background';
export * from './button-common';
const sdkVersion = lazy(() => parseInt(Device.sdkVersion));
interface ClickListener {
new (owner: Button): android.view.View.OnClickListener;
}
let ClickListener: ClickListener;
let APILEVEL: number;
let AndroidButton: typeof android.widget.Button;
function initializeClickListener(): void {
@@ -49,13 +47,6 @@ function initializeClickListener(): void {
export class Button extends ButtonBase {
nativeViewProtected: android.widget.Button;
constructor() {
super();
if (!APILEVEL) {
APILEVEL = android.os.Build.VERSION.SDK_INT;
}
}
private _stateListAnimator: any;
private _highlightedHandler: (args: TouchGestureEventData) => void;
@@ -113,7 +104,7 @@ export class Button extends ButtonBase {
public resetNativeView(): void {
super.resetNativeView();
if (this._stateListAnimator && APILEVEL >= 21) {
if (this._stateListAnimator && SDK_VERSION >= 21) {
(<any>this.nativeViewProtected).setStateListAnimator(this._stateListAnimator);
this._stateListAnimator = undefined;
}
@@ -182,8 +173,7 @@ export class Button extends ButtonBase {
}
[zIndexProperty.setNative](value: number) {
// API >= 21
if (APILEVEL >= 21) {
if (SDK_VERSION >= 21) {
const nativeView = this.nativeViewProtected;
if (!this._stateListAnimator) {
this._stateListAnimator = (<any>nativeView).getStateListAnimator();
@@ -201,7 +191,7 @@ export class Button extends ButtonBase {
}
protected getDefaultElevation(): number {
if (sdkVersion() < 21) {
if (SDK_VERSION < 21) {
return 0;
}
@@ -212,7 +202,7 @@ export class Button extends ButtonBase {
}
protected getDefaultDynamicElevationOffset(): number {
if (sdkVersion() < 21) {
if (SDK_VERSION < 21) {
return 0;
}