• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2023 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 *     http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16/// <reference path='./import.ts' />
17
18class SearchSelectionMenuHiddenModifier extends ModifierWithKey<boolean> {
19  constructor(value: boolean) {
20    super(value);
21  }
22  static identity = Symbol('searchSelectionMenuHidden');
23  applyPeer(node: KNode, reset: boolean): void {
24    if (reset) {
25      getUINativeModule().search.resetSelectionMenuHidden(node);
26    } else {
27      getUINativeModule().search.setSelectionMenuHidden(node, this.value!);
28    }
29  }
30  checkObjectDiff(): boolean {
31    return this.stageValue !== this.value;
32  }
33}
34
35class SearchCaretStyleModifier extends ModifierWithKey<CaretStyle> {
36  constructor(value: CaretStyle) {
37    super(value);
38  }
39  static identity = Symbol('searchCaretStyle');
40  applyPeer(node: KNode, reset: boolean): void {
41    if (reset) {
42      getUINativeModule().search.resetCaretStyle(node);
43    } else {
44      getUINativeModule().search.setCaretStyle(node, this.value.width,
45        this.value.color);
46    }
47  }
48  checkObjectDiff(): boolean {
49    return !isBaseOrResourceEqual(this.stageValue.width, this.value.width) ||
50      !isBaseOrResourceEqual(this.stageValue.color, this.value.color);
51  }
52}
53
54class SearchEnableKeyboardOnFocusModifier extends ModifierWithKey<boolean> {
55  constructor(value: boolean) {
56    super(value);
57  }
58  static identity = Symbol('searchEnableKeyboardOnFocus');
59  applyPeer(node: KNode, reset: boolean): void {
60    if (reset) {
61      getUINativeModule().search.resetEnableKeyboardOnFocus(node);
62    } else {
63      getUINativeModule().search.setEnableKeyboardOnFocus(node, this.value!);
64    }
65  }
66  checkObjectDiff(): boolean {
67    return this.stageValue !== this.value;
68  }
69}
70
71class SearchSearchIconModifier extends ModifierWithKey<IconOptions> {
72  constructor(value: IconOptions) {
73    super(value);
74  }
75  static identity = Symbol('searchSearchIcon');
76  applyPeer(node: KNode, reset: boolean): void {
77    if (reset) {
78      getUINativeModule().search.resetSearchIcon(node);
79    } else {
80      getUINativeModule().search.setSearchIcon(node, this.value.size,
81        this.value.color, this.value.src);
82    }
83  }
84  checkObjectDiff(): boolean {
85    return !isBaseOrResourceEqual(this.stageValue.size, this.value.size) ||
86      !isBaseOrResourceEqual(this.stageValue.color, this.value.color) ||
87      !isBaseOrResourceEqual(this.stageValue.src, this.value.src);
88  }
89}
90
91class SearchPlaceholderFontModifier extends ModifierWithKey<Font> {
92  constructor(value: Font) {
93    super(value);
94  }
95  static identity = Symbol('searchPlaceholderFont');
96  applyPeer(node: KNode, reset: boolean): void {
97    if (reset) {
98      getUINativeModule().search.resetPlaceholderFont(node);
99    } else {
100      getUINativeModule().search.setPlaceholderFont(node, this.value.size,
101        this.value.weight, this.value.family, this.value.style);
102    }
103  }
104  checkObjectDiff(): boolean {
105    return this.stageValue.weight !== this.value.weight ||
106      this.stageValue.style !== this.value.style ||
107      !isBaseOrResourceEqual(this.stageValue.size, this.value.size) ||
108      !isBaseOrResourceEqual(this.stageValue.family, this.value.family);
109  }
110}
111
112class SearchSearchButtonModifier extends ModifierWithKey<ArkSearchButton> {
113  constructor(value: ArkSearchButton) {
114    super(value);
115  }
116  static identity = Symbol('searchSearchButton');
117  applyPeer(node: KNode, reset: boolean): void {
118    if (reset) {
119      getUINativeModule().search.resetSearchButton(node);
120    } else {
121      getUINativeModule().search.setSearchButton(node, this.value.value,
122        this.value.fontSize, this.value.fontColor);
123    }
124  }
125  checkObjectDiff(): boolean {
126    return this.stageValue.value !== this.value.value ||
127      !isBaseOrResourceEqual(this.stageValue.fontSize, this.value.fontSize) ||
128      !isBaseOrResourceEqual(this.stageValue.fontColor, this.value.fontColor);
129  }
130}
131
132class SearchFontColorModifier extends ModifierWithKey<ResourceColor> {
133  constructor(value: ResourceColor) {
134    super(value);
135  }
136  static identity = Symbol('searchFontColor');
137  applyPeer(node: KNode, reset: boolean): void {
138    if (reset) {
139      getUINativeModule().search.resetFontColor(node);
140    } else {
141      getUINativeModule().search.setFontColor(node, this.value!);
142    }
143  }
144  checkObjectDiff(): boolean {
145    return !isBaseOrResourceEqual(this.stageValue, this.value);
146  }
147}
148
149class SearchCopyOptionModifier extends ModifierWithKey<CopyOptions> {
150  constructor(value: CopyOptions) {
151    super(value);
152  }
153  static identity = Symbol('searchCopyOption');
154  applyPeer(node: KNode, reset: boolean): void {
155    if (reset) {
156      getUINativeModule().search.resetCopyOption(node);
157    } else {
158      getUINativeModule().search.setCopyOption(node, this.value!);
159    }
160  }
161  checkObjectDiff(): boolean {
162    return this.stageValue !== this.value;
163  }
164}
165
166class SearchTextFontModifier extends ModifierWithKey<Font> {
167  constructor(value: Font) {
168    super(value);
169  }
170  static identity = Symbol('searchTextFont');
171  applyPeer(node: KNode, reset: boolean): void {
172    if (reset) {
173      getUINativeModule().search.resetTextFont(node);
174    } else {
175      getUINativeModule().search.setTextFont(node, this.value.size, this.value.weight, this.value.family, this.value.style);
176    }
177  }
178  checkObjectDiff(): boolean {
179    return this.stageValue.weight !== this.value.weight ||
180      this.stageValue.style !== this.value.style ||
181      !isBaseOrResourceEqual(this.stageValue.size, this.value.size) ||
182      !isBaseOrResourceEqual(this.stageValue.family, this.value.family);
183  }
184}
185
186class SearchPlaceholderColorModifier extends ModifierWithKey<ResourceColor> {
187  constructor(value: ResourceColor) {
188    super(value);
189  }
190  static identity = Symbol('searchPlaceholderColor');
191  applyPeer(node: KNode, reset: boolean): void {
192    if (reset) {
193      getUINativeModule().search.resetPlaceholderColor(node);
194    } else {
195      getUINativeModule().search.setPlaceholderColor(node, this.value!);
196    }
197  }
198  checkObjectDiff(): boolean {
199    return !isBaseOrResourceEqual(this.stageValue, this.value);
200  }
201}
202
203class SearchCancelButtonModifier extends ModifierWithKey<{ style?: CancelButtonStyle, icon?: IconOptions }> {
204  constructor(value: { style?: CancelButtonStyle, icon?: IconOptions }) {
205    super(value);
206  }
207  static identity = Symbol('searchCancelButton');
208  applyPeer(node: KNode, reset: boolean): void {
209    if (reset) {
210      getUINativeModule().search.resetCancelButton(node);
211    } else {
212      getUINativeModule().search.setCancelButton(node, this.value.style,
213        this.value.icon?.size, this.value.icon?.color, this.value.icon?.src);
214    }
215  }
216  checkObjectDiff(): boolean {
217    return this.stageValue.style !== this.value.style ||
218      !isBaseOrResourceEqual(this.stageValue.icon?.size, this.value.icon?.size) ||
219      !isBaseOrResourceEqual(this.stageValue.icon?.color, this.value.icon?.color) ||
220      !isBaseOrResourceEqual(this.stageValue.icon?.src, this.value.icon?.src);
221  }
222}
223
224class SearchTextAlignModifier extends ModifierWithKey<TextAlign> {
225  constructor(value: TextAlign) {
226    super(value);
227  }
228  static identity = Symbol('searchTextAlign');
229  applyPeer(node: KNode, reset: boolean): void {
230    if (reset) {
231      getUINativeModule().search.resetTextAlign(node);
232    } else {
233      getUINativeModule().search.setTextAlign(node, this.value!);
234    }
235  }
236  checkObjectDiff(): boolean {
237    return this.stageValue !== this.value;
238  }
239}
240
241class SearchHeightModifier extends ModifierWithKey<Length> {
242  constructor(value: Length) {
243    super(value);
244  }
245  static identity: Symbol = Symbol('searchHeight');
246  applyPeer(node: KNode, reset: boolean): void {
247    if (reset) {
248      getUINativeModule().search.resetSearchHeight(node);
249    } else {
250      getUINativeModule().search.setSearchHeight(node, this.value);
251    }
252  }
253
254  checkObjectDiff(): boolean {
255    return !isBaseOrResourceEqual(this.stageValue, this.value);
256  }
257}
258
259class ArkSearchComponent extends ArkComponent implements CommonMethod<SearchAttribute> {
260  constructor(nativePtr: KNode) {
261    super(nativePtr);
262  }
263  onEditChange(callback: (isEditing: boolean) => void): SearchAttribute {
264    throw new Error('Method not implemented.');
265  }
266  type(value: SearchType): SearchAttribute {
267    throw new Error('Method not implemented.');
268  }
269  maxLength(value: number): SearchAttribute {
270    throw new Error('Method not implemented.');
271  }
272  onEditChanged(callback: (isEditing: boolean) => void): SearchAttribute {
273    throw new Error('Method not implemented.');
274  }
275  customKeyboard(event: () => void): SearchAttribute {
276    throw new Error('Method not implemented.');
277  }
278  showUnit(event: () => void): SearchAttribute {
279    throw new Error('Method not implemented.');
280  }
281  onContentScroll(callback: (totalOffsetX: number, totalOffsetY: number) => void): SearchAttribute {
282    throw new Error('Method not implemented.');
283  }
284  onChange(callback: (value: string) => void): SearchAttribute {
285    throw new Error('Method not implemented.');
286  }
287  onTextSelectionChange(callback: (selectionStart: number, selectionEnd: number) => void): SearchAttribute {
288    throw new Error('Method not implemented.');
289  }
290  onCopy(callback: (value: string) => void): SearchAttribute {
291    throw new Error('Method not implemented.');
292  }
293  onCut(callback: (value: string) => void): SearchAttribute {
294    throw new Error('Method not implemented.');
295  }
296  onSubmit(callback: (value: string) => void): SearchAttribute {
297    throw new Error('Method not implemented.');
298  }
299  onPaste(callback: (value: string) => void): SearchAttribute {
300    throw new Error('Method not implemented.');
301  }
302  showCounter(value: boolean): SearchAttribute {
303    throw new Error('Method not implemented.');
304  }
305  searchButton(value: string, option?: SearchButtonOptions): SearchAttribute {
306    let searchButton = new ArkSearchButton();
307    searchButton.value = value;
308    searchButton.fontColor = option?.fontColor;
309    searchButton.fontSize = option?.fontSize;
310    modifierWithKey(this._modifiersWithKeys, SearchSearchButtonModifier.identity, SearchSearchButtonModifier, searchButton);
311    return this;
312  }
313  selectionMenuHidden(value: boolean): SearchAttribute {
314    modifierWithKey(this._modifiersWithKeys, SearchSelectionMenuHiddenModifier.identity, SearchSelectionMenuHiddenModifier, value);
315    return this;
316  }
317  enableKeyboardOnFocus(value: boolean): SearchAttribute {
318    modifierWithKey(this._modifiersWithKeys, SearchEnableKeyboardOnFocusModifier.identity, SearchEnableKeyboardOnFocusModifier, value);
319    return this;
320  }
321  caretStyle(value: CaretStyle): SearchAttribute {
322    modifierWithKey(this._modifiersWithKeys, SearchCaretStyleModifier.identity, SearchCaretStyleModifier, value);
323    return this;
324  }
325  cancelButton(value: { style?: CancelButtonStyle, icon?: IconOptions }): SearchAttribute {
326    modifierWithKey(this._modifiersWithKeys, SearchCancelButtonModifier.identity, SearchCancelButtonModifier, value);
327    return this;
328  }
329  searchIcon(value: IconOptions): SearchAttribute {
330    modifierWithKey(this._modifiersWithKeys, SearchSearchIconModifier.identity, SearchSearchIconModifier, value);
331    return this;
332  }
333  fontColor(value: ResourceColor): SearchAttribute {
334    modifierWithKey(this._modifiersWithKeys, SearchFontColorModifier.identity, SearchFontColorModifier, value);
335    return this;
336  }
337  placeholderColor(value: ResourceColor): SearchAttribute {
338    modifierWithKey(this._modifiersWithKeys, SearchPlaceholderColorModifier.identity, SearchPlaceholderColorModifier, value);
339    return this;
340  }
341  placeholderFont(value?: Font): SearchAttribute {
342    modifierWithKey(this._modifiersWithKeys, SearchPlaceholderFontModifier.identity, SearchPlaceholderFontModifier, value);
343    return this;
344  }
345  textFont(value?: Font): SearchAttribute {
346    modifierWithKey(this._modifiersWithKeys, SearchTextFontModifier.identity, SearchTextFontModifier, value);
347    return this;
348  }
349  copyOption(value: CopyOptions): SearchAttribute {
350    modifierWithKey(this._modifiersWithKeys, SearchCopyOptionModifier.identity, SearchCopyOptionModifier, value);
351    return this;
352  }
353  textAlign(value: TextAlign): SearchAttribute {
354    modifierWithKey(this._modifiersWithKeys, SearchTextAlignModifier.identity, SearchTextAlignModifier, value);
355    return this;
356  }
357  height(value: Length): this {
358    modifierWithKey(this._modifiersWithKeys, SearchHeightModifier.identity, SearchHeightModifier, value);
359    return this;
360  }
361}
362// @ts-ignore
363globalThis.Search.attributeModifier = function (modifier) {
364  const elmtId = ViewStackProcessor.GetElmtIdToAccountFor();
365  let nativeNode = getUINativeModule().getFrameNodeById(elmtId);
366  let component = this.createOrGetNode(elmtId, () => {
367    return new ArkSearchComponent(nativeNode);
368  });
369  applyUIAttributes(modifier, nativeNode, component);
370  component.applyModifierPatch();
371};