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 FOUNDATION_ACE_FRAMEWORKS_BRIDGE_CJ_FRONTEND_CJ_PAGE_ROUTER_NG_H 17 #define FOUNDATION_ACE_FRAMEWORKS_BRIDGE_CJ_FRONTEND_CJ_PAGE_ROUTER_NG_H 18 19 #include "core/components_ng/base/frame_node.h" 20 #include "bridge/cj_frontend/frontend/cj_page_router_abstract.h" 21 #include "bridge/declarative_frontend/ng/page_router_manager.h" 22 23 #include <string> 24 25 namespace OHOS::Ace::Framework { 26 class CJPageRouterNG final : public CJPageRouterAbstract { DECLARE_ACE_TYPE(CJPageRouterNG,CJPageRouterAbstract)27 DECLARE_ACE_TYPE(CJPageRouterNG, CJPageRouterAbstract) 28 public: 29 explicit CJPageRouterNG(WeakPtr<CJFrontendAbstract> frontend): CJPageRouterAbstract(std::move(frontend)) {} 30 31 void EnableAlertBeforeBackPage(const std::string& message, std::function<void(int32_t)> callback) override; 32 33 void ClearAlertCallback(const RefPtr<NG::PageInfo>& pageInfo); 34 35 void DisableAlertBeforeBackPage(); 36 37 bool PopWithExitCheck() override; 38 39 void FlushReload() override; 40 41 // router operation 42 int32_t GetStackSize() const override; 43 void GetState(int32_t& index, std::string& name, std::string& path) override; 44 std::string GetParams() const override; 45 GetCurrentPageNode()46 RefPtr<NG::FrameNode> GetCurrentPageNode() override 47 { 48 if (pageRouterStack_.empty()) { 49 LOGE("fail to get current page node due to page is null"); 50 return nullptr; 51 } 52 return pageRouterStack_.back().Upgrade(); 53 } 54 55 std::string GetCurrentPageUrl() override; 56 57 protected: 58 std::pair<int32_t, RefPtr<NG::FrameNode>> FindPageInStack(const std::string& url); 59 60 void OnShowCurrent() override; 61 void OnHideCurrent() override; 62 bool AllowPopLastPage() override; 63 void StartPush(const RouterPageInfo& target, const std::string& params, RouterMode mode) override; 64 void StartBack(const RouterPageInfo& target, const std::string& params); 65 bool StartPop() override; 66 void StartReplace(const RouterPageInfo& target, const std::string& params, RouterMode mode) override; 67 void BackCheckAlert(const RouterPageInfo& target, const std::string& params) override; 68 void StartClean() override; 69 70 // page operations 71 void LoadPage(int32_t pageId, const RouterPageInfo& target, const std::string& params, bool isRestore = false, 72 bool needHideLast = true, bool needTransition = true) override; 73 void MovePageToFront(int32_t index, const RefPtr<NG::FrameNode>& pageNode, const std::string& params, 74 bool needHideLast, bool forceShowCurrent = false, bool needTransition = true); 75 void PopPage(const std::string& params, bool needShowNext, bool needTransition) override; 76 void PopPageToIndex(int32_t index, const std::string& params, bool needShowNext, bool needTransition) override; 77 78 RefPtr<NG::PipelineContext> GetCurrentPipeline(bool isCardRouter, uint64_t cardId = 0); 79 80 bool OnPageReady(const RefPtr<NG::FrameNode>& pageNode, bool needHideLast, bool needTransition, 81 bool isCardRouter = false, uint64_t cardId = 0); 82 static bool OnPopPage(bool needShowNext, bool needTransition); 83 static bool OnPopPageToIndex(int32_t index, bool needShowNext, bool needTransition); 84 static bool OnCleanPageStack(); 85 86 std::list<WeakPtr<NG::FrameNode>> pageRouterStack_; 87 88 ACE_DISALLOW_COPY_AND_MOVE(CJPageRouterNG); 89 }; 90 91 } // namespace OHOS::Ace::Framework 92 93 #endif // FOUNDATION_ACE_FRAMEWORKS_BRIDGE_CJ_FRONTEND_CJ_PAGE_ROUTER_NG_H