• 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' />
17class ArkLoadingProgressComponent extends ArkComponent implements LoadingProgressAttribute {
18  constructor(nativePtr: KNode) {
19    super(nativePtr);
20  }
21  onGestureJudgeBegin(callback: (gestureInfo: GestureInfo, event: BaseGestureEvent) => GestureJudgeResult): this {
22    throw new Error('Method not implemented.');
23  }
24  color(value: ResourceColor): this {
25    modifierWithKey(this._modifiersWithKeys, LoadingProgressColorModifier.identity, LoadingProgressColorModifier, value);
26    return this;
27  }
28  enableLoading(value: boolean): this {
29    modifierWithKey(this._modifiersWithKeys, LoadingProgressEnableLoadingModifier.identity, LoadingProgressEnableLoadingModifier, value);
30    return this;
31  }
32  foregroundColor(value: ResourceColor): this {
33    modifierWithKey(this._modifiersWithKeys, LoadingProgressForegroundColorModifier.identity,
34      LoadingProgressForegroundColorModifier, value);
35    return this;
36  }
37}
38
39class LoadingProgressColorModifier extends ModifierWithKey<ResourceColor> {
40  constructor(value: ResourceColor) {
41    super(value);
42  }
43  static identity: Symbol = Symbol('loadingProgressColor');
44  applyPeer(node: KNode, reset: boolean): void {
45    if (reset) {
46      getUINativeModule().loadingProgress.resetColor(node);
47    } else {
48      getUINativeModule().loadingProgress.setColor(node, this.value);
49    }
50  }
51
52  checkObjectDiff(): boolean {
53    return !isBaseOrResourceEqual(this.stageValue, this.value);
54  }
55}
56
57class LoadingProgressForegroundColorModifier extends ModifierWithKey<ResourceColor> {
58  constructor(value: ResourceColor) {
59    super(value);
60  }
61  static identity: Symbol = Symbol('loadingProgressForegroundColor');
62  applyPeer(node: KNode, reset: boolean): void {
63    if (reset) {
64      getUINativeModule().loadingProgress.resetForegroundColor(node);
65    } else {
66      getUINativeModule().loadingProgress.setForegroundColor(node, this.value);
67    }
68  }
69  checkObjectDiff(): boolean {
70    return !isBaseOrResourceEqual(this.stageValue, this.value);
71  }
72}
73
74class LoadingProgressEnableLoadingModifier extends ModifierWithKey<boolean> {
75  constructor(value: boolean) {
76    super(value);
77  }
78  static identity: Symbol = Symbol('loadingProgressEnableLoading');
79  applyPeer(node: KNode, reset: boolean): void {
80    if (reset) {
81      getUINativeModule().loadingProgress.resetEnableLoading(node);
82    } else {
83      getUINativeModule().loadingProgress.setEnableLoading(node, this.value);
84    }
85  }
86}
87
88// @ts-ignore
89globalThis.LoadingProgress.attributeModifier = function (modifier) {
90  const elmtId = ViewStackProcessor.GetElmtIdToAccountFor();
91  let nativeNode = getUINativeModule().getFrameNodeById(elmtId);
92  let component = this.createOrGetNode(elmtId, () => {
93    return new ArkLoadingProgressComponent(nativeNode);
94  });
95  applyUIAttributes(modifier, nativeNode, component);
96  component.applyModifierPatch();
97};
98