FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

fix(android): elevation should not require explicit dynamic elevation… · NativeScript/NativeScript@be6e408 · GitHub

Commit be6e408

Browse files
authored
fix(android): elevation should not require explicit dynamic elevation offset (#7250)
1 parent ab485fe commit be6e408

2 files changed

Lines changed: 38 additions & 19 deletions

File tree

‎tns-core-modules/ui/button/button.android.ts‎

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
paddingLeftProperty, paddingTopProperty, paddingRightProperty, paddingBottomProperty,
44
Length, zIndexProperty, textAlignmentProperty, TextAlignment
55
} from "./button-common";
6-
import { androidElevationProperty, androidDynamicElevationOffsetProperty } from "../styling/style-properties";
76
import { profile } from "../../profiling";
87
import { TouchGestureEventData, GestureTypes, TouchAction } from "../gestures";
98
import { device } from "../../platform";
@@ -151,7 +150,13 @@ export class Button extends ButtonBase {
151150
org.nativescript.widgets.ViewHelper.setZIndex(this.nativeViewProtected, value);
152151
}
153152

154-
[androidElevationProperty.getDefault](): number {
153+
[textAlignmentProperty.setNative](value: TextAlignment) {
154+
// Button initial value is center.
155+
const newValue = value === "initial" ? "center" : value;
156+
super[textAlignmentProperty.setNative](newValue);
157+
}
158+
159+
protected getDefaultElevation(): number {
155160
if (sdkVersion() < 21) {
156161
return 0;
157162
}
@@ -162,17 +167,11 @@ export class Button extends ButtonBase {
162167
return 2;
163168
}
164169

165-
[androidDynamicElevationOffsetProperty.getDefault](): number {
170+
protected getDefaultDynamicElevationOffset(): number {
166171
if (sdkVersion() < 21) {
167172
return 0;
168173
}
169174

170175
return 4; // 4dp @dimen/button_pressed_z_material
171176
}
172-
173-
[textAlignmentProperty.setNative](value: TextAlignment) {
174-
// Button initial value is center.
175-
const newValue = value === "initial" ? "center" : value;
176-
super[textAlignmentProperty.setNative](newValue);
177-
}
178177
}

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

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -720,13 +720,7 @@ export class View extends ViewCommon {
720720
}
721721

722722
[androidElevationProperty.getDefault](): number {
723-
if (sdkVersion() < 21) {
724-
return 0;
725-
}
726-
727-
// NOTE: overriden in Button implementation as for widgets with StateListAnimator (Button)
728-
// nativeView.getElevation() returns 0 at the time of the getDefault() query
729-
return layout.toDeviceIndependentPixels((<any>this.nativeViewProtected).getElevation());
723+
return this.getDefaultElevation();
730724
}
731725
[androidElevationProperty.setNative](value: number) {
732726
if (sdkVersion() < 21) {
@@ -737,7 +731,7 @@ export class View extends ViewCommon {
737731
}
738732

739733
[androidDynamicElevationOffsetProperty.getDefault](): number {
740-
return 0;
734+
return this.getDefaultDynamicElevationOffset();
741735
}
742736
[androidDynamicElevationOffsetProperty.setNative](value: number) {
743737
if (sdkVersion() < 21) {
@@ -747,16 +741,42 @@ export class View extends ViewCommon {
747741
this.refreshStateListAnimator();
748742
}
749743

744+
protected getDefaultElevation(): number {
745+
if (sdkVersion() < 21) {
746+
return 0;
747+
}
748+
749+
// NOTE: overriden in Button implementation as for widgets with StateListAnimator (Button)
750+
// nativeView.getElevation() returns 0 at the time of the getDefault() query
751+
return layout.toDeviceIndependentPixels((<any>this.nativeViewProtected).getElevation());
752+
}
753+
754+
protected getDefaultDynamicElevationOffset() {
755+
// NOTE: overriden in Button implementation
756+
return 0;
757+
}
758+
750759
private refreshStateListAnimator() {
751760
const nativeView: any = this.nativeViewProtected;
752761

753762
const ObjectAnimator = android.animation.ObjectAnimator;
754763
const AnimatorSet = android.animation.AnimatorSet;
755764

756765
const duration = nativeView.getContext().getResources().getInteger(shortAnimTime) / 2;
757-
const elevation = layout.toDevicePixels(this.androidElevation || 0);
766+
767+
let elevation = this.androidElevation;
768+
if (typeof elevation === "undefined" || elevation === null) {
769+
elevation = this.getDefaultElevation();
770+
}
771+
elevation = layout.toDevicePixels(elevation);
772+
758773
const z = layout.toDevicePixels(0);
759-
const pressedZ = layout.toDevicePixels(this.androidDynamicElevationOffset || 0);
774+
775+
let pressedZ = this.androidDynamicElevationOffset;
776+
if (typeof pressedZ === "undefined" || pressedZ === null) {
777+
pressedZ = this.getDefaultDynamicElevationOffset();
778+
}
779+
pressedZ = layout.toDevicePixels(pressedZ);
760780

761781
const pressedSet = new AnimatorSet();
762782
pressedSet.playTogether(java.util.Arrays.asList([

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL