1 /* 2 * Copyright (c) 2024 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_NAV_PATH_STACK_H 17 #define FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_JS_VIEW_JS_NAV_PATH_STACK_H 18 19 #include <functional> 20 #include <string> 21 22 #include "base/memory/referenced.h" 23 #include "bridge/declarative_frontend/engine/bindings.h" 24 #include "bridge/declarative_frontend/engine/functions/js_function.h" 25 #include "bridge/declarative_frontend/engine/js_types.h" 26 #include "bridge/declarative_frontend/engine/js_ref_ptr.h" 27 #include "core/components_ng/pattern/navigation/navigation_pattern.h" 28 29 namespace OHOS::Ace::Framework { 30 class JSNavPathStack final : public Referenced { 31 public: JSNavPathStack()32 JSNavPathStack() 33 { 34 containerCurrentId_ = Container::CurrentId(); 35 }; 36 ~JSNavPathStack() override = default; 37 38 static void JSBind(BindingTarget globalObj); 39 OnStateChanged()40 void OnStateChanged() 41 { 42 if (onStateChangedCallback_) { 43 onStateChangedCallback_(); 44 } 45 } 46 SetOnStateChangedCallback(std::function<void ()> callback)47 void SetOnStateChangedCallback(std::function<void()> callback) 48 { 49 onStateChangedCallback_ = callback; 50 } 51 52 void OnPushDestination(const JSCallbackInfo& info); 53 SetCheckNavDestinationExistsFunc(std::function<int32_t (JSRef<JSObject>)> checkFunc)54 void SetCheckNavDestinationExistsFunc(std::function<int32_t(JSRef<JSObject>)> checkFunc) 55 { 56 checkNavDestinationExistsFunc_ = checkFunc; 57 } 58 59 static JSRef<JSObject> CreateNewNavPathStackJSObject(); 60 static void SetNativeNavPathStack(JSRef<JSObject> jsStack, JSRef<JSObject> nativeStack); 61 62 static bool CheckIsValid(JSValueWrapper object); 63 64 private: 65 static void Constructor(const JSCallbackInfo& info); 66 static void Destructor(JSNavPathStack* stack); 67 68 std::function<void()> onStateChangedCallback_; 69 std::function<int32_t(JSRef<JSObject>)> checkNavDestinationExistsFunc_; 70 71 int32_t containerCurrentId_; 72 }; 73 } // namespace OHOS::Ace::Framework 74 75 #endif // FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_JS_VIEW_JS_NAV_PATH_STACK_H 76