• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2023-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
16const LOADINGPROGRESS_SIZE = 24;
17const DEFAULT_MARGIN = 16;
18const ITEM_SPACE = 4;
19
20export class SwipeRefresher extends ViewPU {
21  constructor(e, t, o, s = -1) {
22    super(e, o, s);
23    this.__content = new SynchedPropertySimpleOneWayPU(t.content, this, "content");
24    this.__isLoading = new SynchedPropertySimpleOneWayPU(t.isLoading, this, "isLoading");
25    this.setInitiallyProvidedValue(t)
26  }
27
28  setInitiallyProvidedValue(e) {
29    void 0 !== e.content ? this.__content.set(e.content) : this.__content.set(null);
30    void 0 !== e.isLoading ? this.__isLoading.set(e.isLoading) : this.__isLoading.set(!1)
31  }
32
33  updateStateVars(e) {
34    this.__content.reset(e.content);
35    this.__isLoading.reset(e.isLoading)
36  }
37
38  purgeVariableDependenciesOnElmtId(e) {
39    this.__content.purgeDependencyOnElmtId(e);
40    this.__isLoading.purgeDependencyOnElmtId(e)
41  }
42
43  aboutToBeDeleted() {
44    this.__content.aboutToBeDeleted();
45    this.__isLoading.aboutToBeDeleted();
46    SubscriberManager.Get().delete(this.id__());
47    this.aboutToBeDeletedInternal()
48  }
49
50  get content() {
51    return this.__content.get()
52  }
53
54  set content(e) {
55    this.__content.set(e)
56  }
57
58  get isLoading() {
59    return this.__isLoading.get()
60  }
61
62  set isLoading(e) {
63    this.__isLoading.set(e)
64  }
65
66  initialRender() {
67    this.observeComponentCreation(((e, t) => {
68      ViewStackProcessor.StartGetAccessRecordingFor(e);
69      Flex.create({ justifyContent: FlexAlign.Center, alignItems: ItemAlign.Center });
70      t || Flex.pop();
71      ViewStackProcessor.StopGetAccessRecording()
72    }));
73    this.observeComponentCreation(((e, t) => {
74      ViewStackProcessor.StartGetAccessRecordingFor(e);
75      If.create();
76      this.isLoading ? this.ifElseBranchUpdateFunction(0, (() => {
77        this.observeComponentCreation(((e, t) => {
78          ViewStackProcessor.StartGetAccessRecordingFor(e);
79          LoadingProgress.create();
80          LoadingProgress.height(24);
81          LoadingProgress.width(24);
82          LoadingProgress.margin({ right: 4 });
83          t || LoadingProgress.pop();
84          ViewStackProcessor.StopGetAccessRecording()
85        }))
86      })) : If.branchId(1);
87      t || If.pop();
88      ViewStackProcessor.StopGetAccessRecording()
89    }));
90    If.pop();
91    this.observeComponentCreation(((e, t) => {
92      ViewStackProcessor.StartGetAccessRecordingFor(e);
93      Text.create(this.content);
94      Text.fontColor({
95        id: -1,
96        type: 10001,
97        params: ["sys.color.ohos_id_color_text_secondary"],
98        bundleName: "",
99        moduleName: ""
100      });
101      Text.fontSize({
102        id: -1,
103        type: 10002,
104        params: ["sys.float.ohos_id_text_size_body2"],
105        bundleName: "",
106        moduleName: ""
107      });
108      Text.padding({ top: 16, bottom: 16 });
109      t || Text.pop();
110      ViewStackProcessor.StopGetAccessRecording()
111    }));
112    Text.pop();
113    Flex.pop()
114  }
115
116  rerender() {
117    this.updateDirtyElements()
118  }
119}
120
121export default { SwipeRefresher };