• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-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 #ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_LOADING_PROGRESS_LOADING_PROGRESS_PAINT_PROPERTY_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_LOADING_PROGRESS_LOADING_PROGRESS_PAINT_PROPERTY_H
18 
19 #include "base/geometry/dimension.h"
20 #include "core/components/progress/progress_theme.h"
21 #include "core/components_ng/pattern/loading_progress/loading_progress_owner.h"
22 #include "core/components_ng/pattern/loading_progress/loading_progress_style.h"
23 #include "core/components_ng/property/property.h"
24 #include "core/components_ng/render/paint_property.h"
25 #include "core/pipeline_ng/pipeline_context.h"
26 
27 namespace OHOS::Ace::NG {
28 
29 class ACE_EXPORT LoadingProgressPaintProperty : public PaintProperty {
30     DECLARE_ACE_TYPE(LoadingProgressPaintProperty, PaintProperty);
31 
32 public:
33     LoadingProgressPaintProperty() = default;
34 
35     ~LoadingProgressPaintProperty() override = default;
36 
Clone()37     RefPtr<PaintProperty> Clone() const override
38     {
39         auto paintProperty = MakeRefPtr<LoadingProgressPaintProperty>();
40         paintProperty->propColor_ = CloneColor();
41         paintProperty->propEnableLoading_ = CloneEnableLoading();
42         paintProperty->propLoadingProgressOwner_ = CloneLoadingProgressOwner();
43         paintProperty->propRefreshAnimationState_ = CloneRefreshAnimationState();
44         paintProperty->propRefreshFollowRatio_ = CloneRefreshFollowRatio();
45         paintProperty->propRefreshTransitionRatio_ = CloneRefreshTransitionRatio();
46         paintProperty->propRefreshFadeAwayRatio_ = CloneRefreshFadeAwayRatio();
47         return paintProperty;
48     }
49 
Reset()50     void Reset() override
51     {
52         PaintProperty::Reset();
53         ResetColor();
54         ResetEnableLoading();
55         ResetLoadingProgressOwner();
56         ResetRefreshAnimationState();
57         ResetRefreshFollowRatio();
58         ResetRefreshTransitionRatio();
59         ResetRefreshFadeAwayRatio();
60     }
61 
ToJsonValue(std::unique_ptr<JsonValue> & json)62     void ToJsonValue(std::unique_ptr<JsonValue>& json) const override
63     {
64         PaintProperty::ToJsonValue(json);
65 
66         auto pipeline = PipelineBase::GetCurrentContext();
67         CHECK_NULL_VOID(pipeline);
68         auto progressTheme = pipeline->GetTheme<ProgressTheme>();
69         CHECK_NULL_VOID(progressTheme);
70 
71         json->Put("color", propColor_.value_or(progressTheme->GetLoadingColor()).ColorToString().c_str());
72         json->Put("enableLoading", GetEnableLoading().value_or(true) ? "true" : "false");
73     }
74 
75     ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(Color, Color, PROPERTY_UPDATE_RENDER);
76     ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(EnableLoading, bool, PROPERTY_UPDATE_RENDER);
77     ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(LoadingProgressOwner, LoadingProgressOwner, PROPERTY_UPDATE_RENDER);
78     ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(RefreshAnimationState, int32_t, PROPERTY_UPDATE_RENDER);
79     ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(RefreshFollowRatio, float, PROPERTY_UPDATE_RENDER);
80     ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(RefreshTransitionRatio, float, PROPERTY_UPDATE_RENDER);
81     ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(RefreshFadeAwayRatio, float, PROPERTY_UPDATE_RENDER);
82 };
83 } // namespace OHOS::Ace::NG
84 
85 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_LOADING_PROGRESS_LOADING_PROGRESS_PAINT_PROPERTY_H
86