1 /* 2 * Copyright (c) 2022-2025 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 class ACE_EXPORT LoadingProgressPaintMethod : public NodePaintMethod { 30 DECLARE_ACE_TYPE(LoadingProgressPaintMethod, NodePaintMethod); 31 public: LoadingProgressPaintMethod(const RefPtr<LoadingProgressModifier> & loadingProgressModifier)32 explicit LoadingProgressPaintMethod(const RefPtr<LoadingProgressModifier>& loadingProgressModifier) 33 : loadingProgressModifier_(loadingProgressModifier) 34 {} 35 ~LoadingProgressPaintMethod() override = default; 36 GetContentModifier(PaintWrapper * paintWrapper)37 RefPtr<Modifier> GetContentModifier(PaintWrapper* paintWrapper) override 38 { 39 CHECK_NULL_RETURN(loadingProgressModifier_, nullptr); 40 return loadingProgressModifier_; 41 } 42 UpdateContentModifier(PaintWrapper * paintWrapper)43 void UpdateContentModifier(PaintWrapper* paintWrapper) override 44 { 45 CHECK_NULL_VOID(loadingProgressModifier_); 46 auto pipeline = PipelineBase::GetCurrentContext(); 47 CHECK_NULL_VOID(pipeline); 48 auto paintProperty = DynamicCast<LoadingProgressPaintProperty>(paintWrapper->GetPaintProperty()); 49 CHECK_NULL_VOID(paintProperty); 50 auto host = paintProperty->GetHost(); 51 auto themeScopeId = host ? host->GetThemeScopeId() : 0; 52 auto progressTheme = pipeline->GetTheme<ProgressTheme>(themeScopeId); 53 CHECK_NULL_VOID(progressTheme); 54 loadingProgressModifier_->SetEnableLoading(paintProperty->GetEnableLoadingValue(true)); 55 loadingProgressModifier_->SetContentOffset(paintWrapper->GetContentOffset()); 56 loadingProgressModifier_->SetContentSize(paintWrapper->GetContentSize()); 57 auto renderContext = paintWrapper->GetRenderContext(); 58 CHECK_NULL_VOID(renderContext); 59 if (renderContext->HasForegroundColorStrategy()) { 60 paintProperty->UpdateColor(Color::FOREGROUND); 61 } 62 if (!loadingProgressModifier_->GetForegroundColorParseFailed() || themeScopeId) { 63 color_ = paintProperty->GetColor().value_or(progressTheme->GetLoadingColor()); 64 loadingProgressModifier_->SetColor(LinearColor(color_)); 65 } 66 if (loadingProgressModifier_->GetOwner() == LoadingProgressOwner::SELF) { 67 loadingProgressModifier_->ChangeSizeScaleData(1.0f); 68 loadingProgressModifier_->StartRecycle(); 69 return; 70 } 71 auto loadingState = paintProperty->GetRefreshAnimationState().value_or(RefreshAnimationState::FOLLOW_HAND); 72 switch (loadingState) { 73 case RefreshAnimationState::FOLLOW_HAND: 74 loadingProgressModifier_->ChangeRefreshFollowData( 75 paintProperty->GetRefreshSizeScaleRatio().value_or(1.0f)); 76 break; 77 case RefreshAnimationState::FOLLOW_TO_RECYCLE: 78 loadingProgressModifier_->StartTransToRecycleAnimation(); 79 break; 80 case RefreshAnimationState::RECYCLE: 81 loadingProgressModifier_->ChangeSizeScaleData(paintProperty->GetRefreshSizeScaleRatio().value_or(1.0f)); 82 loadingProgressModifier_->StartRecycle(); 83 break; 84 default: 85 break; 86 } 87 } 88 89 private: 90 Color color_ = Color::BLUE; 91 RefPtr<LoadingProgressModifier> loadingProgressModifier_; 92 ACE_DISALLOW_COPY_AND_MOVE(LoadingProgressPaintMethod); 93 }; 94 95 } // namespace OHOS::Ace::NG 96 97 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_PROGRESS_LOADING_PROGRESS_PAINT_METHOD_H 98