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(NG::NavContentInfo from, NG::NavContentInfo to, NG::NavigationOperation operation); 41 42 void Execute(const RefPtr<NG::NavigationTransitionProxy>& proxy); 43 }; 44 45 class JsNavigationTransitionProxy : public Referenced { 46 public: 47 static void JSBind(BindingTarget globalObj); 48 49 void SetFromContentInfo(const JSCallbackInfo& info); 50 51 void GetFromContentInfo(const JSCallbackInfo& info); 52 53 void SetToContentInfo(const JSCallbackInfo& info); 54 55 void GetToContentInfo(const JSCallbackInfo& info); 56 SetProxy(const RefPtr<NG::NavigationTransitionProxy> & proxy)57 void SetProxy(const RefPtr<NG::NavigationTransitionProxy>& proxy) 58 { 59 proxy_ = proxy; 60 } 61 GetProxy()62 RefPtr<NG::NavigationTransitionProxy> GetProxy() const 63 { 64 return proxy_; 65 } 66 67 void FinishTransition(const JSCallbackInfo& info); 68 69 static JSRef<JSVal> ConvertContentInfo(NG::NavContentInfo info); 70 71 private: 72 static void Constructor(const JSCallbackInfo& args); 73 74 static void Destructor(JsNavigationTransitionProxy* proxy); 75 76 RefPtr<NG::NavigationTransitionProxy> proxy_; 77 }; 78 } // namespace OHOS::Ace::Framework 79 #endif // FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_JS_NAVIGATION_FUNCTION_H