• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-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 FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_JS_VIEW_JS_SWIPER_H
17 #define FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_JS_VIEW_JS_SWIPER_H
18 
19 #include "core/components_ng/pattern/swiper/swiper_model.h"
20 #include "frameworks/bridge/declarative_frontend/jsview/js_container_base.h"
21 
22 namespace OHOS::Ace::Framework {
23 
24 class JSSwiper : public JSContainerBase {
25 public:
26     static void JSBind(BindingTarget globalObj);
27     static void Create(const JSCallbackInfo& info);
28 
29 protected:
30     static void SetAutoPlay(bool autoPlay);
31     static void SetDuration(const JSCallbackInfo& info);
32     static void SetIndex(const JSCallbackInfo& info);
33     static void SetInterval(const JSCallbackInfo& info);
34     static void SetLoop(const JSCallbackInfo& info);
35     static void SetVertical(bool isVertical);
36     static void SetIndicator(const JSCallbackInfo& info);
37     static void SetWidth(const JSCallbackInfo& info);
38     static void SetHeight(const JSCallbackInfo& info);
39     static void SetWidth(const JSRef<JSVal>& jsValue);
40     static void SetHeight(const JSRef<JSVal>& jsValue);
41     static void SetSize(const JSCallbackInfo& info);
42     static void SetIndicatorStyle(const JSCallbackInfo& info);
43     static void SetItemSpace(const JSCallbackInfo& info);
44     static void SetPreviousMargin(const JSCallbackInfo& info);
45     static void SetNextMargin(const JSCallbackInfo& info);
46     static void SetDisplayMode(int32_t index);
47     static void SetEffectMode(const JSCallbackInfo& info);
48     static void SetDisplayCount(const JSCallbackInfo& info);
49     static void SetCachedCount(const JSCallbackInfo& info);
50     static void SetEnabled(const JSCallbackInfo& info);
51     static void SetDisableSwipe(bool disableSwipe);
52     static void SetCurve(const JSCallbackInfo& info);
53     static void SetOnChange(const JSCallbackInfo& info);
54     static void SetOnAnimationStart(const JSCallbackInfo& info);
55     static void SetOnAnimationEnd(const JSCallbackInfo& info);
56     static void SetOnGestureSwipe(const JSCallbackInfo& info);
57     static void SetOnClick(const JSCallbackInfo& info);
58     static void JsRemoteMessage(const JSCallbackInfo& info);
59     static void GetFontContent(const JSRef<JSVal>& font, bool isSelected, SwiperDigitalParameters& digitalParameters);
60     static void SetDisplayArrow(const JSCallbackInfo& info);
61     static SwiperParameters GetDotIndicatorInfo(const JSRef<JSObject>& obj);
62     static SwiperDigitalParameters GetDigitIndicatorInfo(const JSRef<JSObject>& obj);
63     static void SetIsIndicatorCustomSize(const Dimension& dimPosition, bool parseOk);
64     static bool GetArrowInfo(const JSRef<JSObject>& obj, SwiperArrowParameters& swiperArrowParameters);
65 };
66 
67 class JSSwiperController final : public Referenced {
68 public:
69     JSSwiperController() = default;
70     ~JSSwiperController() override = default;
71 
72     static void JSBind(BindingTarget globalObj);
73     static void Constructor(const JSCallbackInfo& args);
74     static void Destructor(JSSwiperController* scroller);
75 
SwipeTo(const JSCallbackInfo & args)76     void SwipeTo(const JSCallbackInfo& args)
77     {
78         if (args.Length() < 1 || !args[0]->IsNumber()) {
79             LOGE("Param is not valid");
80             return;
81         }
82         if (controller_) {
83             controller_->SwipeTo(args[0]->ToNumber<int32_t>());
84         }
85     }
86 
ShowNext(const JSCallbackInfo & args)87     void ShowNext(const JSCallbackInfo& args)
88     {
89         if (controller_) {
90             controller_->ShowNext();
91         }
92     }
93 
ShowPrevious(const JSCallbackInfo & args)94     void ShowPrevious(const JSCallbackInfo& args)
95     {
96         if (controller_) {
97             controller_->ShowPrevious();
98         }
99     }
100 
101     void FinishAnimation(const JSCallbackInfo& args);
102 
SetController(const RefPtr<SwiperController> & controller)103     void SetController(const RefPtr<SwiperController>& controller)
104     {
105         controller_ = controller;
106     }
107 
108 private:
109     RefPtr<SwiperController> controller_;
110 
111     ACE_DISALLOW_COPY_AND_MOVE(JSSwiperController);
112 };
113 
114 } // namespace OHOS::Ace::Framework
115 #endif // FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_JS_VIEW_JS_SWIPER_H
116