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

fix(android): elevation should not require explicit dynamic elevation by manoldonev · Pull Request #7250 · NativeScript/NativeScript · GitHub

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .ts  (2) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
17 changes: 8 additions & 9 deletions tns-core-modules/ui/button/button.android.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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;
}
Expand All @@ -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);
}
}
40 changes: 30 additions & 10 deletions tns-core-modules/ui/core/view/view.android.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -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((<any>this.nativeViewProtected).getElevation());
return this.getDefaultElevation();
}
[androidElevationProperty.setNative](value: number) {
if (sdkVersion() < 21) {
Expand All @@ -737,7 +731,7 @@ export class View extends ViewCommon {
}

[androidDynamicElevationOffsetProperty.getDefault](): number {
return 0;
return this.getDefaultDynamicElevationOffset();
}
[androidDynamicElevationOffsetProperty.setNative](value: number) {
if (sdkVersion() < 21) {
Expand All @@ -747,16 +741,42 @@ 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((<any>this.nativeViewProtected).getElevation());
}

protected getDefaultDynamicElevationOffset() {
// NOTE: overriden in Button implementation
return 0;
}

private refreshStateListAnimator() {
const nativeView: any = this.nativeViewProtected;

const ObjectAnimator = android.animation.ObjectAnimator;
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([
Expand Down

Back | FazBrowse Home | New Git URL