1 /*
2  * Copyright (c) 2022 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 #ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_REFRESH_MODEL_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_REFRESH_MODEL_H
18 
19 #include <mutex>
20 #include <string>
21 
22 #include "frameworks/base/geometry/dimension.h"
23 #include "frameworks/base/utils/macros.h"
24 #include "frameworks/core/components/common/properties/color.h"
25 #include "frameworks/core/components_ng/pattern/refresh/refresh_pattern.h"
26 
27 namespace OHOS::Ace {
28 
29 class ACE_FORCE_EXPORT RefreshModel {
30 public:
31     static RefreshModel* GetInstance();
32     virtual ~RefreshModel() = default;
33 
34     virtual void Create() = 0;
35     virtual void Pop() = 0;
36     virtual void SetRefreshing(bool isRefreshing) = 0;
37     virtual void SetRefreshDistance(const Dimension& refreshDistance) = 0;
38     virtual void SetUseOffset(bool isUseOffset) = 0;
39     virtual void SetIndicatorOffset(const Dimension& indicatorOffset) = 0;
40     virtual void SetFriction(int32_t friction) = 0;
41     virtual void IsRefresh(bool isRefresh) = 0;
42 
43     virtual void SetLoadingDistance(const Dimension& loadingDistance) = 0;
44     virtual void SetProgressDistance(const Dimension& progressDistance) = 0;
45     virtual void SetProgressDiameter(const Dimension& progressDiameter) = 0;
46     virtual void SetMaxDistance(const Dimension& maxDistance) = 0;
47     virtual void SetIsShowLastTime(bool IsShowLastTime) = 0;
48     virtual void SetShowTimeDistance(const Dimension& showTimeDistance) = 0;
49 
50     virtual void SetTextStyle(const TextStyle& textStyle) = 0;
51     virtual void SetProgressColor(const Color& progressColor) = 0;
52     virtual void SetProgressBackgroundColor(const Color& backgroundColor) = 0;
53     virtual void SetOnStateChange(std::function<void(const int32_t)>&& stateChange) = 0;
54     virtual void SetOnRefreshing(std::function<void()>&& refreshing) = 0;
55     virtual void SetOnOffsetChange(std::function<void(const float)>&& dragOffset) = 0;
56     virtual void ResetOnOffsetChange() = 0;
SetPullDownRatio(const std::optional<float> & pullDownRatio)57     virtual void SetPullDownRatio(const std::optional<float>& pullDownRatio) {}
58     virtual void SetChangeEvent(std::function<void(const std::string)>&& changeEvent) = 0;
59     virtual void SetCustomBuilder(const RefPtr<NG::UINode>& customBuilder) = 0;
60     virtual void SetLoadingText(const std::string& loadingText) = 0;
ResetLoadingText()61     virtual void ResetLoadingText() {}
62     virtual void SetRefreshOffset(const Dimension& offset) = 0;
63     virtual void SetPullToRefresh(bool isPullToRefresh) = 0;
SetIsCustomBuilderExist(bool isCustomBuilderExist)64     virtual void SetIsCustomBuilderExist(bool isCustomBuilderExist) {}
65 
66 private:
67     static std::unique_ptr<RefreshModel> instance_;
68     static std::mutex mutex_;
69 };
70 } // namespace OHOS::Ace
71 
72 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_REFRESH_MODEL_H
73