mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
perf(core): android sdk check (#10084)
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user