forked from bradleygore/nativescript-textinputlayout
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtextInputLayout.android.js
More file actions
133 lines (133 loc) · 5.53 KB
/
textInputLayout.android.js
File metadata and controls
133 lines (133 loc) · 5.53 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
131
132
133
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var textInputLayout_common_1 = require("./textInputLayout.common");
var view_1 = require("tns-core-modules/ui/core/view");
var text_view_1 = require("tns-core-modules/ui/text-view");
var text_field_1 = require("tns-core-modules/ui/text-field");
function getStyleResourceId(context, name) {
if (!context || (name || '').length === 0) {
return null;
}
return context.getResources().getIdentifier(name, 'style', context.getPackageName());
}
exports.hintAnimationEnabledProperty = new textInputLayout_common_1.Property({
name: "hintAnimationEnabled", valueConverter: view_1.booleanConverter
});
exports.hintTextAppearanceProperty = new textInputLayout_common_1.Property({
name: "hintTextAppearance"
});
exports.counterEnabledProperty = new textInputLayout_common_1.Property({
name: "counterEnabled", affectsLayout: true, valueConverter: view_1.booleanConverter
});
exports.errorTextAppearanceProperty = new textInputLayout_common_1.Property({
name: "errorTextAppearance"
});
exports.errorEnabledProperty = new textInputLayout_common_1.Property({
name: "errorEnabled", affectsLayout: true, valueConverter: view_1.booleanConverter
});
var TextInputLayout = (function (_super) {
__extends(TextInputLayout, _super);
function TextInputLayout() {
return _super !== null && _super.apply(this, arguments) || this;
}
Object.defineProperty(TextInputLayout.prototype, "textField", {
get: function () { return this._textField; },
set: function (tf) {
var old = this._textField;
if (old) {
this._removeView(old);
}
this._textField = tf;
if (tf) {
this._addView(tf);
}
this.setupTextView();
},
enumerable: true,
configurable: true
});
Object.defineProperty(TextInputLayout.prototype, "_childrenCount", {
get: function () {
return this._textField ? 1 : 0;
},
enumerable: true,
configurable: true
});
TextInputLayout.prototype._addChildFromBuilder = function (name, child) {
if (!(child instanceof text_view_1.TextView || child instanceof text_field_1.TextField)) {
throw new Error('TextInputLayout may only have a <TextView> or <TextField> as a child');
}
this.textField = child;
};
TextInputLayout.prototype.eachChildView = function (callback) {
if (this._textField) {
callback(this._textField);
}
};
TextInputLayout.prototype.createNativeView = function () {
return new android.support.design.widget.TextInputLayout(this._context);
};
TextInputLayout.prototype.onLoaded = function () {
_super.prototype.onLoaded.call(this);
this.setupTextView();
};
TextInputLayout.prototype.setupTextView = function () {
if (!this.isLoaded) {
return;
}
var textField = this._textField;
var nativeView = this.nativeView;
var layoutParams = new android.widget.LinearLayout.LayoutParams(android.widget.LinearLayout.LayoutParams.MATCH_PARENT, android.widget.LinearLayout.LayoutParams.WRAP_CONTENT);
var current = nativeView.getEditText();
var nativeTextField = textField.nativeView;
if (current !== nativeTextField) {
if (current) {
nativeView.removeView(current);
}
nativeView.addView(nativeTextField, 0, layoutParams);
}
var txtValue = textField.nativeView.getText();
nativeTextField.setText('');
nativeTextField.setText(txtValue);
};
TextInputLayout.prototype[textInputLayout_common_1.hintProperty.setNative] = function (value) {
this.nativeView.setHint(value);
};
TextInputLayout.prototype[exports.hintAnimationEnabledProperty.setNative] = function (value) {
this.nativeView.setHintAnimationEnabled(value);
};
TextInputLayout.prototype[exports.hintTextAppearanceProperty.setNative] = function (value) {
var resourceId = getStyleResourceId(this._context, value);
if (value && resourceId) {
this.nativeView.setHintTextAppearance(resourceId);
}
};
TextInputLayout.prototype[exports.errorTextAppearanceProperty.setNative] = function (value) {
var resourceId = getStyleResourceId(this._context, value);
if (value && resourceId) {
this.nativeView.setErrorTextAppearance(resourceId);
}
};
TextInputLayout.prototype[exports.errorEnabledProperty.setNative] = function (value) {
if (!value && (this.error || '').length > 0) {
this.error = '';
}
this.nativeView.setErrorEnabled(value);
};
TextInputLayout.prototype[textInputLayout_common_1.errorProperty.setNative] = function (value) {
this.nativeView.setError(value || '');
if ((value || '').length > 0) {
this.errorEnabled = true;
}
};
TextInputLayout.prototype[exports.counterEnabledProperty.setNative] = function (value) {
this.nativeView.setCounterEnabled(value);
};
return TextInputLayout;
}(textInputLayout_common_1.TextInputLayout));
exports.TextInputLayout = TextInputLayout;
exports.hintAnimationEnabledProperty.register(TextInputLayout);
exports.hintTextAppearanceProperty.register(TextInputLayout);
exports.errorTextAppearanceProperty.register(TextInputLayout);
exports.counterEnabledProperty.register(TextInputLayout);
exports.errorEnabledProperty.register(TextInputLayout);