forked from NativeScript/NativeScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbutton.android.ts
More file actions
130 lines (106 loc) · 4.92 KB
/
Copy pathbutton.android.ts
File metadata and controls
130 lines (106 loc) · 4.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
import common = require("./button-common");
import utils = require("utils/utils")
import dependencyObservable = require("ui/core/dependency-observable");
import style = require("ui/styling/style");
import { TextBaseStyler as TBS } from "ui/text-base/text-base-styler";
global.moduleMerge(common, exports);
export class Button extends common.Button {
private _android: android.widget.Button;
private _isPressed: boolean;
constructor() {
super();
this._isPressed = false;
}
get android(): android.widget.Button {
return this._android;
}
public _createUI() {
var that = new WeakRef(this);
this._android = new android.widget.Button(this._context);
this._android.setOnClickListener(new android.view.View.OnClickListener(
<utils.Owned & android.view.View.IOnClickListener>{
get owner() {
return that.get();
},
onClick: function(v) {
if (this.owner) {
this.owner._emit(common.Button.tapEvent);
}
}
}));
this._android.setOnTouchListener(new android.view.View.OnTouchListener(
<utils.Owned & android.view.View.IOnTouchListener>{
get owner() {
return that.get();
},
onTouch: function(v, ev) {
if (ev.getAction() === 0) { // down
this.owner._goToVisualState("highlighted");
}
else if (ev.getAction() === 1) { // up
this.owner._goToVisualState("normal");
}
return false;
}
}
));
}
public _onTextPropertyChanged(data: dependencyObservable.PropertyChangeData) {
if (this.android) {
this.android.setText(data.newValue + "");
}
}
private _transformationMethod;
public _setFormattedTextPropertyToNative(value) {
var newText = value ? value._formattedText : null;
if (this.android) {
if (newText) {
if (!this._transformationMethod) {
this._transformationMethod = this.android.getTransformationMethod();
}
this.android.setTransformationMethod(null);
} else {
if (this._transformationMethod && !this.android.getTransformationMethod()) {
this.android.setTransformationMethod(this._transformationMethod);
}
}
this.android.setText(newText);
}
}
}
export class ButtonStyler implements style.Styler {
public static registerHandlers() {
// !!! IMPORTANT !!! This was moved here because of the following bug: https://github.com/NativeScript/NativeScript/issues/1902
// If there is no TextBase on the Page, the TextBaseStyler.registerHandlers
// method was never called because the file it is called from was never required.
// Register the same stylers for Button.
// It also derives from TextView but is not under TextBase in our View hierarchy.
var TextBaseStyler = <any>TBS;
style.registerHandler(style.colorProperty, new style.StylePropertyChangedHandler(
TextBaseStyler.setColorProperty,
TextBaseStyler.resetColorProperty,
TextBaseStyler.getNativeColorValue), "Button");
style.registerHandler(style.fontInternalProperty, new style.StylePropertyChangedHandler(
TextBaseStyler.setFontInternalProperty,
TextBaseStyler.resetFontInternalProperty,
TextBaseStyler.getNativeFontInternalValue), "Button");
style.registerHandler(style.textAlignmentProperty, new style.StylePropertyChangedHandler(
TextBaseStyler.setTextAlignmentProperty,
TextBaseStyler.resetTextAlignmentProperty,
TextBaseStyler.getNativeTextAlignmentValue), "Button");
style.registerHandler(style.textDecorationProperty, new style.StylePropertyChangedHandler(
TextBaseStyler.setTextDecorationProperty,
TextBaseStyler.resetTextDecorationProperty), "Button");
style.registerHandler(style.textTransformProperty, new style.StylePropertyChangedHandler(
TextBaseStyler.setTextTransformProperty,
TextBaseStyler.resetTextTransformProperty), "Button");
style.registerHandler(style.whiteSpaceProperty, new style.StylePropertyChangedHandler(
TextBaseStyler.setWhiteSpaceProperty,
TextBaseStyler.resetWhiteSpaceProperty), "Button");
style.registerHandler(style.letterSpacingProperty, new style.StylePropertyChangedHandler(
TextBaseStyler.setLetterSpacingProperty,
TextBaseStyler.resetLetterSpacingProperty,
TextBaseStyler.getLetterSpacingProperty), "Button");
}
}
ButtonStyler.registerHandlers();