1 /* 2 * Copyright (c) 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_NAVIGATION_FUNCTION_H 17 #define FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_JS_NAVIGATION_FUNCTION_H 18 19 #include "frameworks/bridge/declarative_frontend/engine/functions/js_function.h" 20 #include "frameworks/core/components_ng/pattern/navigation/navigation_declaration.h" 21 #include "frameworks/core/components_ng/pattern/navigation/navigation_transition_proxy.h" 22 23 namespace OHOS::Ace::Framework { 24 25 class JsNavigationFunction : public JsFunction { DECLARE_ACE_TYPE(JsNavigationFunction,JsFunction)26 DECLARE_ACE_TYPE(JsNavigationFunction, JsFunction) 27 28 public: 29 explicit JsNavigationFunction(const JSRef<JSFunc>& jsFunction) : JsFunction(JSRef<JSObject>(), jsFunction) {} 30 31 static void JSBind(BindingTarget globalObj); 32 ~JsNavigationFunction()33 ~JsNavigationFunction() override {}; 34 Execute()35 void Execute() override 36 { 37 ExecuteJS(); 38 } 39 40 JSRef<JSVal> Execute(RefPtr<NG::NavDestinationContext> from, 41 RefPtr<NG::NavDestinationContext> to, NG::NavigationOperation operation); 42 43 void Execute(const RefPtr<NG::NavigationTransitionProxy>& proxy); 44 }; 45 46 class JsNavigationTransitionProxy : public Referenced { 47 public: 48 static void JSBind(BindingTarget globalObj); 49 50 void SetFromContentInfo(const JSCallbackInfo& info); 51 52 void GetFromContentInfo(const JSCallbackInfo& info); 53 54 void SetToContentInfo(const JSCallbackInfo& info); 55 56 void GetToContentInfo(const JSCallbackInfo& info); 57 SetProxy(const RefPtr<NG::NavigationTransitionProxy> & proxy)58 void SetProxy(const RefPtr<NG::NavigationTransitionProxy>& proxy) 59 { 60 proxy_ = proxy; 61 } 62 GetProxy()63 RefPtr<NG::NavigationTransitionProxy> GetProxy() const 64 { 65 return proxy_; 66 } 67 68 void FinishTransition(const JSCallbackInfo& info); 69 70 static JSRef<JSVal> ConvertContentInfo(RefPtr<NG::NavDestinationContext> info); 71 72 void SetInteractive(const JSCallbackInfo& info); 73 74 void GetInteractive(const JSCallbackInfo& info); 75 76 void CancelAnimation(const JSCallbackInfo& info); 77 78 void UpdateTransition(const JSCallbackInfo& info); 79 80 private: 81 static void Constructor(const JSCallbackInfo& args); 82 83 static void Destructor(JsNavigationTransitionProxy* proxy); 84 85 RefPtr<NG::NavigationTransitionProxy> proxy_; 86 }; 87 } // namespace OHOS::Ace::Framework 88 #endif // FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_JS_NAVIGATION_FUNCTION_H