1 /*
2 * Copyright (c) 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 #include "core/interfaces/native/node/swiper_controller_modifier.h"
16
17 #include "core/components_ng/base/frame_node.h"
18 #include "core/components_ng/pattern/swiper/swiper_model_ng.h"
19 #include "core/interfaces/native/node/view_model.h"
20
21 namespace OHOS::Ace::NG {
22
GetSwiperController(ArkUINodeHandle node)23 ArkUINodeHandle GetSwiperController(ArkUINodeHandle node)
24 {
25 auto* frameNode = reinterpret_cast<FrameNode*>(node);
26 CHECK_NULL_RETURN(frameNode, nullptr);
27 auto controller = SwiperModelNG::GetOrCreateSwiperController(frameNode);
28 return reinterpret_cast<ArkUINodeHandle>(AceType::RawPtr(controller));
29 }
30
ShowNext(ArkUINodeHandle controller)31 void ShowNext(ArkUINodeHandle controller)
32 {
33 CHECK_NULL_VOID(controller);
34 auto* swiperController = reinterpret_cast<SwiperController*>(controller);
35 swiperController->ShowNext();
36 }
37
ShowPrevious(ArkUINodeHandle controller)38 void ShowPrevious(ArkUINodeHandle controller)
39 {
40 CHECK_NULL_VOID(controller);
41 auto* swiperController = reinterpret_cast<SwiperController*>(controller);
42 swiperController->ShowPrevious();
43 }
44
45 namespace NodeModifier {
GetSwiperControllerModifier()46 const ArkUISwiperControllerModifier* GetSwiperControllerModifier()
47 {
48 static const ArkUISwiperControllerModifier modifier = {
49 GetSwiperController,
50 ShowNext,
51 ShowPrevious
52 };
53 return &modifier;
54 }
55
GetCJUISwiperControllerModifier()56 const CJUISwiperControllerModifier* GetCJUISwiperControllerModifier()
57 {
58 static const CJUISwiperControllerModifier modifier = {
59 GetSwiperController,
60 ShowNext,
61 ShowPrevious
62 };
63 return &modifier;
64 }
65 }
66 }
67