• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/pattern/swiper/swiper_model_ng.h"
18 
19 namespace OHOS::Ace::NG {
20 
GetSwiperController(ArkUINodeHandle node)21 ArkUINodeHandle GetSwiperController(ArkUINodeHandle node)
22 {
23     auto* frameNode = reinterpret_cast<FrameNode*>(node);
24     CHECK_NULL_RETURN(frameNode, nullptr);
25     auto controller = SwiperModelNG::GetOrCreateSwiperController(frameNode);
26     return reinterpret_cast<ArkUINodeHandle>(AceType::RawPtr(controller));
27 }
28 
ShowNext(ArkUINodeHandle controller)29 void ShowNext(ArkUINodeHandle controller)
30 {
31     CHECK_NULL_VOID(controller);
32     auto* swiperController = reinterpret_cast<SwiperController*>(controller);
33     swiperController->ShowNext();
34 }
35 
ShowPrevious(ArkUINodeHandle controller)36 void ShowPrevious(ArkUINodeHandle controller)
37 {
38     CHECK_NULL_VOID(controller);
39     auto* swiperController = reinterpret_cast<SwiperController*>(controller);
40     swiperController->ShowPrevious();
41 }
42 
43 namespace NodeModifier {
GetSwiperControllerModifier()44 const ArkUISwiperControllerModifier* GetSwiperControllerModifier()
45 {
46     CHECK_INITIALIZED_FIELDS_BEGIN(); // don't move this line
47     static const ArkUISwiperControllerModifier modifier = {
48         .getSwiperController = GetSwiperController,
49         .showNext = ShowNext,
50         .showPrevious = ShowPrevious,
51     };
52     CHECK_INITIALIZED_FIELDS_END(modifier, 0, 0, 0); // don't move this line
53 
54     return &modifier;
55 }
56 
GetCJUISwiperControllerModifier()57 const CJUISwiperControllerModifier* GetCJUISwiperControllerModifier()
58 {
59     CHECK_INITIALIZED_FIELDS_BEGIN(); // don't move this line
60     static const CJUISwiperControllerModifier modifier = {
61         .getSwiperController = GetSwiperController,
62         .showNext = ShowNext,
63         .showPrevious = ShowPrevious,
64     };
65     CHECK_INITIALIZED_FIELDS_END(modifier, 0, 0, 0); // don't move this line
66 
67     return &modifier;
68 }
69 }
70 }
71