1 /* 2 * Copyright (c) 2022-2024 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_SCROLL_SCROLL_MODEL_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_SCROLL_SCROLL_MODEL_H 18 19 #include <memory> 20 #include <mutex> 21 22 #include "core/components/common/layout/constants.h" 23 #include "core/components/scroll_bar/scroll_proxy.h" 24 #include "core/components_ng/pattern/scroll/scroll_event_hub.h" 25 26 namespace OHOS::Ace { 27 28 class ScrollBarTheme; 29 class ScrollControllerBase; 30 31 class ACE_FORCE_EXPORT ScrollModel { 32 public: 33 static ScrollModel* GetInstance(); 34 virtual ~ScrollModel() = default; 35 36 virtual void Create() = 0; 37 virtual RefPtr<ScrollControllerBase> GetOrCreateController() = 0; 38 virtual RefPtr<ScrollProxy> CreateScrollBarProxy() = 0; 39 virtual void SetAxis(Axis axis) = 0; 40 virtual void SetOnScrollBegin(OnScrollBeginEvent&& event) = 0; 41 virtual void SetOnScrollFrameBegin(OnScrollFrameBeginEvent&& event) = 0; 42 virtual void SetOnScroll(NG::ScrollEvent&& event) = 0; SetOnWillScroll(NG::ScrollEventWithReturn && event)43 virtual void SetOnWillScroll(NG::ScrollEventWithReturn&& event) {}; SetOnDidScroll(NG::ScrollEventWithState && event)44 virtual void SetOnDidScroll(NG::ScrollEventWithState&& event) {}; 45 virtual void SetOnScrollEdge(NG::ScrollEdgeEvent&& event) = 0; 46 virtual void SetOnScrollEnd(NG::ScrollEndEvent&& event) = 0; 47 virtual void SetOnScrollStart(OnScrollStartEvent&& event) = 0; 48 virtual void SetOnScrollStop(OnScrollStopEvent&& event) = 0; 49 virtual void SetOnReachStart(OnReachEvent&& onReachStart) = 0; 50 virtual void SetOnReachEnd(OnReachEvent&& onReachEnd) = 0; 51 virtual void SetScrollBarProxy(const RefPtr<ScrollProxy>& proxy) = 0; 52 virtual void InitScrollBar(const RefPtr<ScrollBarTheme>& theme, const std::pair<bool, Color>& color, 53 const std::pair<bool, Dimension>& width, EdgeEffect effect) = 0; 54 virtual void SetDisplayMode(int displayMode) = 0; 55 virtual void SetScrollBarWidth(const Dimension& dimension) = 0; 56 virtual void SetScrollBarColor(const Color& color) = 0; 57 virtual void SetEdgeEffect(EdgeEffect edgeEffect, bool alwaysEnabled) = 0; 58 virtual void SetHasWidth(bool hasWidth) = 0; 59 virtual void SetHasHeight(bool hasHeight) = 0; 60 virtual void SetNestedScroll(const NestedScrollOptions& nestedOpt) = 0; 61 virtual void SetScrollEnabled(bool scrollEnabled) = 0; 62 virtual void SetFriction(double friction) = 0; 63 virtual void SetScrollSnap(ScrollSnapAlign scrollSnapAlign, const Dimension& intervalSize, 64 const std::vector<Dimension>& snapPaginations, const std::pair<bool, bool>& enableSnapToSide) = 0; 65 virtual void SetEnablePaging(bool enablePaging) = 0; 66 virtual void SetInitialOffset(const NG::OffsetT<CalcDimension>& offset) = 0; 67 68 private: 69 static std::unique_ptr<ScrollModel> instance_; 70 static std::mutex mutex_; 71 }; 72 73 } // namespace OHOS::Ace 74 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_SCROLL_SCROLL_MODEL_H 75