!46087 元服务分包路由先更新路由表然后触发pushpath,修复概率性因时序导致的页面无法跳转问题

Merge pull request !46087 from 连漪/master
This commit is contained in:
openharmony_ci 2024-10-18 08:31:46 +00:00 committed by Gitee
commit 63ee943cda
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
10 changed files with 30 additions and 21 deletions

View File

@ -54,11 +54,6 @@ void NavigationRouteOhos::InitRouteMap()
moduleInfos_ = bundleInfo.hapModuleInfos;
}
void NavigationRouteOhos::OnPackageChange()
{
InitRouteMap();
}
bool NavigationRouteOhos::GetRouteItem(const std::string& name, NG::RouteItem& info)
{
AppExecFwk::RouterItem routeItem;

View File

@ -43,13 +43,12 @@ public:
int32_t LoadPage(const std::string& name) override;
bool IsNavigationItemExits(const std::string& name) override;
void OnPackageChange() override;
void InitRouteMap() override;
private:
bool GetRouteItemFromBundle(const std::string& name, AppExecFwk::RouterItem& routeItem);
int32_t LoadPageFromHapModule(const std::string& name);
void InitRouteMap();
sptr<AppExecFwk::IBundleMgr> GetBundleManager();
AppExecFwk::RouterItem GetRouteItem(const std::string name);
std::vector<AppExecFwk::RouterItem> allRouteItems_;

View File

@ -28,6 +28,7 @@ public:
static int32_t SilentInstall(const std::string& moduleName, const std::function<void()>& callback,
const std::function<void(int32_t, const std::string&)>& silentInstallErrorCallBack);
static bool IsHspExist(const std::string& moduleName, const std::string& pathName);
static void InitRouteMap();
private:
static OHOS::sptr<OHOS::AppExecFwk::IBundleMgr> GetBundleManager();

View File

@ -26,6 +26,7 @@ class HspSilentInstallNapi {
public:
static napi_value SilentInstall(napi_env env, napi_callback_info info);
static napi_value IsHspExist(napi_env env, napi_callback_info info);
static napi_value InitRouteMap(napi_env env, napi_callback_info info);
private:
struct CallbackData {

View File

@ -34,6 +34,7 @@ export class NavPushPathHelper {
}
return new Promise((resolve, reject) => {
navPushPathHelperApi.silentInstall(moduleName, () => {
navPushPathHelperApi.initRouteMap();
this.navPathStack_?.pushPath(info, optionParam);
resolve();
},
@ -53,6 +54,7 @@ export class NavPushPathHelper {
}
return new Promise((resolve, reject) => {
navPushPathHelperApi.silentInstall(moduleName, () => {
navPushPathHelperApi.initRouteMap();
this.navPathStack_?.pushDestination(info, optionParam)
.then(resolve).catch(reject);
}, (error) => {
@ -71,6 +73,7 @@ export class NavPushPathHelper {
}
return new Promise((resolve, reject) => {
navPushPathHelperApi.silentInstall(moduleName, () => {
navPushPathHelperApi.initRouteMap();
this.navPathStack_?.pushPathByName(name, param, onPop, optionParam);
resolve();
}, (error) => {
@ -89,6 +92,7 @@ export class NavPushPathHelper {
}
return new Promise((resolve, reject) => {
navPushPathHelperApi.silentInstall(moduleName, () => {
navPushPathHelperApi.initRouteMap();
this.navPathStack_?.pushDestinationByName(name, param, onPop, optionParam)
.then(resolve).catch(reject);
}, (error) => {
@ -107,6 +111,7 @@ export class NavPushPathHelper {
}
return new Promise((resolve, reject) => {
navPushPathHelperApi.silentInstall(moduleName, () => {
navPushPathHelperApi.initRouteMap();
this.navPathStack_?.replacePath(info, optionParam);
resolve();
}, (error) => {
@ -125,6 +130,8 @@ export class NavPushPathHelper {
}
return new Promise((resolve, reject) => {
navPushPathHelperApi.silentInstall(moduleName, () => {
hilog.info(0x3900, tag, `silentInstall success`);
navPushPathHelperApi.initRouteMap();
this.navPathStack_?.replacePathByName(name, param, optionParam);
resolve();
}, (error) => {

View File

@ -105,4 +105,13 @@ bool HspSilentInstall::IsHspExist(const std::string &moduleName, const std::stri
}
return false;
}
void HspSilentInstall::InitRouteMap()
{
auto container = OHOS::Ace::Container::CurrentSafely();
CHECK_NULL_VOID(container);
auto navigationRoute = container->GetNavigationRoute();
CHECK_NULL_VOID(navigationRoute);
navigationRoute->InitRouteMap();
}
} // namespace OHOS::NavPushPathHelper

View File

@ -56,6 +56,12 @@ napi_value HspSilentInstallNapi::IsHspExist(napi_env env, napi_callback_info inf
return jsResult;
}
napi_value HspSilentInstallNapi::InitRouteMap(napi_env env, napi_callback_info info)
{
HspSilentInstall::InitRouteMap();
return nullptr;
}
napi_value HspSilentInstallNapi::SilentInstall(napi_env env, napi_callback_info info)
{
napi_value result = nullptr;

View File

@ -34,6 +34,7 @@ namespace OHOS::NavPushPathHelper {
napi_property_descriptor desc[] = {
DECLARE_NAPI_FUNCTION("silentInstall", HspSilentInstallNapi::SilentInstall),
DECLARE_NAPI_FUNCTION("isHspExist", HspSilentInstallNapi::IsHspExist),
DECLARE_NAPI_FUNCTION("initRouteMap", HspSilentInstallNapi::InitRouteMap),
};
NAPI_CALL(env, napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc));
return exports;

View File

@ -32,7 +32,6 @@
#include "core/components_ng/pattern/navigation/navigation_declaration.h"
#include "core/components_ng/pattern/navigation/navigation_pattern.h"
#include "core/components_ng/pattern/navigation/navigation_title_util.h"
#include "core/event/package/package_event_proxy.h"
namespace OHOS::Ace::NG {
namespace {
@ -1048,14 +1047,6 @@ void NavigationGroupNode::OnAttachToMainTree(bool recursive)
if (!findNavdestination) {
pipelineContext->AddNavigationNode(pageId, WeakClaim(this));
}
auto* eventProxy = PackageEventProxy::GetInstance();
if (eventProxy) {
auto container = OHOS::Ace::Container::CurrentSafely();
CHECK_NULL_VOID(container);
auto navigationRoute = container->GetNavigationRoute();
CHECK_NULL_VOID(navigationRoute);
eventProxy->Register(WeakClaim(AceType::RawPtr(navigationRoute)));
}
}
void NavigationGroupNode::FireHideNodeChange(NavDestinationLifecycle lifecycle)

View File

@ -19,7 +19,6 @@
#include <map>
#include "base/memory/ace_type.h"
#include "base/memory/referenced.h"
#include "core/event/package/package_change_listener.h"
namespace OHOS::Ace::NG {
using NavigationLoadPageCallback = std::function<int32_t(
@ -34,8 +33,8 @@ struct RouteItem {
std::map<std::string, std::string> data;
};
class ACE_EXPORT NavigationRoute : public PackageChangeListener {
DECLARE_ACE_TYPE(NavigationRoute, PackageChangeListener);
class ACE_EXPORT NavigationRoute : public AceType {
DECLARE_ACE_TYPE(NavigationRoute, AceType);
public:
NavigationRoute() = default;
~NavigationRoute() = default;
@ -65,7 +64,7 @@ public:
return false;
}
void OnPackageChange() override {}
virtual void InitRouteMap() {}
protected:
NavigationLoadPageCallback callback_;