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_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 color_ = paintProperty->GetColor().value_or(progressTheme->GetLoadingColor()); 59 loadingProgressModifier_->SetColor(LinearColor(color_)); 60 if (loadingProgressModifier_->GetOwner() == LoadingProgressOwner::SELF) { 61 loadingProgressModifier_->StartRecycle(); 62 return; 63 } 64 auto loadingState = 65 paintProperty->GetRefreshAnimationState().value_or(static_cast<int32_t>(RefreshAnimationState::UNKNOWN)); 66 switch (loadingState) { 67 case REFRESH_STATE_FOLLOW_HAND: 68 loadingProgressModifier_->ChangeRefreshFollowData( 69 paintProperty->GetRefreshFollowRatio().value_or(0.0f)); 70 break; 71 case REFRESH_STATE_FOLLOW_TO_RESYCLE: 72 loadingProgressModifier_->StartTransToRecycleAnimation(); 73 break; 74 case REFRESH_STATE_RESYCLE: 75 loadingProgressModifier_->StartRecycle(); 76 break; 77 case REFRESH_STATE_FADEAWAY: 78 loadingProgressModifier_->ChangeRefreshFollowData( 79 paintProperty->GetRefreshFadeAwayRatio().value_or(0.0f)); 80 break; 81 default:; 82 } 83 } 84 85 private: 86 Color color_ = Color::BLUE; 87 RefPtr<LoadingProgressModifier> loadingProgressModifier_; 88 ACE_DISALLOW_COPY_AND_MOVE(LoadingProgressPaintMethod); 89 }; 90 91 } // namespace OHOS::Ace::NG 92 93 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_PROGRESS_LOADING_PROGRESS_PAINT_METHOD_H 94