mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
Add support for snapshot
Fix Layout class getMeasuredWidth & getMeasuredHeight Move some classes to widgets Fix API17 tests
This commit is contained in:
@@ -6,34 +6,45 @@
|
||||
|
||||
export * from "./button-common";
|
||||
|
||||
@Interfaces([android.view.View.OnClickListener])
|
||||
class ClickListener extends java.lang.Object implements android.view.View.OnClickListener {
|
||||
constructor(public owner: WeakRef<Button>) {
|
||||
super();
|
||||
return global.__native(this);
|
||||
interface ClickListener {
|
||||
new (owner: Button): android.view.View.OnClickListener;
|
||||
}
|
||||
|
||||
let ClickListener: ClickListener;
|
||||
|
||||
function initializeClickListener(): void {
|
||||
if (ClickListener) {
|
||||
return;
|
||||
}
|
||||
|
||||
public onClick(v: android.view.View): void {
|
||||
let btn = this.owner.get();
|
||||
if (btn) {
|
||||
btn._emit(ButtonBase.tapEvent);
|
||||
@Interfaces([android.view.View.OnClickListener])
|
||||
class ClickListenerImpl extends java.lang.Object implements android.view.View.OnClickListener {
|
||||
constructor(public owner: Button) {
|
||||
super();
|
||||
return global.__native(this);
|
||||
}
|
||||
|
||||
public onClick(v: android.view.View): void {
|
||||
this.owner._emit(ButtonBase.tapEvent);
|
||||
}
|
||||
}
|
||||
|
||||
ClickListener = ClickListenerImpl;
|
||||
}
|
||||
|
||||
export class Button extends ButtonBase {
|
||||
_button: android.widget.Button;
|
||||
private _highlightedHandler: (args: TouchGestureEventData) => void;
|
||||
private _defaultNativePadding: android.graphics.Rect;
|
||||
|
||||
|
||||
get android(): android.widget.Button {
|
||||
return this._button;
|
||||
}
|
||||
|
||||
public _createNativeView() {
|
||||
let weakRef = new WeakRef(this);
|
||||
initializeClickListener();
|
||||
this._button = new android.widget.Button(this._context);
|
||||
this._button.setOnClickListener(new ClickListener(weakRef));
|
||||
this._button.setOnClickListener(new ClickListener(this));
|
||||
|
||||
// Unlike all other widgets, the Button has padding 30 36 30 36 in device pixels.
|
||||
let result = new android.graphics.Rect();
|
||||
@@ -67,7 +78,7 @@ export class Button extends ButtonBase {
|
||||
|
||||
//PaddingTop
|
||||
get [paddingTopProperty.native](): Length {
|
||||
return { value: this._defaultNativePadding.top, unit: "px" }
|
||||
return { value: this._defaultNativePadding.top, unit: "px" }
|
||||
}
|
||||
set [paddingTopProperty.native](value: Length) {
|
||||
org.nativescript.widgets.ViewHelper.setPaddingTop(this.nativeView, Length.toDevicePixels(value, 0) + Length.toDevicePixels(this.style.borderTopWidth, 0));
|
||||
@@ -75,7 +86,7 @@ export class Button extends ButtonBase {
|
||||
|
||||
//PaddingRight
|
||||
get [paddingRightProperty.native](): Length {
|
||||
return { value: this._defaultNativePadding.right, unit: "px" }
|
||||
return { value: this._defaultNativePadding.right, unit: "px" }
|
||||
}
|
||||
set [paddingRightProperty.native](value: Length) {
|
||||
org.nativescript.widgets.ViewHelper.setPaddingRight(this.nativeView, Length.toDevicePixels(value, 0) + Length.toDevicePixels(this.style.borderRightWidth, 0));
|
||||
@@ -83,7 +94,7 @@ export class Button extends ButtonBase {
|
||||
|
||||
//PaddingBottom
|
||||
get [paddingBottomProperty.native](): Length {
|
||||
return { value: this._defaultNativePadding.bottom, unit: "px" }
|
||||
return { value: this._defaultNativePadding.bottom, unit: "px" }
|
||||
}
|
||||
set [paddingBottomProperty.native](value: Length) {
|
||||
org.nativescript.widgets.ViewHelper.setPaddingBottom(this.nativeView, Length.toDevicePixels(value, 0) + Length.toDevicePixels(this.style.borderBottomWidth, 0));
|
||||
@@ -91,7 +102,7 @@ export class Button extends ButtonBase {
|
||||
|
||||
//PaddingLeft
|
||||
get [paddingLeftProperty.native](): Length {
|
||||
return { value: this._defaultNativePadding.left, unit: "px" }
|
||||
return { value: this._defaultNativePadding.left, unit: "px" }
|
||||
}
|
||||
set [paddingLeftProperty.native](value: Length) {
|
||||
org.nativescript.widgets.ViewHelper.setPaddingLeft(this.nativeView, Length.toDevicePixels(value, 0) + Length.toDevicePixels(this.style.borderLeftWidth, 0));
|
||||
@@ -103,8 +114,8 @@ export class Button extends ButtonBase {
|
||||
set [zIndexProperty.native](value: number) {
|
||||
org.nativescript.widgets.ViewHelper.setZIndex(this.nativeView, value);
|
||||
// API >= 21
|
||||
if (this.nativeView.setStateListAnimator){
|
||||
if (this.nativeView.setStateListAnimator) {
|
||||
this.nativeView.setStateListAnimator(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user