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