diff --git a/driver/js/src/modules/contextify_module.cc b/driver/js/src/modules/contextify_module.cc index bcef9834c2a..a0767dfdc7c 100644 --- a/driver/js/src/modules/contextify_module.cc +++ b/driver/js/src/modules/contextify_module.cc @@ -176,7 +176,9 @@ void ContextifyModule::LoadUntrustedContent(CallbackInfo& info, void* data) { try_catch->SetVerbose(true); string_view view_code(reinterpret_cast(move_code.c_str()), move_code.length()); scope->RunJS(view_code, uri, file_name); - ctx->SetProperty(global_object, cur_dir_key, last_dir_str_obj, hippy::napi::PropertyAttribute::ReadOnly); + if (last_dir_str_obj) { + ctx->SetProperty(global_object, cur_dir_key, last_dir_str_obj, hippy::napi::PropertyAttribute::ReadOnly); + } if (try_catch->HasCaught()) { error = try_catch->Exception(); FOOTSTONE_DLOG(ERROR) << "RequestUntrustedContent error = " << try_catch->GetExceptionMessage(); diff --git a/framework/examples/ios-demo/HippyDemo.xcodeproj/project.pbxproj b/framework/examples/ios-demo/HippyDemo.xcodeproj/project.pbxproj index 6ba3dd85e65..42f8c8ae76d 100644 --- a/framework/examples/ios-demo/HippyDemo.xcodeproj/project.pbxproj +++ b/framework/examples/ios-demo/HippyDemo.xcodeproj/project.pbxproj @@ -108,7 +108,6 @@ E54E76502FD6AF687683BA8A /* HippyPageCacheContainerView.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = HippyPageCacheContainerView.h; sourceTree = ""; }; EEE0C5F943248577555BFB26 /* SettingsViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SettingsViewController.m; sourceTree = ""; }; EF558AABDC113B410B8ED69C /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; - F3C3E83580FEFC6EEE4CF186 /* DemoConfigs.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = DemoConfigs.h; sourceTree = ""; }; FBB045A62B4E511674BF590C /* PageCreationViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = PageCreationViewController.h; sourceTree = ""; }; /* End PBXFileReference section */ @@ -131,7 +130,6 @@ 6094F1F80FD70F9F9853EE15 /* AppDelegate.m */, 427F60D1B98DA953328F4E71 /* DemoBaseViewController.h */, 4708C41E8571123282E2B806 /* DemoBaseViewController.m */, - F3C3E83580FEFC6EEE4CF186 /* DemoConfigs.h */, 80D715362B1A0B0DCEAA813D /* DemoNavigationViewController.h */, 16348E2DEBFF10ADD6FCF7A9 /* DemoNavigationViewController.m */, 6045C301C6CFDC6C2E87AA66 /* IconUtils.h */, diff --git a/framework/examples/ios-demo/HippyDemo/AppDelegate.m b/framework/examples/ios-demo/HippyDemo/AppDelegate.m index 7a6a9a9cfb8..806489aa992 100644 --- a/framework/examples/ios-demo/HippyDemo/AppDelegate.m +++ b/framework/examples/ios-demo/HippyDemo/AppDelegate.m @@ -24,13 +24,9 @@ #import "HomePageViewController.h" #import "DemoNavigationViewController.h" -@interface AppDelegate () - -@end @implementation AppDelegate - - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // Override point for customization after application launch. self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds]; @@ -40,8 +36,4 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:( return YES; } -//- (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(nullable UIWindow *)window { -// return UIInterfaceOrientationMaskPortrait; -//} - @end diff --git a/framework/examples/ios-demo/HippyDemo/DemoConfigs.h b/framework/examples/ios-demo/HippyDemo/DemoConfigs.h deleted file mode 100644 index e30dc4862cb..00000000000 --- a/framework/examples/ios-demo/HippyDemo/DemoConfigs.h +++ /dev/null @@ -1,14 +0,0 @@ -// -// DemoConfigs.h -// HippyDemo -// -// Created by bennyzqliu on 2022/1/10. -// Copyright © 2022 tencent. All rights reserved. -// - -#ifndef DemoConfigs_h -#define DemoConfigs_h - -#define DEMO_ENABLE_TURBO 1 - -#endif /* DemoConfigs_h */ diff --git a/framework/examples/ios-demo/HippyDemo/RenderPage/HippyDemoViewController.m b/framework/examples/ios-demo/HippyDemo/RenderPage/HippyDemoViewController.m index dde46817a75..45f9e2abeeb 100644 --- a/framework/examples/ios-demo/HippyDemo/RenderPage/HippyDemoViewController.m +++ b/framework/examples/ios-demo/HippyDemo/RenderPage/HippyDemoViewController.m @@ -23,7 +23,6 @@ #import "HippyDemoViewController.h" #import "UIViewController+Title.h" #import "HippyPageCache.h" -#import "DemoConfigs.h" #import #import diff --git a/framework/ios/base/bridge/HippyBridge+Private.h b/framework/ios/base/bridge/HippyBridge+Private.h index 684f7f93b33..2d7e45ed910 100644 --- a/framework/ios/base/bridge/HippyBridge+Private.h +++ b/framework/ios/base/bridge/HippyBridge+Private.h @@ -28,23 +28,17 @@ #include class VFSUriLoader; -class NativeRenderManager; namespace hippy { inline namespace dom { class DomManager; class RootNode; -class RenderManager; }; }; @protocol HippyBridgeInternal -/// The C++ version of RenderManager instance, bridge holds -/// One NativeRenderManager holds multiple Uimanager instance. -@property (nonatomic, assign) std::shared_ptr renderManager; - /// URI Loader @property (nonatomic, assign) std::weak_ptr vfsUriLoader; diff --git a/framework/ios/base/bridge/HippyBridge.mm b/framework/ios/base/bridge/HippyBridge.mm index a2d738277ba..cc396647291 100644 --- a/framework/ios/base/bridge/HippyBridge.mm +++ b/framework/ios/base/bridge/HippyBridge.mm @@ -160,6 +160,10 @@ @interface HippyBridge() { std::shared_ptr _uriLoader; std::shared_ptr _rootNode; + // The C++ version of RenderManager instance, bridge holds, + // One NativeRenderManager holds multiple UIManager instance. + std::shared_ptr _renderManager; + // 缓存的设备信息 NSDictionary *_cachedDeviceInfo; } @@ -184,7 +188,6 @@ @interface HippyBridge() { @implementation HippyBridge -@synthesize renderManager = _renderManager; @synthesize imageLoader = _imageLoader; @synthesize imageProviders = _imageProviders; @synthesize startTime = _startTime; @@ -259,12 +262,13 @@ - (void)dealloc { self.invalidateReason = HippyInvalidateReasonDealloc; [self invalidate]; - // FIXME: 检查问题 if (_uriLoader) { _uriLoader->Terminate(); } - if (_rootNode) { + if (_renderManager) { _renderManager->RemoveVSyncEventListener(_rootNode); + } + if (_rootNode) { _rootNode->ReleaseResources(); } } @@ -646,7 +650,9 @@ - (void)unloadInstanceForRootView:(NSNumber *)rootTag { if (auto scope = self.javaScriptExecutor.pScope) { scope->UnloadInstance(domValue); } - _renderManager->UnregisterRootView([rootTag intValue]); + if (_renderManager) { + _renderManager->UnregisterRootView([rootTag intValue]); + } if (_rootNode) { _rootNode->ReleaseResources(); _rootNode = nullptr; diff --git a/modules/vfs/ios/VFSUriHandler.mm b/modules/vfs/ios/VFSUriHandler.mm index 768468ec890..89f5e465473 100644 --- a/modules/vfs/ios/VFSUriHandler.mm +++ b/modules/vfs/ios/VFSUriHandler.mm @@ -72,7 +72,7 @@ static bool CheckRequestFromCPP(const std::unordered_map) AssertMainQueue(); NSNumber *hippyTag = rootView.hippyTag; - NSAssert(HippyIsHippyRootView(hippyTag), @"View %@ with tag #%@ is not a root view", rootView, hippyTag); - -#if HIPPY_DEBUG - NSAssert(![_viewRegistry containRootComponentWithTag:hippyTag], @"RootView Tag already exists. Added %@ twice", hippyTag); -#endif + HippyAssert(HippyIsHippyRootView(hippyTag), @"View %@ with tag #%@ is not a root view", rootView, hippyTag); + if ([_viewRegistry containRootComponentWithTag:hippyTag]) { + HippyLogWarn(@"RootView Tag %@ already exists. Start Replace!", hippyTag); + [self unregisterRootViewFromTag:hippyTag]; + } // Register view [_viewRegistry addRootComponent:rootView rootNode:rootNode forTag:hippyTag]; diff --git a/renderer/native/ios/renderer/NativeRenderManager.h b/renderer/native/ios/renderer/NativeRenderManager.h index 2551df1057c..870eb786a2d 100644 --- a/renderer/native/ios/renderer/NativeRenderManager.h +++ b/renderer/native/ios/renderer/NativeRenderManager.h @@ -25,6 +25,7 @@ #include #include +#include #include #include "dom/render_manager.h" @@ -157,7 +158,7 @@ class NativeRenderManager : public hippy::RenderManager, public std::enable_shar void UnregisterRootView(uint32_t id); private: - + std::shared_mutex _mutex; // For _uiManagerMap's thread safety std::unordered_map _uiManagerMap; }; diff --git a/renderer/native/ios/renderer/NativeRenderManager.mm b/renderer/native/ios/renderer/NativeRenderManager.mm index 8465d2678ed..d2402ec8d0c 100644 --- a/renderer/native/ios/renderer/NativeRenderManager.mm +++ b/renderer/native/ios/renderer/NativeRenderManager.mm @@ -47,8 +47,8 @@ @autoreleasepool { auto rootNode = root_node.lock(); if (rootNode) { + std::shared_lock lock(_mutex); HippyUIManager *uiManager = _uiManagerMap[rootNode->GetId()]; - HippyAssertParam(uiManager); [uiManager createRenderNodes:std::move(nodes) onRootNode:root_node]; } } @@ -59,8 +59,8 @@ @autoreleasepool { auto rootNode = root_node.lock(); if (rootNode) { + std::shared_lock lock(_mutex); HippyUIManager *uiManager = _uiManagerMap[rootNode->GetId()]; - HippyAssertParam(uiManager); [uiManager updateRenderNodes:std::move(nodes) onRootNode:root_node]; } @@ -72,8 +72,8 @@ @autoreleasepool { auto rootNode = root_node.lock(); if (rootNode) { + std::shared_lock lock(_mutex); HippyUIManager *uiManager = _uiManagerMap[rootNode->GetId()]; - HippyAssertParam(uiManager); [uiManager deleteRenderNodesIds:std::move(nodes) onRootNode:root_node]; } } @@ -86,8 +86,8 @@ if (!rootNode) { return; } + std::shared_lock lock(_mutex); HippyUIManager *uiManager = _uiManagerMap[rootNode->GetId()]; - HippyAssertParam(uiManager); using DomNodeUpdateInfoTuple = std::tuple; std::vector nodes_infos; nodes_infos.reserve(nodes.size()); @@ -111,8 +111,8 @@ if (!rootNode) { return; } + std::shared_lock lock(_mutex); HippyUIManager *uiManager = _uiManagerMap[rootNode->GetId()]; - HippyAssertParam(uiManager); [uiManager renderMoveViews:std::move(moved_ids) fromContainer:from_pid toContainer:to_pid @@ -128,8 +128,8 @@ if (!rootNode) { return; } + std::shared_lock lock(_mutex); HippyUIManager *uiManager = _uiManagerMap[rootNode->GetId()]; - HippyAssertParam(uiManager); // Check whether all nodes have the same pid uint32_t firstPid = nodes[0]->GetPid(); bool allSamePid = std::all_of(nodes.begin(), nodes.end(), @@ -160,8 +160,8 @@ if (!rootNode) { return; } + std::shared_lock lock(_mutex); HippyUIManager *uiManager = _uiManagerMap[rootNode->GetId()]; - HippyAssertParam(uiManager); [uiManager batchOnRootNode:root_node]; TDF_PERF_LOG("NativeRenderManager::EndBatch End"); @@ -182,8 +182,8 @@ if (!rootNode) { return; } + std::shared_lock lock(_mutex); HippyUIManager *uiManager = _uiManagerMap[rootNode->GetId()]; - HippyAssertParam(uiManager); auto node = dom_node.lock(); if (node) { int32_t tag = node->GetId(); @@ -200,8 +200,8 @@ if (!rootNode) { return; } + std::shared_lock lock(_mutex); HippyUIManager *uiManager = _uiManagerMap[rootNode->GetId()]; - HippyAssertParam(uiManager); auto node = dom_node.lock(); if (node) { int32_t node_id = node->GetId(); @@ -216,8 +216,8 @@ if (!rootNode) { return; } + std::shared_lock lock(_mutex); HippyUIManager *uiManager = _uiManagerMap[rootNode->GetId()]; - HippyAssertParam(uiManager); [uiManager removeVSyncEventOnRootNode:root_node]; } } @@ -232,8 +232,8 @@ if (!rootNode) { return; } + std::shared_lock lock(_mutex); HippyUIManager *uiManager = _uiManagerMap[rootNode->GetId()]; - HippyAssertParam(uiManager); std::shared_ptr node = dom_node.lock(); if (node) { HippyValue hippy_value; @@ -258,6 +258,7 @@ return; } HippyAssertParam(uiManager); + std::shared_lock lock(_mutex); _uiManagerMap[rootNode->GetId()] = uiManager; [uiManager registerRootView:view asRootNode:root_node]; } @@ -265,6 +266,7 @@ void NativeRenderManager::UnregisterRootView(uint32_t rootId) { @autoreleasepool { + std::shared_lock lock(_mutex); HippyUIManager *uiManager = _uiManagerMap[rootId]; HippyAssertParam(uiManager); [uiManager unregisterRootViewFromTag:@(rootId)]; @@ -273,9 +275,11 @@ } NativeRenderManager::~NativeRenderManager() { + std::shared_lock lock(_mutex); for (auto &pair : _uiManagerMap) { [pair.second invalidate]; } _uiManagerMap.clear(); + FOOTSTONE_LOG(INFO) << "~NativeRenderManager"; }