• 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  constructor(value: ArkConstraintSizeOptions) {
20    super(value);
21  }
22  static identity: Symbol = Symbol('itemConstraintSize');
23  applyPeer(node: KNode, reset: boolean): void {
24    if (reset) {
25      getUINativeModule().waterFlow.resetItemConstraintSize(node);
26    } else {
27      getUINativeModule().waterFlow.setItemConstraintSize(node, this.value.minWidth,
28        this.value.maxWidth, this.value.minHeight, this.value.maxHeight);
29    }
30  }
31  checkObjectDiff(): boolean {
32    return !isBaseOrResourceEqual(this.stageValue.minWidth, this.value.minWidth) ||
33      !isBaseOrResourceEqual(this.stageValue.maxWidth, this.value.maxWidth) ||
34      !isBaseOrResourceEqual(this.stageValue.minHeight, this.value.minHeight) ||
35      !isBaseOrResourceEqual(this.stageValue.maxHeight, this.value.maxHeight);
36  }
37}
38
39class ColumnsTemplateModifier extends ModifierWithKey<string> {
40  constructor(value: string) {
41    super(value);
42  }
43  static identity: Symbol = Symbol('columnsTemplate');
44  applyPeer(node: KNode, reset: boolean): void {
45    if (reset) {
46      getUINativeModule().waterFlow.resetColumnsTemplate(node);
47    } else {
48      getUINativeModule().waterFlow.setColumnsTemplate(node, this.value);
49    }
50  }
51}
52
53class RowsTemplateModifier extends ModifierWithKey<string> {
54  constructor(value: string) {
55    super(value);
56  }
57  static identity: Symbol = Symbol('rowsTemplate');
58  applyPeer(node: KNode, reset: boolean): void {
59    if (reset) {
60      getUINativeModule().waterFlow.resetRowsTemplate(node);
61    } else {
62      getUINativeModule().waterFlow.setRowsTemplate(node, this.value);
63    }
64  }
65}
66
67class EnableScrollInteractionModifier extends ModifierWithKey<boolean> {
68  constructor(value: boolean) {
69    super(value);
70  }
71  static identity = Symbol('enableScrollInteraction');
72  applyPeer(node: KNode, reset: boolean): void {
73    if (reset) {
74      getUINativeModule().waterFlow.resetEnableScrollInteraction(node);
75    } else {
76      getUINativeModule().waterFlow.setEnableScrollInteraction(node, this.value);
77    }
78  }
79}
80
81class WaterFlowClipModifier extends ModifierWithKey<boolean | object> {
82  constructor(value: boolean | object) {
83    super(value);
84  }
85  static identity: Symbol = Symbol('waterFlowclip');
86  applyPeer(node: KNode, reset: boolean): void {
87    if (reset) {
88      getUINativeModule().common.resetClipWithEdge(node);
89    } else {
90      getUINativeModule().common.setClipWithEdge(node, this.value);
91    }
92  }
93
94  checkObjectDiff(): boolean {
95    return true;
96  }
97}
98
99class RowsGapModifier extends ModifierWithKey<number | string> {
100  constructor(value: number | string) {
101    super(value);
102  }
103  static identity: Symbol = Symbol('rowsGap');
104  applyPeer(node: KNode, reset: boolean): void {
105    if (reset) {
106      getUINativeModule().waterFlow.resetRowsGap(node);
107    } else {
108      getUINativeModule().waterFlow.setRowsGap(node, this.value);
109    }
110  }
111  checkObjectDiff(): boolean {
112    return !isBaseOrResourceEqual(this.stageValue, this.value);
113  }
114}
115
116class ColumnsGapModifier extends ModifierWithKey<number | string> {
117  constructor(value: number | string) {
118    super(value);
119  }
120  static identity: Symbol = Symbol('columnsGap');
121  applyPeer(node: KNode, reset: boolean): void {
122    if (reset) {
123      getUINativeModule().waterFlow.resetColumnsGap(node);
124    } else {
125      getUINativeModule().waterFlow.setColumnsGap(node, this.value);
126    }
127  }
128  checkObjectDiff(): boolean {
129    return !isBaseOrResourceEqual(this.stageValue, this.value);
130  }
131}
132
133class LayoutDirectionModifier extends ModifierWithKey<number> {
134  constructor(value: number) {
135    super(value);
136  }
137  static identity: Symbol = Symbol('layoutDirection');
138  applyPeer(node: KNode, reset: boolean): void {
139    if (reset) {
140      getUINativeModule().waterFlow.resetLayoutDirection(node);
141    } else {
142      getUINativeModule().waterFlow.setLayoutDirection(node, this.value);
143    }
144  }
145}
146
147class NestedScrollModifier extends ModifierWithKey<ArkNestedScrollOptions> {
148  constructor(value: ArkNestedScrollOptions) {
149    super(value);
150  }
151  static identity: Symbol = Symbol('nestedScroll');
152  applyPeer(node: KNode, reset: boolean): void {
153    if (reset) {
154      getUINativeModule().waterFlow.resetNestedScroll(node);
155    } else {
156      getUINativeModule().waterFlow.setNestedScroll(node, this.value.scrollForward, this.value.scrollBackward);
157    }
158  }
159}
160
161class FrictionModifier extends ModifierWithKey<number | Resource> {
162  constructor(value: number | Resource) {
163    super(value);
164  }
165  static identity: Symbol = Symbol('friction');
166  applyPeer(node: KNode, reset: boolean): void {
167    if (reset) {
168      getUINativeModule().waterFlow.resetFriction(node);
169    } else {
170      getUINativeModule().waterFlow.setFriction(node, this.value);
171    }
172  }
173  checkObjectDiff(): boolean {
174    return !isBaseOrResourceEqual(this.stageValue, this.value);
175  }
176}
177
178class ArkWaterFlowComponent extends ArkComponent implements WaterFlowAttribute {
179  constructor(nativePtr: KNode) {
180    super(nativePtr);
181  }
182  columnsTemplate(value: string): this {
183    modifierWithKey(this._modifiersWithKeys, ColumnsTemplateModifier.identity, ColumnsTemplateModifier, value);
184    return this;
185  }
186  rowsTemplate(value: string): this {
187    modifierWithKey(this._modifiersWithKeys, RowsTemplateModifier.identity, RowsTemplateModifier, value);
188    return this;
189  }
190  itemConstraintSize(value: ConstraintSizeOptions): this {
191    if (!value) {
192      modifierWithKey(
193        this._modifiersWithKeys, ItemConstraintSizeModifier.identity, ItemConstraintSizeModifier, undefined);
194      return this;
195    }
196    let arkValue: ArkConstraintSizeOptions = new ArkConstraintSizeOptions();
197    arkValue.minWidth = value.minWidth;
198    arkValue.maxWidth = value.maxWidth;
199    arkValue.minHeight = value.minHeight;
200    arkValue.maxHeight = value.maxHeight;
201    modifierWithKey(this._modifiersWithKeys, ItemConstraintSizeModifier.identity, ItemConstraintSizeModifier, arkValue);
202    return this;
203  }
204  columnsGap(value: Length): this {
205    modifierWithKey(this._modifiersWithKeys, ColumnsGapModifier.identity, ColumnsGapModifier, value);
206    return this;
207  }
208  rowsGap(value: Length): this {
209    modifierWithKey(this._modifiersWithKeys, RowsGapModifier.identity, RowsGapModifier, value);
210    return this;
211  }
212  layoutDirection(value: FlexDirection): this {
213    modifierWithKey(this._modifiersWithKeys, LayoutDirectionModifier.identity, LayoutDirectionModifier, value);
214    return this;
215  }
216  nestedScroll(value: NestedScrollOptions): this {
217    let options = new ArkNestedScrollOptions();
218    if (value) {
219      if (value.scrollForward) {
220        options.scrollForward = value.scrollForward;
221      }
222      if (value.scrollBackward) {
223        options.scrollBackward = value.scrollBackward;
224      }
225      modifierWithKey(this._modifiersWithKeys, NestedScrollModifier.identity, NestedScrollModifier, options);
226    }
227    return this;
228  }
229  enableScrollInteraction(value: boolean): this {
230    modifierWithKey(
231      this._modifiersWithKeys, EnableScrollInteractionModifier.identity, EnableScrollInteractionModifier, value);
232    return this;
233  }
234  friction(value: number | Resource): this {
235    modifierWithKey(this._modifiersWithKeys, FrictionModifier.identity, FrictionModifier, value);
236    return this;
237  }
238  cachedCount(value: number): this {
239    throw new Error('Method not implemented.');
240  }
241  onReachStart(event: () => void): this {
242    throw new Error('Method not implemented.');
243  }
244  onReachEnd(event: () => void): this {
245    throw new Error('Method not implemented.');
246  }
247  onScrollFrameBegin(event: (offset: number, state: ScrollState) => { offsetRemain: number; }): this {
248    throw new Error('Method not implemented.');
249  }
250  clip(value: boolean | CircleAttribute | EllipseAttribute | PathAttribute | RectAttribute): this {
251    modifierWithKey(this._modifiersWithKeys, WaterFlowClipModifier.identity, WaterFlowClipModifier, value);
252    return this;
253  }
254}
255
256// @ts-ignore
257globalThis.WaterFlow.attributeModifier = function (modifier) {
258  const elmtId = ViewStackProcessor.GetElmtIdToAccountFor();
259  let nativeNode = getUINativeModule().getFrameNodeById(elmtId);
260  let component = this.createOrGetNode(elmtId, () => {
261    return new ArkWaterFlowComponent(nativeNode);
262  });
263  applyUIAttributes(modifier, nativeNode, component);
264  component.applyModifierPatch();
265};
266