• 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 "bridge/declarative_frontend/jsview/js_indicator.h"
20 #include "core/components_ng/pattern/swiper/swiper_model.h"
21 #include "frameworks/bridge/declarative_frontend/jsview/js_container_base.h"
22 
23 namespace OHOS::Ace::Framework {
24 
25 class JSSwiper : public JSContainerBase {
26 public:
27     static void JSBind(BindingTarget globalObj);
28     static void Create(const JSCallbackInfo& info);
29 
30 protected:
31     static void SetIndicatorInteractive(const JSCallbackInfo& info);
32     static void SetAutoPlay(const JSCallbackInfo& info);
33     static void SetDuration(const JSCallbackInfo& info);
34     static void SetIndex(const JSCallbackInfo& info);
35     static void SetInterval(const JSCallbackInfo& info);
36     static void SetLoop(const JSCallbackInfo& info);
37     static void SetVertical(bool isVertical);
38     static void SetIndicator(const JSCallbackInfo& info);
39     static void SetWidth(const JSCallbackInfo& info);
40     static void SetHeight(const JSCallbackInfo& info);
41     static void SetWidth(const JSRef<JSVal>& jsValue);
42     static void SetHeight(const JSRef<JSVal>& jsValue);
43     static void SetSize(const JSCallbackInfo& info);
44     static void SetIndicatorStyle(const JSCallbackInfo& info);
45     static void SetItemSpace(const JSCallbackInfo& info);
46     static void SetPreviousMargin(const JSCallbackInfo& info);
47     static void SetNextMargin(const JSCallbackInfo& info);
48     static void SetDisplayMode(int32_t index);
49     static void SetEffectMode(const JSCallbackInfo& info);
50     static void SetDisplayCount(const JSCallbackInfo& info);
51     static void SetCachedCount(const JSCallbackInfo& info);
52     static void SetEnabled(const JSCallbackInfo& info);
53     static void SetDisableSwipe(bool disableSwipe);
54     static void SetCurve(const JSCallbackInfo& info);
55     static void SetOnChange(const JSCallbackInfo& info);
56     static void SetOnUnselected(const JSCallbackInfo& info);
57     static void SetOnAnimationStart(const JSCallbackInfo& info);
58     static void SetOnAnimationEnd(const JSCallbackInfo& info);
59     static void SetOnGestureSwipe(const JSCallbackInfo& info);
60     static void SetOnClick(const JSCallbackInfo& info);
61     static void JsRemoteMessage(const JSCallbackInfo& info);
62     static void GetFontContent(const JSRef<JSVal>& font, bool isSelected, SwiperDigitalParameters& digitalParameters);
63     static void SetDisplayArrow(const JSCallbackInfo& info);
64     static SwiperParameters GetDotIndicatorInfo(const JSRef<JSObject>& obj);
65     static void SetDotIndicatorInfo(const JSRef<JSObject>& obj, SwiperParameters& swiperParameters,
66         const RefPtr<SwiperIndicatorTheme>& swiperIndicatorTheme);
67     static SwiperDigitalParameters GetDigitIndicatorInfo(const JSRef<JSObject>& obj);
68     static std::optional<Dimension> ParseIndicatorDimension(const JSRef<JSVal>& value);
69     static std::optional<Dimension> ParseIndicatorBottom(const JSRef<JSVal>& bottomValue, bool hasIgnoreSize);
70     static void SetIsIndicatorCustomSize(const Dimension& dimPosition, bool parseOk);
71     static bool GetArrowInfo(const JSRef<JSObject>& obj, SwiperArrowParameters& swiperArrowParameters);
72     static void SetNestedScroll(const JSCallbackInfo& info);
73     static void SetCustomContentTransition(const JSCallbackInfo& info);
74     static void SetOnContentDidScroll(const JSCallbackInfo& info);
75     static void SetOnContentWillScroll(const JSCallbackInfo& info);
76     static void SetPageFlipMode(const JSCallbackInfo& info);
77     static void SetOnSelected(const JSCallbackInfo& info);
78     static bool ParseLengthMetricsToDimension(const JSRef<JSVal>& jsValue, CalcDimension& result);
79     static void GetAutoPlayOptionsInfo(const JSRef<JSObject>& obj, SwiperAutoPlayOptions& swiperAutoPlayOptions);
80     static void SetIndicatorController(const JSCallbackInfo& info);
81     static void ResetSwiperNode();
82 
83     private:
84         static WeakPtr<JSIndicatorController> jSIndicatorController_;
85         static bool ParseSpace(const JSRef<JSVal>& jsValue, CalcDimension& result);
86 };
87 
88 class JSSwiperController final : public Referenced {
89 public:
90     JSSwiperController() = default;
91     ~JSSwiperController() override = default;
92 
93     static void JSBind(BindingTarget globalObj);
94     static void Constructor(const JSCallbackInfo& args);
95     static void Destructor(JSSwiperController* scroller);
96 
97     void SwipeTo(const JSCallbackInfo& args);
98     void ShowNext(const JSCallbackInfo& args);
99     void ShowPrevious(const JSCallbackInfo& args);
100     void ChangeIndex(const JSCallbackInfo& args);
101 
102     void FinishAnimation(const JSCallbackInfo& args);
103     void OldPreloadItems(const JSCallbackInfo& args);
104     void NewPreloadItems(const JSCallbackInfo& args);
105     void PreloadItems(const JSCallbackInfo& args);
106 
SetController(const RefPtr<SwiperController> & controller)107     void SetController(const RefPtr<SwiperController>& controller)
108     {
109         controller_ = controller;
110     }
111 
SetInstanceId(int32_t id)112     void SetInstanceId(int32_t id)
113     {
114         instanceId_ = id;
115     }
116 
117 private:
118     int32_t instanceId_ = INSTANCE_ID_UNDEFINED;
119     RefPtr<SwiperController> controller_;
120 
121     ACE_DISALLOW_COPY_AND_MOVE(JSSwiperController);
122 };
123 
124 } // namespace OHOS::Ace::Framework
125 #endif // FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_JS_VIEW_JS_SWIPER_H
126