Skip to content

Commit

Permalink
refactor(ios): remove unused code in scope and update demo (Tencent#4013
Browse files Browse the repository at this point in the history
)
  • Loading branch information
wwwcg committed Sep 13, 2024
1 parent 9a355a6 commit f702cb4
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 42 deletions.
9 changes: 0 additions & 9 deletions driver/js/include/driver/scope.h
Original file line number Diff line number Diff line change
Expand Up @@ -304,14 +304,6 @@ class Scope : public std::enable_shared_from_this<Scope> {

inline std::weak_ptr<DomManager> GetDomManager() { return dom_manager_; }

inline void SetRenderManager(std::shared_ptr<RenderManager> render_manager) {
render_manager_ = render_manager;
}

inline std::weak_ptr<RenderManager> GetRenderManager() {
return render_manager_;
}

inline std::weak_ptr<RootNode> GetRootNode() {
return root_node_;
}
Expand Down Expand Up @@ -493,7 +485,6 @@ class Scope : public std::enable_shared_from_this<Scope> {
std::unique_ptr<ScopeWrapper> wrapper_;
std::weak_ptr<UriLoader> loader_;
std::weak_ptr<DomManager> dom_manager_;
std::weak_ptr<RenderManager> render_manager_;
std::weak_ptr<RootNode> root_node_;
std::unordered_map<std::string, std::shared_ptr<ModuleBase>> module_object_map_;
std::unordered_map<string_view , std::shared_ptr<CtxValue>> javascript_class_map_;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,6 @@


@interface HippyDemoViewController () <HippyMethodInterceptorProtocol, HippyBridgeDelegate, HippyRootViewDelegate> {
DriverType _driverType;
RenderType _renderType;
BOOL _isDebugMode;
NSURL *_debugURL;

HippyBridge *_hippyBridge;
HippyRootView *_hippyRootView;
BOOL _fromCache;
Expand All @@ -57,7 +52,7 @@ - (instancetype)initWithDriverType:(DriverType)driverType
_driverType = driverType;
_renderType = renderType;
_debugURL = debugURL;
_isDebugMode = isDebugMode;
_debugMode = isDebugMode;
}
return self;
}
Expand All @@ -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;
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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();
Expand Down
31 changes: 13 additions & 18 deletions framework/ios/base/bridge/HippyBridge.mm
Original file line number Diff line number Diff line change
Expand Up @@ -1025,24 +1025,19 @@ - (void)setMethodInterceptor:(id<HippyMethodInterceptorProtocol>)methodIntercept

- (void)setupDomManager:(std::shared_ptr<hippy::DomManager>)domManager
rootNode:(std::weak_ptr<hippy::RootNode>)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 {
Expand Down

0 comments on commit f702cb4

Please sign in to comment.