1 | import { Font } from '../styling/font';
|
2 | import { SearchBarBase, textProperty, hintProperty, textFieldHintColorProperty, textFieldBackgroundColorProperty } from './search-bar-common';
|
3 | import { isUserInteractionEnabledProperty, isEnabledProperty } from '../core/view';
|
4 | import { ad } from '../../utils';
|
5 | import { Color } from '../../color';
|
6 | import { colorProperty, backgroundColorProperty, backgroundInternalProperty, fontInternalProperty, fontSizeProperty } from '../styling/style-properties';
|
7 | export * from './search-bar-common';
|
8 | const SEARCHTEXT = Symbol('searchText');
|
9 | const QUERY = Symbol('query');
|
10 | let QueryTextListener;
|
11 | let CloseListener;
|
12 | function initializeNativeClasses() {
|
13 | if (QueryTextListener) {
|
14 | return;
|
15 | }
|
16 | var CompatQueryTextListenerImpl = (function (_super) {
|
17 | __extends(CompatQueryTextListenerImpl, _super);
|
18 | function CompatQueryTextListenerImpl(owner) {
|
19 | var _this = _super.call(this) || this;
|
20 | _this.owner = owner;
|
21 | return global.__native(_this);
|
22 | }
|
23 | CompatQueryTextListenerImpl.prototype.onQueryTextChange = function (newText) {
|
24 | var owner = this.owner;
|
25 | textProperty.nativeValueChange(owner, newText);
|
26 |
|
27 | if (newText === '' && this[SEARCHTEXT] !== newText) {
|
28 | owner._emit(SearchBarBase.clearEvent);
|
29 | }
|
30 | this[SEARCHTEXT] = newText;
|
31 | this[QUERY] = undefined;
|
32 | return true;
|
33 | };
|
34 | CompatQueryTextListenerImpl.prototype.onQueryTextSubmit = function (query) {
|
35 | var owner = this.owner;
|
36 |
|
37 | if (query !== '' && this[QUERY] !== query) {
|
38 | owner._emit(SearchBarBase.submitEvent);
|
39 | }
|
40 | this[QUERY] = query;
|
41 | return true;
|
42 | };
|
43 | var _a;
|
44 | CompatQueryTextListenerImpl = __decorate([
|
45 | Interfaces([androidx.appcompat.widget.SearchView.OnQueryTextListener]),
|
46 | __metadata("design:paramtypes", [typeof (_a = typeof SearchBar !== "undefined" && SearchBar) === "function" ? _a : Object])
|
47 | ], CompatQueryTextListenerImpl);
|
48 | return CompatQueryTextListenerImpl;
|
49 | }(java.lang.Object));
|
50 | var CompatCloseListenerImpl = (function (_super) {
|
51 | __extends(CompatCloseListenerImpl, _super);
|
52 | function CompatCloseListenerImpl(owner) {
|
53 | var _this = _super.call(this) || this;
|
54 | _this.owner = owner;
|
55 | return global.__native(_this);
|
56 | }
|
57 | CompatCloseListenerImpl.prototype.onClose = function () {
|
58 | this.owner._emit(SearchBarBase.clearEvent);
|
59 | return true;
|
60 | };
|
61 | var _a;
|
62 | CompatCloseListenerImpl = __decorate([
|
63 | Interfaces([androidx.appcompat.widget.SearchView.OnCloseListener]),
|
64 | __metadata("design:paramtypes", [typeof (_a = typeof SearchBar !== "undefined" && SearchBar) === "function" ? _a : Object])
|
65 | ], CompatCloseListenerImpl);
|
66 | return CompatCloseListenerImpl;
|
67 | }(java.lang.Object));
|
68 | QueryTextListener = CompatQueryTextListenerImpl;
|
69 | CloseListener = CompatCloseListenerImpl;
|
70 | }
|
71 | function enableSearchView(nativeView, value) {
|
72 | nativeView.setEnabled(value);
|
73 | if (!(nativeView instanceof android.view.ViewGroup)) {
|
74 | return;
|
75 | }
|
76 | for (let i = 0; i < nativeView.getChildCount(); i++) {
|
77 | const child = nativeView.getChildAt(i);
|
78 | enableSearchView(child, value);
|
79 | }
|
80 | }
|
81 | function enableUserInteractionSearchView(nativeView, value) {
|
82 | nativeView.setClickable(value);
|
83 | nativeView.setFocusable(value);
|
84 | if (!(nativeView instanceof android.view.ViewGroup)) {
|
85 | return;
|
86 | }
|
87 | for (let i = 0; i < nativeView.getChildCount(); i++) {
|
88 | const child = nativeView.getChildAt(i);
|
89 | enableUserInteractionSearchView(child, value);
|
90 | }
|
91 | }
|
92 | export class SearchBar extends SearchBarBase {
|
93 | dismissSoftInput() {
|
94 | ad.dismissSoftInput(this.nativeViewProtected);
|
95 | }
|
96 | focus() {
|
97 | const result = super.focus();
|
98 | if (result) {
|
99 | ad.showSoftInput(this.nativeViewProtected);
|
100 | }
|
101 | return result;
|
102 | }
|
103 | createNativeView() {
|
104 | const nativeView = new androidx.appcompat.widget.SearchView(this._context);
|
105 | nativeView.setIconified(false);
|
106 | return nativeView;
|
107 | }
|
108 | initNativeView() {
|
109 | super.initNativeView();
|
110 | const nativeView = this.nativeViewProtected;
|
111 | initializeNativeClasses();
|
112 | const queryTextListener = new QueryTextListener(this);
|
113 | nativeView.setOnQueryTextListener(queryTextListener);
|
114 | nativeView.queryTextListener = queryTextListener;
|
115 | const closeListener = new CloseListener(this);
|
116 | nativeView.setOnCloseListener(closeListener);
|
117 | nativeView.closeListener = closeListener;
|
118 | }
|
119 | disposeNativeView() {
|
120 | const nativeView = this.nativeViewProtected;
|
121 | if (nativeView.closeListener) {
|
122 | nativeView.closeListener.owner = null;
|
123 | }
|
124 | if (nativeView.queryTextListener) {
|
125 | nativeView.queryTextListener.owner = null;
|
126 | }
|
127 | this._searchPlate = null;
|
128 | this._searchTextView = null;
|
129 | super.disposeNativeView();
|
130 | }
|
131 | [isEnabledProperty.setNative](value) {
|
132 | enableSearchView(this.nativeViewProtected, value);
|
133 | }
|
134 | [isUserInteractionEnabledProperty.setNative](value) {
|
135 | enableUserInteractionSearchView(this.nativeViewProtected, value);
|
136 | }
|
137 | [backgroundColorProperty.getDefault]() {
|
138 |
|
139 | const result = this.nativeViewProtected.getDrawingCacheBackgroundColor();
|
140 | return result;
|
141 | }
|
142 | [backgroundColorProperty.setNative](value) {
|
143 | let color;
|
144 | if (typeof value === 'number') {
|
145 | color = value;
|
146 | }
|
147 | else {
|
148 | color = value.android;
|
149 | }
|
150 | this.nativeViewProtected.setBackgroundColor(color);
|
151 | const searchPlate = this._getSearchPlate();
|
152 | searchPlate.setBackgroundColor(color);
|
153 | }
|
154 | [colorProperty.getDefault]() {
|
155 | const textView = this._getTextView();
|
156 | return textView.getCurrentTextColor();
|
157 | }
|
158 | [colorProperty.setNative](value) {
|
159 | const color = typeof value === 'number' ? value : value.android;
|
160 | const textView = this._getTextView();
|
161 | textView.setTextColor(color);
|
162 | }
|
163 | [fontSizeProperty.getDefault]() {
|
164 | return { nativeSize: this._getTextView().getTextSize() };
|
165 | }
|
166 | [fontSizeProperty.setNative](value) {
|
167 | if (typeof value === 'number') {
|
168 | this._getTextView().setTextSize(value);
|
169 | }
|
170 | else {
|
171 | this._getTextView().setTextSize(android.util.TypedValue.COMPLEX_UNIT_PX, value.nativeSize);
|
172 | }
|
173 | }
|
174 | [fontInternalProperty.getDefault]() {
|
175 | return this._getTextView().getTypeface();
|
176 | }
|
177 | [fontInternalProperty.setNative](value) {
|
178 | this._getTextView().setTypeface(value instanceof Font ? value.getAndroidTypeface() : value);
|
179 | }
|
180 | [backgroundInternalProperty.getDefault]() {
|
181 | return null;
|
182 | }
|
183 | [backgroundInternalProperty.setNative](value) {
|
184 |
|
185 | }
|
186 | [textProperty.getDefault]() {
|
187 | return '';
|
188 | }
|
189 | [textProperty.setNative](value) {
|
190 | const text = value === null || value === undefined ? '' : value.toString();
|
191 | this.nativeViewProtected.setQuery(text, false);
|
192 | }
|
193 | [hintProperty.getDefault]() {
|
194 | return null;
|
195 | }
|
196 | [hintProperty.setNative](value) {
|
197 | if (value === null || value === undefined) {
|
198 | this.nativeViewProtected.setQueryHint(null);
|
199 | }
|
200 | else {
|
201 | this.nativeViewProtected.setQueryHint(value.toString());
|
202 | }
|
203 | }
|
204 | [textFieldBackgroundColorProperty.getDefault]() {
|
205 | const textView = this._getTextView();
|
206 | return textView.getBackground();
|
207 | }
|
208 | [textFieldBackgroundColorProperty.setNative](value) {
|
209 | const textView = this._getTextView();
|
210 | if (value instanceof Color) {
|
211 | textView.setBackgroundColor(value.android);
|
212 | }
|
213 | else {
|
214 | textView.setBackground(value);
|
215 | }
|
216 | }
|
217 | [textFieldHintColorProperty.getDefault]() {
|
218 | const textView = this._getTextView();
|
219 | return textView.getCurrentTextColor();
|
220 | }
|
221 | [textFieldHintColorProperty.setNative](value) {
|
222 | const textView = this._getTextView();
|
223 | const color = value instanceof Color ? value.android : value;
|
224 | textView.setHintTextColor(color);
|
225 | }
|
226 | _getTextView() {
|
227 | if (!this._searchTextView) {
|
228 | const pkgName = this.nativeViewProtected.getContext().getPackageName();
|
229 | const id = this.nativeViewProtected.getContext().getResources().getIdentifier('search_src_text', 'id', pkgName);
|
230 | this._searchTextView = this.nativeViewProtected.findViewById(id);
|
231 | }
|
232 | return this._searchTextView;
|
233 | }
|
234 | _getSearchPlate() {
|
235 | if (!this._searchPlate) {
|
236 | const pkgName = this.nativeViewProtected.getContext().getPackageName();
|
237 | const id = this.nativeViewProtected.getContext().getResources().getIdentifier('search_plate', 'id', pkgName);
|
238 | this._searchPlate = this.nativeViewProtected.findViewById(id);
|
239 | }
|
240 | return this._searchPlate;
|
241 | }
|
242 | }
|
243 |
|
\ | No newline at end of file |