feat(android): elevation shadow support (#7136)

This commit is contained in:
Eduardo Speroni
2019-05-10 05:05:28 -03:00
committed by Manol Donev
parent f8754913c3
commit cf533a7b6d
12 changed files with 236 additions and 11 deletions

View File

@@ -3,11 +3,16 @@
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";
import lazy from "../../utils/lazy";
export * from "./button-common";
const sdkVersion = lazy(() => parseInt(device.sdkVersion));
interface ClickListener {
new(owner: Button): android.view.View.OnClickListener;
}
@@ -146,9 +151,28 @@ export class Button extends ButtonBase {
org.nativescript.widgets.ViewHelper.setZIndex(this.nativeViewProtected, value);
}
[androidElevationProperty.getDefault](): number {
if (sdkVersion() < 21) {
return 0;
}
// NOTE: Button widget has StateListAnimator that defines the elevation value and
// at the time of the getDefault() query the animator is not applied yet so we
// return the hardcoded @dimen/button_elevation_material value 2dp here instead
return 2;
}
[androidDynamicElevationOffsetProperty.getDefault](): 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);
}
}
}