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 class ACE_EXPORT LoadingProgressPaintMethod : public NodePaintMethod { DECLARE_ACE_TYPE(LoadingProgressPaintMethod,NodePaintMethod)30 DECLARE_ACE_TYPE(LoadingProgressPaintMethod, NodePaintMethod) 31 public: 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 progressTheme = pipeline->GetTheme<ProgressTheme>(); 49 CHECK_NULL_VOID(progressTheme); 50 auto paintProperty = DynamicCast<LoadingProgressPaintProperty>(paintWrapper->GetPaintProperty()); 51 CHECK_NULL_VOID(paintProperty); 52 loadingProgressModifier_->SetEnableLoading(paintProperty->GetEnableLoadingValue(true)); 53 loadingProgressModifier_->SetContentOffset(paintWrapper->GetContentOffset()); 54 loadingProgressModifier_->SetContentSize(paintWrapper->GetContentSize()); 55 auto renderContext = paintWrapper->GetRenderContext(); 56 CHECK_NULL_VOID(renderContext); 57 if (renderContext->HasForegroundColorStrategy()) { 58 paintProperty->UpdateColor(Color::FOREGROUND); 59 } 60 color_ = paintProperty->GetColor().value_or(progressTheme->GetLoadingColor()); 61 loadingProgressModifier_->SetColor(LinearColor(color_)); 62 if (loadingProgressModifier_->GetOwner() == LoadingProgressOwner::SELF) { 63 loadingProgressModifier_->ChangeSizeScaleData(1.0f); 64 loadingProgressModifier_->StartRecycle(); 65 return; 66 } 67 auto loadingState = paintProperty->GetRefreshAnimationState().value_or(RefreshAnimationState::FOLLOW_HAND); 68 switch (loadingState) { 69 case RefreshAnimationState::FOLLOW_HAND: 70 loadingProgressModifier_->ChangeRefreshFollowData( 71 paintProperty->GetRefreshSizeScaleRatio().value_or(1.0f)); 72 break; 73 case RefreshAnimationState::FOLLOW_TO_RECYCLE: 74 loadingProgressModifier_->StartTransToRecycleAnimation(); 75 break; 76 case RefreshAnimationState::RECYCLE: 77 loadingProgressModifier_->ChangeSizeScaleData(paintProperty->GetRefreshSizeScaleRatio().value_or(1.0f)); 78 loadingProgressModifier_->StartRecycle(); 79 break; 80 default: 81 break; 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