diff --git a/tns-core-modules/ui/button/button.android.ts b/tns-core-modules/ui/button/button.android.ts index 2a2104652..2acbf475d 100644 --- a/tns-core-modules/ui/button/button.android.ts +++ b/tns-core-modules/ui/button/button.android.ts @@ -3,7 +3,6 @@ paddingLeftProperty, paddingTopProperty, paddingRightProperty, paddingBottomProperty, Length, zIndexProperty, textAlignmentProperty, TextAlignment } from "./button-common"; -import { androidElevationProperty, androidDynamicElevationOffsetProperty } from "../styling/style-properties"; import { profile } from "../../profiling"; import { TouchGestureEventData, GestureTypes, TouchAction } from "../gestures"; import { device } from "../../platform"; @@ -151,7 +150,13 @@ export class Button extends ButtonBase { org.nativescript.widgets.ViewHelper.setZIndex(this.nativeViewProtected, value); } - [androidElevationProperty.getDefault](): number { + [textAlignmentProperty.setNative](value: TextAlignment) { + // Button initial value is center. + const newValue = value === "initial" ? "center" : value; + super[textAlignmentProperty.setNative](newValue); + } + + protected getDefaultElevation(): number { if (sdkVersion() < 21) { return 0; } @@ -162,17 +167,11 @@ export class Button extends ButtonBase { return 2; } - [androidDynamicElevationOffsetProperty.getDefault](): number { + protected getDefaultDynamicElevationOffset(): number { if (sdkVersion() < 21) { return 0; } return 4; // 4dp @dimen/button_pressed_z_material } - - [textAlignmentProperty.setNative](value: TextAlignment) { - // Button initial value is center. - const newValue = value === "initial" ? "center" : value; - super[textAlignmentProperty.setNative](newValue); - } } diff --git a/tns-core-modules/ui/core/view/view.android.ts b/tns-core-modules/ui/core/view/view.android.ts index 7c4e92e60..0f6e936e4 100644 --- a/tns-core-modules/ui/core/view/view.android.ts +++ b/tns-core-modules/ui/core/view/view.android.ts @@ -720,13 +720,7 @@ export class View extends ViewCommon { } [androidElevationProperty.getDefault](): number { - if (sdkVersion() < 21) { - return 0; - } - - // NOTE: overriden in Button implementation as for widgets with StateListAnimator (Button) - // nativeView.getElevation() returns 0 at the time of the getDefault() query - return layout.toDeviceIndependentPixels((this.nativeViewProtected).getElevation()); + return this.getDefaultElevation(); } [androidElevationProperty.setNative](value: number) { if (sdkVersion() < 21) { @@ -737,7 +731,7 @@ export class View extends ViewCommon { } [androidDynamicElevationOffsetProperty.getDefault](): number { - return 0; + return this.getDefaultDynamicElevationOffset(); } [androidDynamicElevationOffsetProperty.setNative](value: number) { if (sdkVersion() < 21) { @@ -747,6 +741,21 @@ export class View extends ViewCommon { this.refreshStateListAnimator(); } + protected getDefaultElevation(): number { + if (sdkVersion() < 21) { + return 0; + } + + // NOTE: overriden in Button implementation as for widgets with StateListAnimator (Button) + // nativeView.getElevation() returns 0 at the time of the getDefault() query + return layout.toDeviceIndependentPixels((this.nativeViewProtected).getElevation()); + } + + protected getDefaultDynamicElevationOffset() { + // NOTE: overriden in Button implementation + return 0; + } + private refreshStateListAnimator() { const nativeView: any = this.nativeViewProtected; @@ -754,9 +763,20 @@ export class View extends ViewCommon { const AnimatorSet = android.animation.AnimatorSet; const duration = nativeView.getContext().getResources().getInteger(shortAnimTime) / 2; - const elevation = layout.toDevicePixels(this.androidElevation || 0); + + let elevation = this.androidElevation; + if (typeof elevation === "undefined" || elevation === null) { + elevation = this.getDefaultElevation(); + } + elevation = layout.toDevicePixels(elevation); + const z = layout.toDevicePixels(0); - const pressedZ = layout.toDevicePixels(this.androidDynamicElevationOffset || 0); + + let pressedZ = this.androidDynamicElevationOffset; + if (typeof pressedZ === "undefined" || pressedZ === null) { + pressedZ = this.getDefaultDynamicElevationOffset(); + } + pressedZ = layout.toDevicePixels(pressedZ); const pressedSet = new AnimatorSet(); pressedSet.playTogether(java.util.Arrays.asList([