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