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 std::optional<Dimension> ParseIndicatorDimension(const JSRef<JSVal>& value); 64 static void SetIsIndicatorCustomSize(const Dimension& dimPosition, bool parseOk); 65 static bool GetArrowInfo(const JSRef<JSObject>& obj, SwiperArrowParameters& swiperArrowParameters); 66 static void SetNestedScroll(const JSCallbackInfo& info); 67 }; 68 69 class JSSwiperController final : public Referenced { 70 public: 71 JSSwiperController() = default; 72 ~JSSwiperController() override = default; 73 74 static void JSBind(BindingTarget globalObj); 75 static void Constructor(const JSCallbackInfo& args); 76 static void Destructor(JSSwiperController* scroller); 77 SwipeTo(const JSCallbackInfo & args)78 void SwipeTo(const JSCallbackInfo& args) 79 { 80 ContainerScope scope(instanceId_); 81 if (args.Length() < 1 || !args[0]->IsNumber()) { 82 LOGE("Param is not valid"); 83 return; 84 } 85 if (controller_) { 86 controller_->SwipeTo(args[0]->ToNumber<int32_t>()); 87 } 88 } 89 ShowNext(const JSCallbackInfo & args)90 void ShowNext(const JSCallbackInfo& args) 91 { 92 ContainerScope scope(instanceId_); 93 if (controller_) { 94 controller_->ShowNext(); 95 } 96 } 97 ShowPrevious(const JSCallbackInfo & args)98 void ShowPrevious(const JSCallbackInfo& args) 99 { 100 ContainerScope scope(instanceId_); 101 if (controller_) { 102 controller_->ShowPrevious(); 103 } 104 } 105 106 void FinishAnimation(const JSCallbackInfo& args); 107 void PreloadItems(const JSCallbackInfo& args); 108 SetController(const RefPtr<SwiperController> & controller)109 void SetController(const RefPtr<SwiperController>& controller) 110 { 111 controller_ = controller; 112 } 113 SetInstanceId(int32_t id)114 void SetInstanceId(int32_t id) 115 { 116 instanceId_ = id; 117 } 118 119 private: 120 int32_t instanceId_ = INSTANCE_ID_UNDEFINED; 121 RefPtr<SwiperController> controller_; 122 123 ACE_DISALLOW_COPY_AND_MOVE(JSSwiperController); 124 }; 125 126 } // namespace OHOS::Ace::Framework 127 #endif // FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_JS_VIEW_JS_SWIPER_H 128