• 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_PATTERN_PROGRESS_LOADING_PROGRESS_PAINT_METHOD_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_PROGRESS_LOADING_PROGRESS_PAINT_METHOD_H
18 
19 #include "base/memory/referenced.h"
20 #include "core/components/common/properties/color.h"
21 #include "core/components/progress/progress_theme.h"
22 #include "core/components_ng/base/modifier.h"
23 #include "core/components_ng/pattern/loading_progress/loading_progress_modifier.h"
24 #include "core/components_ng/pattern/loading_progress/loading_progress_paint_property.h"
25 #include "core/components_ng/pattern/refresh/refresh_animation_state.h"
26 #include "core/components_ng/render/node_paint_method.h"
27 
28 namespace OHOS::Ace::NG {
29 namespace {
30 const int32_t REFRESH_STATE_FOLLOW_HAND = static_cast<int32_t>(RefreshAnimationState::FOLLOW_HAND);
31 const int32_t REFRESH_STATE_FOLLOW_TO_RESYCLE = static_cast<int32_t>(RefreshAnimationState::FOLLOW_TO_RECYCLE);
32 const int32_t REFRESH_STATE_RESYCLE = static_cast<int32_t>(RefreshAnimationState::RECYCLE);
33 const int32_t REFRESH_STATE_FADEAWAY = static_cast<int32_t>(RefreshAnimationState::FADEAWAY);
34 }
35 class ACE_EXPORT LoadingProgressPaintMethod : public NodePaintMethod {
DECLARE_ACE_TYPE(LoadingProgressPaintMethod,NodePaintMethod)36     DECLARE_ACE_TYPE(LoadingProgressPaintMethod, NodePaintMethod)
37 public:
38     explicit LoadingProgressPaintMethod(const RefPtr<LoadingProgressModifier>& loadingProgressModifier)
39         : loadingProgressModifier_(loadingProgressModifier)
40     {}
41     ~LoadingProgressPaintMethod() override = default;
42 
GetContentModifier(PaintWrapper * paintWrapper)43     RefPtr<Modifier> GetContentModifier(PaintWrapper* paintWrapper) override
44     {
45         CHECK_NULL_RETURN(loadingProgressModifier_, nullptr);
46         return loadingProgressModifier_;
47     }
48 
UpdateContentModifier(PaintWrapper * paintWrapper)49     void UpdateContentModifier(PaintWrapper* paintWrapper) override
50     {
51         CHECK_NULL_VOID(loadingProgressModifier_);
52         auto pipeline = PipelineBase::GetCurrentContext();
53         CHECK_NULL_VOID(pipeline);
54         auto progressTheme = pipeline->GetTheme<ProgressTheme>();
55         CHECK_NULL_VOID(progressTheme);
56         auto paintProperty = DynamicCast<LoadingProgressPaintProperty>(paintWrapper->GetPaintProperty());
57         CHECK_NULL_VOID(paintProperty);
58         loadingProgressModifier_->SetEnableLoading(paintProperty->GetEnableLoadingValue(true));
59         loadingProgressModifier_->SetContentOffset(paintWrapper->GetContentOffset());
60         loadingProgressModifier_->SetContentSize(paintWrapper->GetContentSize());
61         auto renderContext = paintWrapper->GetRenderContext();
62         CHECK_NULL_VOID(renderContext);
63         if (renderContext->HasForegroundColorStrategy()) {
64             paintProperty->UpdateColor(Color::FOREGROUND);
65         }
66         color_ = paintProperty->GetColor().value_or(progressTheme->GetLoadingColor());
67         loadingProgressModifier_->SetColor(LinearColor(color_));
68         if (loadingProgressModifier_->GetOwner() == LoadingProgressOwner::SELF) {
69             loadingProgressModifier_->StartRecycle();
70             return;
71         }
72         auto loadingState =
73             paintProperty->GetRefreshAnimationState().value_or(static_cast<int32_t>(RefreshAnimationState::UNKNOWN));
74         switch (loadingState) {
75             case REFRESH_STATE_FOLLOW_HAND:
76                 loadingProgressModifier_->ChangeRefreshFollowData(
77                     paintProperty->GetRefreshFollowRatio().value_or(0.0f));
78                 break;
79             case REFRESH_STATE_FOLLOW_TO_RESYCLE:
80                 loadingProgressModifier_->StartTransToRecycleAnimation();
81                 break;
82             case REFRESH_STATE_RESYCLE:
83                 loadingProgressModifier_->StartRecycle();
84                 break;
85             case REFRESH_STATE_FADEAWAY:
86                 loadingProgressModifier_->ChangeRefreshFollowData(
87                     paintProperty->GetRefreshFadeAwayRatio().value_or(0.0f));
88                 break;
89             default:
90                 break;
91         }
92     }
93 
94 private:
95     Color color_ = Color::BLUE;
96     RefPtr<LoadingProgressModifier> loadingProgressModifier_;
97     ACE_DISALLOW_COPY_AND_MOVE(LoadingProgressPaintMethod);
98 };
99 
100 } // namespace OHOS::Ace::NG
101 
102 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_PROGRESS_LOADING_PROGRESS_PAINT_METHOD_H
103