• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 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_PATTERNS_SCROLLABLE_NESTABLE_SCROLL_CONTAINER_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_SCROLLABLE_NESTABLE_SCROLL_CONTAINER_H
18 
19 #include "base/memory/ace_type.h"
20 #include "base/utils/noncopyable.h"
21 #include "core/components_ng/pattern/pattern.h"
22 #include "core/components_ng/pattern/scrollable/scrollable.h"
23 
24 namespace OHOS::Ace::NG {
25 class NestableScrollContainer : public virtual Pattern {
26     DECLARE_ACE_TYPE(NestableScrollContainer, Pattern)
27 public:
28     NestableScrollContainer() = default;
29     ~NestableScrollContainer() override = default;
30 
31     virtual Axis GetAxis() const = 0;
32 
33     /**
34      * @brief Handle regular scroll motion.
35      *
36      * @param offset delta on the main axis.
37      * @param source scroll source type defined in scrollable_properties.h.
38      * @param state current nested state. Defines how this function is triggered.
39      * @return remaining offset and whether the edge is reached
40      */
41     virtual ScrollResult HandleScroll(float offset, int32_t source, NestedState state) = 0;
42 
43     /**
44      * @brief Handle drag end velocity, triggering a scroll animation or a bounce animation on overScroll.
45      *
46      * @param velocity drag end velocity.
47      * @return true if velocity is consumed
48      */
49     virtual bool HandleScrollVelocity(float velocity) = 0;
50 
51     /**
52      * @brief Called when the scroll starts, recursively pass upwards.
53      *
54      * @param position The global position of the first touch point.
55      */
56     virtual void OnScrollStartRecursive(float position) = 0;
57 
58     /**
59      * @brief This function is called when the scrolling ends, recursively pass upwards.
60      *
61      * @param velocity The velocity of the DragEnd event. Optionally passed to parent when the child won't call
62      * HandleScrollVelocity.
63      */
64     virtual void OnScrollEndRecursive(const std::optional<float>& velocity) = 0;
65 
66 protected:
67     /**
68      * @brief Helper function. Searches for the parent NestableScrollContainer of the current instance.
69      *
70      * @return RefPtr<NestableScrollContainer> A reference to the parent NestableScrollContainer.
71      */
72     RefPtr<NestableScrollContainer> SearchParent();
73 
74     ACE_DISALLOW_COPY_AND_MOVE(NestableScrollContainer);
75 };
76 } // namespace OHOS::Ace::NG
77 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_SCROLLABLE_NESTABLE_SCROLL_CONTAINER_H
78