• 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 ItemConstraintSizeModifier extends ModifierWithKey<ArkConstraintSizeOptions> {
19  static identity: Symbol = Symbol('itemConstraintSize');
20  applyPeer(node: KNode, reset: boolean): void {
21    if (reset) {
22      getUINativeModule().waterFlow.resetItemConstraintSize(node);
23    } else {
24      getUINativeModule().waterFlow.setItemConstraintSize(node, this.value.minWidth,
25        this.value.maxWidth, this.value.minHeight, this.value.maxHeight);
26    }
27  }
28  checkObjectDiff(): boolean {
29    return !isBaseOrResourceEqual(this.stageValue.minWidth, this.value.minWidth) ||
30      !isBaseOrResourceEqual(this.stageValue.maxWidth, this.value.maxWidth) ||
31      !isBaseOrResourceEqual(this.stageValue.minHeight, this.value.minHeight) ||
32      !isBaseOrResourceEqual(this.stageValue.maxHeight, this.value.maxHeight);
33  }
34}
35
36class ColumnsTemplateModifier extends ModifierWithKey<string> {
37  constructor(value: string) {
38    super(value);
39  }
40  static identity: Symbol = Symbol('columnsTemplate');
41  applyPeer(node: KNode, reset: boolean): void {
42    if (reset) {
43      getUINativeModule().waterFlow.resetColumnsTemplate(node);
44    } else {
45      getUINativeModule().waterFlow.setColumnsTemplate(node, this.value);
46    }
47  }
48}
49
50class RowsTemplateModifier extends ModifierWithKey<string> {
51  constructor(value: string) {
52    super(value);
53  }
54  static identity: Symbol = Symbol('rowsTemplate');
55  applyPeer(node: KNode, reset: boolean): void {
56    if (reset) {
57      getUINativeModule().waterFlow.resetRowsTemplate(node);
58    } else {
59      getUINativeModule().waterFlow.setRowsTemplate(node, this.value);
60    }
61  }
62}
63
64class EnableScrollInteractionModifier extends ModifierWithKey<boolean> {
65  constructor(value: boolean) {
66    super(value);
67  }
68  static identity = Symbol('enableScrollInteraction');
69  applyPeer(node: KNode, reset: boolean): void {
70    if (reset) {
71      getUINativeModule().waterFlow.resetEnableScrollInteraction(node);
72    } else {
73      getUINativeModule().waterFlow.setEnableScrollInteraction(node, this.value);
74    }
75  }
76}
77
78class WaterFlowClipModifier extends ModifierWithKey<boolean | object> {
79  constructor(value: boolean | object) {
80    super(value);
81  }
82  static identity: Symbol = Symbol('waterFlowclip');
83  applyPeer(node: KNode, reset: boolean): void {
84    if (reset) {
85      getUINativeModule().common.resetClipWithEdge(node);
86    } else {
87      getUINativeModule().common.setClipWithEdge(node, this.value);
88    }
89  }
90
91  checkObjectDiff(): boolean {
92    return true;
93  }
94}
95
96class RowsGapModifier extends ModifierWithKey<number | string> {
97  static identity: Symbol = Symbol('rowsGap');
98  applyPeer(node: KNode, reset: boolean): void {
99    if (reset) {
100      getUINativeModule().waterFlow.resetRowsGap(node);
101    } else {
102      getUINativeModule().waterFlow.setRowsGap(node, this.value);
103    }
104  }
105  checkObjectDiff(): boolean {
106    return !isBaseOrResourceEqual(this.stageValue, this.value);
107  }
108}
109
110class ColumnsGapModifier extends ModifierWithKey<number | string> {
111  static identity: Symbol = Symbol('columnsGap');
112  applyPeer(node: KNode, reset: boolean): void {
113    if (reset) {
114      getUINativeModule().waterFlow.resetColumnsGap(node);
115    } else {
116      getUINativeModule().waterFlow.setColumnsGap(node, this.value);
117    }
118  }
119  checkObjectDiff(): boolean {
120    return !isBaseOrResourceEqual(this.stageValue, this.value);
121  }
122}
123
124class LayoutDirectionModifier extends ModifierWithKey<number> {
125  constructor(value: number) {
126    super(value);
127  }
128  static identity: Symbol = Symbol('layoutDirection');
129  applyPeer(node: KNode, reset: boolean): void {
130    if (reset) {
131      getUINativeModule().waterFlow.resetLayoutDirection(node);
132    } else {
133      getUINativeModule().waterFlow.setLayoutDirection(node, this.value);
134    }
135  }
136}
137
138class NestedScrollModifier extends ModifierWithKey<ArkNestedScrollOptions> {
139  constructor(value: ArkNestedScrollOptions) {
140    super(value);
141  }
142  static identity: Symbol = Symbol('nestedScroll');
143  applyPeer(node: KNode, reset: boolean): void {
144    if (reset) {
145      getUINativeModule().waterFlow.resetNestedScroll(node);
146    } else {
147      getUINativeModule().waterFlow.setNestedScroll(node, this.value.scrollForward, this.value.scrollBackward);
148    }
149  }
150}
151
152class FrictionModifier extends ModifierWithKey<number | Resource> {
153  static identity: Symbol = Symbol('friction');
154  applyPeer(node: KNode, reset: boolean): void {
155    if (reset) {
156      getUINativeModule().waterFlow.resetFriction(node);
157    } else {
158      getUINativeModule().waterFlow.setFriction(node, this.value);
159    }
160  }
161  checkObjectDiff(): boolean {
162    return !isBaseOrResourceEqual(this.stageValue, this.value);
163  }
164}
165
166class WaterFlowEdgeEffectModifier extends ModifierWithKey<ArkWaterFlowEdgeEffect> {
167  constructor(value: ArkWaterFlowEdgeEffect) {
168    super(value);
169  }
170  static identity: Symbol = Symbol('waterFlowEdgeEffect');
171  applyPeer(node: KNode, reset: boolean): void {
172    if (reset) {
173      getUINativeModule().waterFlow.resetEdgeEffect(node);
174    } else {
175      getUINativeModule().waterFlow.setEdgeEffect(node, this.value?.value, this.value.options?.alwaysEnabled);
176    }
177  }
178
179  checkObjectDiff(): boolean {
180    return !((this.stageValue.value === this.value.value) &&
181      (this.stageValue.options === this.value.options));
182  }
183}
184
185
186class WaterFlowScrollBarWidthModifier extends ModifierWithKey<string | number> {
187  constructor(value: string | number) {
188    super(value);
189  }
190  static identity: Symbol = Symbol('waterFlowScrollBarWidth');
191  applyPeer(node: KNode, reset: boolean): void {
192    if (reset) {
193      getUINativeModule().waterFlow.resetScrollBarWidth(node);
194    } else {
195      getUINativeModule().waterFlow.setScrollBarWidth(node, this.value);
196    }
197  }
198}
199
200class WaterFlowScrollBarModifier extends ModifierWithKey<BarState> {
201  constructor(value: BarState) {
202    super(value);
203  }
204  static identity: Symbol = Symbol('waterFlowScrollBar');
205  applyPeer(node: KNode, reset: boolean): void {
206    if (reset) {
207      getUINativeModule().waterFlow.resetScrollBar(node);
208    } else {
209      getUINativeModule().waterFlow.setScrollBar(node, this.value);
210    }
211  }
212}
213
214class WaterFlowScrollBarColorModifier extends ModifierWithKey<string | number | Color> {
215  constructor(value: string | number | Color) {
216    super(value);
217  }
218  static identity: Symbol = Symbol('waterFlowScrollBarColor');
219  applyPeer(node: KNode, reset: boolean): void {
220    if (reset) {
221      getUINativeModule().waterFlow.resetScrollBarColor(node);
222    } else {
223      getUINativeModule().waterFlow.setScrollBarColor(node, this.value);
224    }
225  }
226}
227
228class WaterFlowCachedCountModifier extends ModifierWithKey<number> {
229  constructor(value: number) {
230    super(value);
231  }
232  static identity: Symbol = Symbol('waterFlowCachedCount');
233  applyPeer(node: KNode, reset: boolean): void {
234    if (reset) {
235      getUINativeModule().waterFlow.resetCachedCount(node);
236    } else {
237      getUINativeModule().waterFlow.setCachedCount(node, this.value);
238    }
239  }
240}
241
242class WaterFlowFlingSpeedLimitModifier extends ModifierWithKey<number> {
243  constructor(value: number) {
244    super(value);
245  }
246  static identity: Symbol = Symbol('waterFlowFlingSpeedLimit');
247  applyPeer(node: KNode, reset: boolean): void {
248    if (reset) {
249      getUINativeModule().waterFlow.resetFlingSpeedLimit(node);
250    } else {
251      getUINativeModule().waterFlow.setFlingSpeedLimit(node, this.value);
252    }
253  }
254}
255
256class WaterFlowInitializeModifier extends ModifierWithKey<WaterFlowParam> {
257  constructor(value: WaterFlowParam) {
258    super(value);
259  }
260  static identity: Symbol = Symbol('waterFlowInitialize');
261  applyPeer(node: KNode, reset: boolean): void {
262    if (reset) {
263      getUINativeModule().waterFlow.resetWaterFlowInitialize(node);
264    } else {
265      getUINativeModule().waterFlow.setWaterFlowInitialize(node,
266        this.value?.scroller, this.value?.sections, this.value?.layoutMode);
267    }
268  }
269}
270
271interface WaterFlowParam {
272  scroller?: Scroller;
273  sections?: WaterFlowSections;
274  layoutMode?: WaterFlowLayoutMode;
275}
276
277class ArkWaterFlowComponent extends ArkComponent implements WaterFlowAttribute {
278  constructor(nativePtr: KNode, classType?: ModifierType) {
279    super(nativePtr, classType);
280  }
281  columnsTemplate(value: string): this {
282    modifierWithKey(this._modifiersWithKeys, ColumnsTemplateModifier.identity, ColumnsTemplateModifier, value);
283    return this;
284  }
285  rowsTemplate(value: string): this {
286    modifierWithKey(this._modifiersWithKeys, RowsTemplateModifier.identity, RowsTemplateModifier, value);
287    return this;
288  }
289  itemConstraintSize(value: ConstraintSizeOptions): this {
290    if (!value) {
291      modifierWithKey(
292        this._modifiersWithKeys, ItemConstraintSizeModifier.identity, ItemConstraintSizeModifier, undefined);
293      return this;
294    }
295    let arkValue: ArkConstraintSizeOptions = new ArkConstraintSizeOptions();
296    arkValue.minWidth = value.minWidth;
297    arkValue.maxWidth = value.maxWidth;
298    arkValue.minHeight = value.minHeight;
299    arkValue.maxHeight = value.maxHeight;
300    modifierWithKey(this._modifiersWithKeys, ItemConstraintSizeModifier.identity, ItemConstraintSizeModifier, arkValue);
301    return this;
302  }
303  columnsGap(value: Length): this {
304    modifierWithKey(this._modifiersWithKeys, ColumnsGapModifier.identity, ColumnsGapModifier, value);
305    return this;
306  }
307  rowsGap(value: Length): this {
308    modifierWithKey(this._modifiersWithKeys, RowsGapModifier.identity, RowsGapModifier, value);
309    return this;
310  }
311  layoutDirection(value: FlexDirection): this {
312    modifierWithKey(this._modifiersWithKeys, LayoutDirectionModifier.identity, LayoutDirectionModifier, value);
313    return this;
314  }
315  nestedScroll(value: NestedScrollOptions): this {
316    let options = new ArkNestedScrollOptions();
317    if (value) {
318      if (value.scrollForward) {
319        options.scrollForward = value.scrollForward;
320      }
321      if (value.scrollBackward) {
322        options.scrollBackward = value.scrollBackward;
323      }
324      modifierWithKey(this._modifiersWithKeys, NestedScrollModifier.identity, NestedScrollModifier, options);
325    }
326    return this;
327  }
328  enableScrollInteraction(value: boolean): this {
329    modifierWithKey(
330      this._modifiersWithKeys, EnableScrollInteractionModifier.identity, EnableScrollInteractionModifier, value);
331    return this;
332  }
333  friction(value: number | Resource): this {
334    modifierWithKey(this._modifiersWithKeys, FrictionModifier.identity, FrictionModifier, value);
335    return this;
336  }
337  cachedCount(value: number): this {
338    modifierWithKey(this._modifiersWithKeys, WaterFlowCachedCountModifier.identity, WaterFlowCachedCountModifier, value);
339    return this;
340  }
341  onReachStart(event: () => void): this {
342    throw new Error('Method not implemented.');
343  }
344  onReachEnd(event: () => void): this {
345    throw new Error('Method not implemented.');
346  }
347  onScrollFrameBegin(event: (offset: number, state: ScrollState) => { offsetRemain: number; }): this {
348    throw new Error('Method not implemented.');
349  }
350  clip(value: boolean | CircleAttribute | EllipseAttribute | PathAttribute | RectAttribute): this {
351    modifierWithKey(this._modifiersWithKeys, WaterFlowClipModifier.identity, WaterFlowClipModifier, value);
352    return this;
353  }
354  edgeEffect(value: EdgeEffect, options?: EdgeEffectOptions | undefined): this {
355    let effect: ArkWaterFlowEdgeEffect = new ArkWaterFlowEdgeEffect();
356    effect.value = value;
357    effect.options = options;
358    modifierWithKey(this._modifiersWithKeys, WaterFlowEdgeEffectModifier.identity, WaterFlowEdgeEffectModifier, effect);
359    return this;
360  }
361  scrollBarWidth(value: string | number): this {
362    modifierWithKey(this._modifiersWithKeys, WaterFlowScrollBarWidthModifier.identity, WaterFlowScrollBarWidthModifier, value);
363    return this;
364  }
365  scrollBarColor(value: string | number | Color): this {
366    modifierWithKey(this._modifiersWithKeys, WaterFlowScrollBarColorModifier.identity, WaterFlowScrollBarColorModifier, value);
367    return this;
368  }
369  scrollBar(value: BarState): this {
370    modifierWithKey(this._modifiersWithKeys, WaterFlowScrollBarModifier.identity, WaterFlowScrollBarModifier, value);
371    return this;
372  }
373  flingSpeedLimit(value: number): this {
374    modifierWithKey(this._modifiersWithKeys, WaterFlowFlingSpeedLimitModifier.identity, WaterFlowFlingSpeedLimitModifier, value);
375    return this;
376  }
377  initialize(value: Object[]): this {
378    if (value[0] !== undefined) {
379      modifierWithKey(this._modifiersWithKeys, WaterFlowInitializeModifier.identity,
380        WaterFlowInitializeModifier, (value[0] as WaterFlowParam));
381    } else {
382      modifierWithKey(this._modifiersWithKeys, WaterFlowInitializeModifier.identity,
383        WaterFlowInitializeModifier, undefined);
384    }
385    return this;
386  }
387  allowChildTypes(): string[] {
388    return ['FlowItem'];
389  }
390}
391
392// @ts-ignore
393globalThis.WaterFlow.attributeModifier = function (modifier: ArkComponent): void {
394  attributeModifierFunc.call(this, modifier, (nativePtr: KNode) => {
395    return new ArkWaterFlowComponent(nativePtr);
396  }, (nativePtr: KNode, classType: ModifierType, modifierJS: ModifierJS) => {
397    return new modifierJS.WaterFlowModifier(nativePtr, classType);
398  });
399};
400