• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2024 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
16const __ArcList__ = requireInternal('arkui.ArcList');
17const ModifierMap = requireNapi('arkui.modifier').ModifierMap;
18const ModifierUtils = requireNapi('arkui.modifier').ModifierUtils;
19const LengthUnit = requireNapi('arkui.node').LengthUnit;
20
21class ArcListChildrenMainSizeModifier extends ModifierWithKey {
22    static identity = Symbol('childrenMainSize');
23    constructor(value) {
24        super(value);
25    }
26    applyPeer(node, reset) {
27        if (reset || !this.value) {
28            __ArcList__.modifier.resetChildrenMainSize(node);
29        }
30        else {
31            __ArcList__.modifier.setChildrenMainSize(node, this.value.defaultMainSize, this.value.sizeArray);
32        }
33    }
34    checkObjectDiff() {
35        if (!this.stageValue && !this.value) {
36            return false;
37        } else if (this.stageValue && this.value) {
38            if (this.stageValue.defaultMainSize !== this.value.defaultMainSize ||
39                this.stageValue.sizeArray.length !== this.value.sizeArray.length ||
40                !this.stageValue.sizeArray.every((v, i) => v === this.value.sizeArray[i])) {
41                return true;
42            }
43            return false;
44        }
45        return true;
46    }
47}
48
49class ArcListScrollBarWidthModifier extends ModifierWithKey {
50    static identity = Symbol('scrollBarWidth');
51    constructor(value) {
52        super(value);
53    }
54    applyPeer(node, reset) {
55        if (reset || !this.value) {
56            getUINativeModule().list.resetListScrollBarWidth(node);
57        }
58        else {
59            let width = `${this.value.value}${LengthUnit[this.value.unit]}`;
60            getUINativeModule().list.setListScrollBarWidth(node, width);
61        }
62    }
63    checkObjectDiff() {
64        if (!this.stageValue && !this.value) {
65            return false;
66        } else if (this.stageValue && this.value) {
67            if (this.stageValue.value !== this.value.value ||
68                this.stageValue.unit !== this.value.unit) {
69                return true;
70            }
71            return false;
72        }
73        return true;
74    }
75}
76
77class ArcListScrollBarColorModifier extends ModifierWithKey {
78    static identity = Symbol('scrollBarColor');
79    constructor(value) {
80        super(value);
81    }
82    applyPeer(node, reset) {
83        if (reset || !this.value) {
84            getUINativeModule().list.resetListScrollBarColor(node);
85        }
86        else {
87            getUINativeModule().list.setListScrollBarColor(node, this.value.color);
88        }
89    }
90    checkObjectDiff() {
91        if (!this.stageValue && !this.value) {
92            return false;
93        } else if (this.stageValue && this.value) {
94            return this.stageValue.color !== this.value.color;
95        }
96        return true;
97    }
98}
99
100class ArcListSpaceModifier extends ModifierWithKey {
101    static identity = Symbol('space');
102    constructor(value) {
103        super(value);
104    }
105    applyPeer(node, reset) {
106        if (reset || !this.value) {
107            __ArcList__.modifier.resetSpace(node);
108        }
109        else {
110            __ArcList__.modifier.setSpace(node, this.value);
111        }
112    }
113    checkObjectDiff() {
114        if (!this.stageValue && !this.value) {
115            return false;
116        } else if (this.stageValue && this.value) {
117            if (this.stageValue.value !== this.value.value ||
118                this.stageValue.unit !== this.value.unit) {
119                return true;
120            }
121            return false;
122        }
123        return true;
124    }
125}
126
127class ArcListDigitalCrownSensitivityModifier extends ModifierWithKey {
128    static identity = Symbol('digitalCrownSensitivity');
129    constructor(value) {
130        super(value);
131    }
132    applyPeer(node, reset) {
133        if (reset || this.value === undefined) {
134            __ArcList__.modifier.resetDigitalCrownSensitivity(node);
135        }
136        else {
137            __ArcList__.modifier.setDigitalCrownSensitivity(node, this.value);
138        }
139    }
140}
141
142class ArcListComponent extends ArkListComponent {
143    constructor(nativePtr, classType) {
144        super(nativePtr, classType);
145    }
146    digitalCrownSensitivity(sensitivity) {
147        modifierWithKey(this._modifiersWithKeys, ArcListDigitalCrownSensitivityModifier.identity, ArcListDigitalCrownSensitivityModifier, sensitivity);
148        return this;
149    }
150    space(space) {
151        modifierWithKey(this._modifiersWithKeys, ArcListSpaceModifier.identity, ArcListSpaceModifier, space);
152        return this;
153    }
154    scrollBarColor(color) {
155        modifierWithKey(this._modifiersWithKeys, ArcListScrollBarColorModifier.identity, ArcListScrollBarColorModifier, color);
156        return this;
157    }
158    scrollBarWidth(width) {
159        modifierWithKey(this._modifiersWithKeys, ArcListScrollBarWidthModifier.identity, ArcListScrollBarWidthModifier, width);
160        return this;
161    }
162    childrenMainSize(size) {
163        modifierWithKey(this._modifiersWithKeys, ArcListChildrenMainSizeModifier.identity, ArcListChildrenMainSizeModifier, size);
164        return this;
165    }
166}
167
168class ArcListModifier extends ArcListComponent {
169    constructor(nativePtr, classType) {
170        super(nativePtr, classType);
171        this._modifiersWithKeys = new ModifierMap();
172    }
173    applyNormalAttribute(instance) {
174        ModifierUtils.applySetOnChange(this);
175        ModifierUtils.applyAndMergeModifier(instance, this);
176    }
177}
178
179class ArcList extends List {
180    static attributeModifier(modifier) {
181        attributeModifierFunc.call(this, modifier, (nativePtr) => {
182            return new ArcListComponent(nativePtr);
183        }, (nativePtr, classType, modifierJS) => {
184            return new ArcListModifier(nativePtr, classType);
185        });
186    }
187
188    static create(value) {
189        __ArcList__.create(value);
190    }
191
192    static space(value) {
193        __ArcList__.space(value);
194    }
195
196    static scrollBarWidth(value) {
197        if (value) {
198            value = `${value.value}${LengthUnit[value.unit]}`;
199        }
200        List.scrollBarWidth(value);
201    }
202
203    static scrollBarColor(value) {
204        if (value) {
205            value = value.color;
206        }
207        List.scrollBarColor(value);
208    }
209
210    static digitalCrownSensitivity(value) {
211        __ArcList__.digitalCrownSensitivity(value);
212    }
213}
214
215class ArcListItemAutoScaleModifier extends ModifierWithKey {
216    static identity = Symbol('autoScale');
217    constructor(value) {
218        super(value);
219    }
220    applyPeer(node, reset) {
221        if (reset || this.value === undefined) {
222            __ArcList__.item.modifier.resetAutoScale(node);
223        } else {
224            __ArcList__.item.modifier.setAutoScale(node, this.value);
225        }
226    }
227}
228
229class ArcListItemComponent extends ArkListItemComponent {
230    constructor(nativePtr, classType) {
231        super(nativePtr, classType);
232    }
233    autoScale(enable) {
234        modifierWithKey(this._modifiersWithKeys, ArcListItemAutoScaleModifier.identity, ArcListItemAutoScaleModifier, enable);
235        return this;
236    }
237}
238
239class ArcListItemModifier extends ArcListItemComponent {
240    constructor(nativePtr, classType) {
241        super(nativePtr, classType);
242        this._modifiersWithKeys = new ModifierMap();
243    }
244    applyNormalAttribute(instance) {
245        ModifierUtils.applySetOnChange(this);
246        ModifierUtils.applyAndMergeModifier(instance, this);
247    }
248}
249
250class ArcListItem extends ListItem {
251    static attributeModifier(modifier) {
252        attributeModifierFunc.call(this, modifier, (nativePtr) => {
253            return new ArcListItemComponent(nativePtr);
254        }, (nativePtr, classType, modifierJS) => {
255            return new ArcListItemModifier(nativePtr, classType);
256        });
257    }
258
259    static create(deepRenderFunction, isLazy, options) {
260        if (isLazy === false) {
261            __ArcList__.item.createInternal(deepRenderFunction, isLazy, options);
262            return;
263        }
264        const listItemElmtId = ViewStackProcessor.GetElmtIdToAccountFor();
265        const themeScope = ArkThemeScopeManager.getInstance().scopeForElmtId(listItemElmtId);
266        if (themeScope === undefined) {
267            __ArcList__.item.createInternal(deepRenderFunction, isLazy, options);
268            return;
269        }
270        const deepRenderFunctionWrapper = (elmtId, isInitialRender) => {
271            const result = ArkThemeScopeManager.getInstance().onDeepRenderScopeEnter(themeScope);
272            deepRenderFunction(elmtId, isInitialRender);
273            if (result === true) {
274                ArkThemeScopeManager.getInstance().onDeepRenderScopeExit();
275            }
276        };
277        __ArcList__.item.createInternal(deepRenderFunctionWrapper, isLazy, options);
278    }
279
280    static autoScale(value) {
281        __ArcList__.item.autoScale(value);
282    }
283}
284
285export default {
286    ArcList,
287    ArcListItem,
288};
289