| 57 | } |
| 58 | |
| 59 | export class Button extends ButtonBase { |
| 60 | nativeViewProtected: android.widget.Button; |
| 61 | |
| 62 | private _stateListAnimator: any; |
| 63 | |
| 64 | @profile |
| 65 | public createNativeView() { |
| 66 | if (!AndroidButton) { |
| 67 | AndroidButton = android.widget.Button; |
| 68 | } |
| 69 | |
| 70 | return new AndroidButton(this._context); |
| 71 | } |
| 72 | |
| 73 | public initNativeView(): void { |
| 74 | super.initNativeView(); |
| 75 | const nativeView = this.nativeViewProtected; |
| 76 | // make consistent with iOS, easier on users given css styling |
| 77 | nativeView.setAllCaps(false); |
| 78 | initializeClickListener(); |
| 79 | const clickListener = new ClickListener(this); |
| 80 | nativeView.setOnClickListener(clickListener); |
| 81 | (<any>nativeView).clickListener = clickListener; |
| 82 | } |
| 83 | |
| 84 | public disposeNativeView() { |
| 85 | if ((<any>this.nativeViewProtected)?.clickListener) { |
| 86 | (<any>this.nativeViewProtected).clickListener.owner = null; |
| 87 | } |
| 88 | super.disposeNativeView(); |
| 89 | } |
| 90 | |
| 91 | public resetNativeView(): void { |
| 92 | super.resetNativeView(); |
| 93 | |
| 94 | if (this._stateListAnimator && SDK_VERSION >= 21) { |
| 95 | this.nativeViewProtected.setStateListAnimator(this._stateListAnimator); |
| 96 | this._stateListAnimator = undefined; |
| 97 | } |
| 98 | } |
| 99 | |
| 100 | @PseudoClassHandler('normal', 'highlighted', 'pressed', 'active') |
| 101 | _updateButtonStateChangeHandler(subscribe: boolean) { |
| 102 | if (subscribe) { |
| 103 | this.on(GestureTypes[GestureTypes.touch], onButtonStateChange); |
| 104 | } else { |
| 105 | this.off(GestureTypes[GestureTypes.touch], onButtonStateChange); |
| 106 | this._removeVisualState('highlighted'); |
| 107 | } |
| 108 | } |
| 109 | |
| 110 | override get needsNativeDrawableFill(): boolean { |
| 111 | return true; |
| 112 | } |
| 113 | |
| 114 | [minWidthProperty.getDefault](): CoreTypes.LengthType { |
| 115 | const dips = org.nativescript.widgets.ViewHelper.getMinWidth(this.nativeViewProtected); |
| 116 |
nothing calls this directly
no test coverage detected