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(bool autoPlay); 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 SetOnAnimationStart(const JSCallbackInfo& info); 57 static void SetOnAnimationEnd(const JSCallbackInfo& info); 58 static void SetOnGestureSwipe(const JSCallbackInfo& info); 59 static void SetOnClick(const JSCallbackInfo& info); 60 static void JsRemoteMessage(const JSCallbackInfo& info); 61 static void GetFontContent(const JSRef<JSVal>& font, bool isSelected, SwiperDigitalParameters& digitalParameters); 62 static void SetDisplayArrow(const JSCallbackInfo& info); 63 static SwiperParameters GetDotIndicatorInfo(const JSRef<JSObject>& obj); 64 static SwiperDigitalParameters GetDigitIndicatorInfo(const JSRef<JSObject>& obj); 65 static std::optional<Dimension> ParseIndicatorDimension(const JSRef<JSVal>& value); 66 static void SetIsIndicatorCustomSize(const Dimension& dimPosition, bool parseOk); 67 static bool GetArrowInfo(const JSRef<JSObject>& obj, SwiperArrowParameters& swiperArrowParameters); 68 static void SetNestedScroll(const JSCallbackInfo& info); 69 static void SetCustomContentTransition(const JSCallbackInfo& info); 70 static void SetOnContentDidScroll(const JSCallbackInfo& info); 71 static void SetPageFlipMode(const JSCallbackInfo& info); 72 static void SetOnContentWillScroll(const JSCallbackInfo& info); 73 static bool ParseLengthMetricsToDimension(const JSRef<JSVal>& jsValue, CalcDimension& result); 74 static void SetIndicatorController(const JSCallbackInfo& info); 75 static void ResetSwiperNode(); 76 77 private: 78 static WeakPtr<JSIndicatorController> jSIndicatorController_; 79 }; 80 81 class JSSwiperController final : public Referenced { 82 public: 83 JSSwiperController() = default; 84 ~JSSwiperController() override = default; 85 86 static void JSBind(BindingTarget globalObj); 87 static void Constructor(const JSCallbackInfo& args); 88 static void Destructor(JSSwiperController* scroller); 89 SwipeTo(const JSCallbackInfo & args)90 void SwipeTo(const JSCallbackInfo& args) 91 { 92 ContainerScope scope(instanceId_); 93 if (args.Length() < 1 || !args[0]->IsNumber()) { 94 LOGE("Param is not valid"); 95 return; 96 } 97 if (controller_) { 98 controller_->SwipeTo(args[0]->ToNumber<int32_t>()); 99 } 100 } 101 ShowNext(const JSCallbackInfo & args)102 void ShowNext(const JSCallbackInfo& args) 103 { 104 ContainerScope scope(instanceId_); 105 if (controller_) { 106 controller_->ShowNext(); 107 } 108 } 109 ShowPrevious(const JSCallbackInfo & args)110 void ShowPrevious(const JSCallbackInfo& args) 111 { 112 ContainerScope scope(instanceId_); 113 if (controller_) { 114 controller_->ShowPrevious(); 115 } 116 } 117 118 void ChangeIndex(const JSCallbackInfo& args); 119 120 void FinishAnimation(const JSCallbackInfo& args); 121 void PreloadItems(const JSCallbackInfo& args); 122 SetController(const RefPtr<SwiperController> & controller)123 void SetController(const RefPtr<SwiperController>& controller) 124 { 125 controller_ = controller; 126 } 127 SetInstanceId(int32_t id)128 void SetInstanceId(int32_t id) 129 { 130 instanceId_ = id; 131 } 132 133 private: 134 int32_t instanceId_ = INSTANCE_ID_UNDEFINED; 135 RefPtr<SwiperController> controller_; 136 137 ACE_DISALLOW_COPY_AND_MOVE(JSSwiperController); 138 }; 139 140 } // namespace OHOS::Ace::Framework 141 #endif // FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_JS_VIEW_JS_SWIPER_H 142