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 #include "frameworks/bridge/declarative_frontend/jsview/models/refresh_model_impl.h" 17 18 #include <utility> 19 20 #include "frameworks/base/utils/utils.h" 21 #include "frameworks/bridge/declarative_frontend/jsview/js_container_base.h" 22 #include "frameworks/bridge/declarative_frontend/view_stack_processor.h" 23 24 namespace OHOS::Ace::Framework { 25 Create()26void RefreshModelImpl::Create() 27 { 28 auto refreshComponent = AceType::MakeRefPtr<RefreshComponent>(); 29 ViewStackProcessor::GetInstance()->ClaimElementId(refreshComponent); 30 ViewStackProcessor::GetInstance()->Push(refreshComponent); 31 } 32 GetComponent()33RefPtr<RefreshComponent> RefreshModelImpl::GetComponent() 34 { 35 auto* stack = ViewStackProcessor::GetInstance(); 36 if (!stack) { 37 return nullptr; 38 } 39 auto component = AceType::DynamicCast<RefreshComponent>(stack->GetMainComponent()); 40 return component; 41 } 42 Pop()43void RefreshModelImpl::Pop() 44 { 45 JSContainerBase::Pop(); 46 } 47 SetRefreshing(bool isRefreshing)48void RefreshModelImpl::SetRefreshing(bool isRefreshing) 49 { 50 auto component = GetComponent(); 51 CHECK_NULL_VOID(component); 52 53 component->SetRefreshing(isRefreshing); 54 } 55 SetRefreshDistance(const Dimension & refreshDistance)56void RefreshModelImpl::SetRefreshDistance(const Dimension& refreshDistance) 57 { 58 auto component = GetComponent(); 59 CHECK_NULL_VOID(component); 60 61 component->SetRefreshDistance(refreshDistance); 62 } 63 SetUseOffset(bool isUseOffset)64void RefreshModelImpl::SetUseOffset(bool isUseOffset) 65 { 66 auto component = GetComponent(); 67 CHECK_NULL_VOID(component); 68 69 component->SetUseOffset(isUseOffset); 70 } 71 SetIndicatorOffset(const Dimension & indicatorOffset)72void RefreshModelImpl::SetIndicatorOffset(const Dimension& indicatorOffset) 73 { 74 auto component = GetComponent(); 75 CHECK_NULL_VOID(component); 76 77 component->SetIndicatorOffset(indicatorOffset); 78 } 79 SetFriction(int32_t friction)80void RefreshModelImpl::SetFriction(int32_t friction) 81 { 82 auto component = GetComponent(); 83 CHECK_NULL_VOID(component); 84 85 component->SetFriction(friction); 86 } 87 IsRefresh(bool isRefresh)88void RefreshModelImpl::IsRefresh(bool isRefresh) 89 { 90 auto component = GetComponent(); 91 CHECK_NULL_VOID(component); 92 93 component->IsRefresh(isRefresh); 94 } 95 SetLoadingDistance(const Dimension & loadingDistance)96void RefreshModelImpl::SetLoadingDistance(const Dimension& loadingDistance) 97 { 98 auto component = GetComponent(); 99 CHECK_NULL_VOID(component); 100 101 component->SetLoadingDistance(loadingDistance); 102 } 103 SetProgressDistance(const Dimension & progressDistance)104void RefreshModelImpl::SetProgressDistance(const Dimension& progressDistance) 105 { 106 auto component = GetComponent(); 107 CHECK_NULL_VOID(component); 108 109 component->SetProgressDistance(progressDistance); 110 } 111 SetProgressDiameter(const Dimension & progressDiameter)112void RefreshModelImpl::SetProgressDiameter(const Dimension& progressDiameter) 113 { 114 auto component = GetComponent(); 115 CHECK_NULL_VOID(component); 116 117 component->SetProgressDiameter(progressDiameter); 118 } 119 SetMaxDistance(const Dimension & maxDistance)120void RefreshModelImpl::SetMaxDistance(const Dimension& maxDistance) 121 { 122 auto component = GetComponent(); 123 CHECK_NULL_VOID(component); 124 125 component->SetMaxDistance(maxDistance); 126 } 127 SetIsShowLastTime(bool IsShowLastTime)128void RefreshModelImpl::SetIsShowLastTime(bool IsShowLastTime) 129 { 130 auto component = GetComponent(); 131 CHECK_NULL_VOID(component); 132 133 component->SetShowLastTime(IsShowLastTime); 134 } 135 SetShowTimeDistance(const Dimension & showTimeDistance)136void RefreshModelImpl::SetShowTimeDistance(const Dimension& showTimeDistance) 137 { 138 auto component = GetComponent(); 139 CHECK_NULL_VOID(component); 140 141 component->SetShowTimeDistance(showTimeDistance); 142 } 143 SetTextStyle(const TextStyle & textStyle)144void RefreshModelImpl::SetTextStyle(const TextStyle& textStyle) 145 { 146 auto component = GetComponent(); 147 CHECK_NULL_VOID(component); 148 149 component->SetTextStyle(textStyle); 150 } 151 SetProgressColor(const Color & progressColor)152void RefreshModelImpl::SetProgressColor(const Color& progressColor) 153 { 154 auto component = GetComponent(); 155 CHECK_NULL_VOID(component); 156 157 component->SetProgressColor(progressColor); 158 } 159 SetProgressBackgroundColor(const Color & backgroundColor)160void RefreshModelImpl::SetProgressBackgroundColor(const Color& backgroundColor) 161 { 162 auto component = GetComponent(); 163 CHECK_NULL_VOID(component); 164 165 component->SetBackgroundColor(backgroundColor); 166 } 167 SetOnStateChange(std::function<void (const int32_t)> && stateChange)168void RefreshModelImpl::SetOnStateChange(std::function<void(const int32_t)>&& stateChange) 169 { 170 auto component = GetComponent(); 171 CHECK_NULL_VOID(component); 172 component->SetOnStateChange(std::move(stateChange)); 173 } 174 SetOnRefreshing(std::function<void ()> && refreshing)175void RefreshModelImpl::SetOnRefreshing(std::function<void()>&& refreshing) 176 { 177 auto component = GetComponent(); 178 CHECK_NULL_VOID(component); 179 component->SetOnRefreshing(std::move(refreshing)); 180 } 181 SetOnOffsetChange(std::function<void (const float)> && offsetChange)182void RefreshModelImpl::SetOnOffsetChange(std::function<void(const float)>&& offsetChange) {} 183 ResetOnOffsetChange()184void RefreshModelImpl::ResetOnOffsetChange() {} 185 SetChangeEvent(std::function<void (const std::string)> && changeEvent)186void RefreshModelImpl::SetChangeEvent(std::function<void(const std::string)>&& changeEvent) 187 { 188 auto component = GetComponent(); 189 CHECK_NULL_VOID(component); 190 auto eventMarker = EventMarker(changeEvent); 191 component->SetChangeEvent(eventMarker); 192 } 193 SetCustomBuilder(const RefPtr<NG::UINode> & customBuilder)194void RefreshModelImpl::SetCustomBuilder(const RefPtr<NG::UINode>& customBuilder) {} SetLoadingText(const std::string & loadingText)195void RefreshModelImpl::SetLoadingText(const std::string& loadingText) {} 196 } // namespace OHOS::Ace::Framework 197