From be8a66934da1a60934ee754ba44bde00a20cbf10 Mon Sep 17 00:00:00 2001 From: wwwcg Date: Tue, 3 Sep 2024 11:06:05 +0800 Subject: [PATCH] refactor(ios): remove unused code in scope and update demo (#4013) --- driver/js/include/driver/scope.h | 9 ------ .../RenderPage/HippyDemoViewController.m | 25 ++++++--------- framework/ios/base/bridge/HippyBridge.mm | 31 ++++++++----------- 3 files changed, 23 insertions(+), 42 deletions(-) diff --git a/driver/js/include/driver/scope.h b/driver/js/include/driver/scope.h index 0daf07568c6..fb67ae06533 100644 --- a/driver/js/include/driver/scope.h +++ b/driver/js/include/driver/scope.h @@ -304,14 +304,6 @@ class Scope : public std::enable_shared_from_this { inline std::weak_ptr GetDomManager() { return dom_manager_; } - inline void SetRenderManager(std::shared_ptr render_manager) { - render_manager_ = render_manager; - } - - inline std::weak_ptr GetRenderManager() { - return render_manager_; - } - inline std::weak_ptr GetRootNode() { return root_node_; } @@ -493,7 +485,6 @@ class Scope : public std::enable_shared_from_this { std::unique_ptr wrapper_; std::weak_ptr loader_; std::weak_ptr dom_manager_; - std::weak_ptr render_manager_; std::weak_ptr root_node_; std::unordered_map> module_object_map_; std::unordered_map> javascript_class_map_; diff --git a/framework/examples/ios-demo/HippyDemo/RenderPage/HippyDemoViewController.m b/framework/examples/ios-demo/HippyDemo/RenderPage/HippyDemoViewController.m index 74af3afde60..dde46817a75 100644 --- a/framework/examples/ios-demo/HippyDemo/RenderPage/HippyDemoViewController.m +++ b/framework/examples/ios-demo/HippyDemo/RenderPage/HippyDemoViewController.m @@ -34,11 +34,6 @@ @interface HippyDemoViewController () { - DriverType _driverType; - RenderType _renderType; - BOOL _isDebugMode; - NSURL *_debugURL; - HippyBridge *_hippyBridge; HippyRootView *_hippyRootView; BOOL _fromCache; @@ -57,7 +52,7 @@ - (instancetype)initWithDriverType:(DriverType)driverType _driverType = driverType; _renderType = renderType; _debugURL = debugURL; - _isDebugMode = isDebugMode; + _debugMode = isDebugMode; } return self; } @@ -68,7 +63,7 @@ - (instancetype)initWithPageCache:(HippyPageCache *)pageCache { _driverType = pageCache.driverType; _renderType = pageCache.renderType; _debugURL = pageCache.debugURL; - _isDebugMode = pageCache.isDebugMode; + _debugMode = pageCache.isDebugMode; _hippyRootView = pageCache.rootView; _hippyBridge = pageCache.hippyBridge; _fromCache = YES; @@ -111,12 +106,12 @@ - (void)registerLogFunction { - (void)runHippyDemo { // Necessary configuration: NSString *moduleName = @"Demo"; - NSDictionary *launchOptions = @{ @"DebugMode": @(_isDebugMode) }; + NSDictionary *launchOptions = @{ @"DebugMode": @(_debugMode) }; NSDictionary *initialProperties = @{ @"isSimulator": @(TARGET_OS_SIMULATOR) }; HippyBridge *bridge = nil; HippyRootView *rootView = nil; - if (_isDebugMode) { + if (_debugMode) { bridge = [[HippyBridge alloc] initWithDelegate:self bundleURL:_debugURL moduleProvider:nil @@ -129,11 +124,11 @@ - (void)runHippyDemo { } else { NSURL *vendorBundleURL = [self vendorBundleURL]; NSURL *indexBundleURL = [self indexBundleURL]; - HippyBridge *bridge = [[HippyBridge alloc] initWithDelegate:self - bundleURL:vendorBundleURL - moduleProvider:nil - launchOptions:launchOptions - executorKey:nil]; + bridge = [[HippyBridge alloc] initWithDelegate:self + bundleURL:vendorBundleURL + moduleProvider:nil + launchOptions:launchOptions + executorKey:moduleName]; rootView = [[HippyRootView alloc] initWithBridge:bridge businessURL:indexBundleURL moduleName:moduleName @@ -191,7 +186,7 @@ - (HippyPageCache *)toPageCache { pageCache.driverType = _driverType; pageCache.renderType = _renderType; pageCache.debugURL = _debugURL; - pageCache.debugMode = _isDebugMode; + pageCache.debugMode = _debugMode; UIGraphicsBeginImageContextWithOptions(_hippyRootView.bounds.size, NO, [UIScreen mainScreen].scale); [_hippyRootView drawViewHierarchyInRect:_hippyRootView.bounds afterScreenUpdates:YES]; UIImage *image = UIGraphicsGetImageFromCurrentImageContext(); diff --git a/framework/ios/base/bridge/HippyBridge.mm b/framework/ios/base/bridge/HippyBridge.mm index 022b9e72e8c..fe6246a9d34 100644 --- a/framework/ios/base/bridge/HippyBridge.mm +++ b/framework/ios/base/bridge/HippyBridge.mm @@ -1025,24 +1025,19 @@ - (void)setMethodInterceptor:(id)methodIntercept - (void)setupDomManager:(std::shared_ptr)domManager rootNode:(std::weak_ptr)rootNode { - __weak HippyBridge *weakSelf = self; - dispatch_block_t block = ^(void){ - HippyBridge *strongSelf = weakSelf; - HippyAssertParam(domManager); - if (!strongSelf || !domManager) { - return; - } - strongSelf.javaScriptExecutor.pScope->SetDomManager(domManager); - strongSelf.javaScriptExecutor.pScope->SetRootNode(rootNode); - #ifdef ENABLE_INSPECTOR - auto devtools_data_source = strongSelf->_javaScriptExecutor.pScope->GetDevtoolsDataSource(); - if (devtools_data_source) { - strongSelf->_javaScriptExecutor.pScope->GetDevtoolsDataSource()->Bind(domManager); - devtools_data_source->SetRootNode(rootNode); - } - #endif - }; - block(); + HippyAssertParam(domManager); + if (!domManager) { + return; + } + self.javaScriptExecutor.pScope->SetDomManager(domManager); + self.javaScriptExecutor.pScope->SetRootNode(rootNode); +#ifdef ENABLE_INSPECTOR + auto devtools_data_source = self.javaScriptExecutor.pScope->GetDevtoolsDataSource(); + if (devtools_data_source) { + self.javaScriptExecutor.pScope->GetDevtoolsDataSource()->Bind(domManager); + devtools_data_source->SetRootNode(rootNode); + } +#endif } - (BOOL)isValid {