diff --git a/framework/examples/ios-demo/HippyDemo.xcodeproj/project.pbxproj b/framework/examples/ios-demo/HippyDemo.xcodeproj/project.pbxproj index d424fd19902..713f3af6e58 100644 --- a/framework/examples/ios-demo/HippyDemo.xcodeproj/project.pbxproj +++ b/framework/examples/ios-demo/HippyDemo.xcodeproj/project.pbxproj @@ -24,7 +24,6 @@ 9C99A05896359E49AE9A8352 /* MyView.m in Sources */ = {isa = PBXBuildFile; fileRef = 90F34E176169143334EDFC28 /* MyView.m */; }; 9CF888F990C83ECD4F6C78AA /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 5EF877A8CB4B2AD68A780A12 /* Assets.xcassets */; }; A3F629CA4C94D65F42BB4B33 /* HippyDemoViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 9EB0CD5FCC3F38E3C7DC5E00 /* HippyDemoViewController.m */; }; - B8AA2B793BE43710EFC9D4DC /* TestModule.mm in Sources */ = {isa = PBXBuildFile; fileRef = D2241406CEF00D2FF5938BB2 /* TestModule.mm */; }; BD5196B65EE0B712FDA2EB9B /* UIViewController+Title.m in Sources */ = {isa = PBXBuildFile; fileRef = C412B5D210F1E3359523628C /* UIViewController+Title.m */; }; C1A78F8868963E6C790472AA /* PageCreationCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 25B65684EC9C9AF27BB04D21 /* PageCreationCell.xib */; }; C94B7BB8A618F36A1F58C270 /* HomePageViewController.mm in Sources */ = {isa = PBXBuildFile; fileRef = 90B5552FD45612EC5EC4CB45 /* HomePageViewController.mm */; }; @@ -90,7 +89,6 @@ 9EB0CD5FCC3F38E3C7DC5E00 /* HippyDemoViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = HippyDemoViewController.m; sourceTree = ""; }; A066953E3614D26125F617EF /* HippyPageCacheContainerView.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = HippyPageCacheContainerView.m; sourceTree = ""; }; B2FA2A97C78628634C6AFC9A /* TTTGB-Medium.otf */ = {isa = PBXFileReference; lastKnownFileType = file; path = "TTTGB-Medium.otf"; sourceTree = ""; }; - B5A22F93EAA399DE400CED88 /* TestModule.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = TestModule.h; sourceTree = ""; }; BD54126F3E80B297E2109B40 /* DebugCell.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = DebugCell.m; sourceTree = ""; }; BF84819C1E7CCD88BCBEA4D7 /* HippyPageCache.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = HippyPageCache.h; sourceTree = ""; }; C412B5D210F1E3359523628C /* UIViewController+Title.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "UIViewController+Title.m"; sourceTree = ""; }; @@ -98,7 +96,6 @@ C6BAC7BC0021E9E21B04E496 /* SettingsInfo.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SettingsInfo.m; sourceTree = ""; }; C7504BC18486120B29F3D9FA /* PageCreationCell.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = PageCreationCell.h; sourceTree = ""; }; CC8AEAE8BF116954FB41BDF9 /* TurboBaseModule.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = TurboBaseModule.mm; sourceTree = ""; }; - D2241406CEF00D2FF5938BB2 /* TestModule.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = TestModule.mm; sourceTree = ""; }; D2EE3455BE6DD7D2ADA20093 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; DC53FC9D9560D6AD989F8540 /* HomePageView.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = HomePageView.xib; sourceTree = ""; }; DDD052D2760E830B1E0095EA /* UIViewController+Title.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "UIViewController+Title.h"; sourceTree = ""; }; @@ -135,8 +132,6 @@ 17AB7FB6346FE861C9D953F5 /* IconUtils.m */, 177A9E8373F2682A9A831991 /* Info.plist */, D2EE3455BE6DD7D2ADA20093 /* main.m */, - B5A22F93EAA399DE400CED88 /* TestModule.h */, - D2241406CEF00D2FF5938BB2 /* TestModule.mm */, DDD052D2760E830B1E0095EA /* UIViewController+Title.h */, C412B5D210F1E3359523628C /* UIViewController+Title.m */, 4CF6648308C60D57DD274D30 /* HomePage */, @@ -381,7 +376,6 @@ DCCEB3FED1802C0D9C21AB11 /* PageManagerViewController.m in Sources */, F3F6D205C6FBA36CB262A28E /* SettingsInfo.m in Sources */, 380469787621147052854E8F /* SettingsViewController.m in Sources */, - B8AA2B793BE43710EFC9D4DC /* TestModule.mm in Sources */, 74C51526435B1AB788CBF991 /* TurboBaseModule.mm in Sources */, 72328C3389BA8DD5E54D7D5F /* TurboConfig.m in Sources */, BD5196B65EE0B712FDA2EB9B /* UIViewController+Title.m in Sources */, diff --git a/framework/examples/ios-demo/HippyDemo/RenderPage/HippyDemoViewController.m b/framework/examples/ios-demo/HippyDemo/RenderPage/HippyDemoViewController.m index b3439997871..926c1bfdeaa 100644 --- a/framework/examples/ios-demo/HippyDemo/RenderPage/HippyDemoViewController.m +++ b/framework/examples/ios-demo/HippyDemo/RenderPage/HippyDemoViewController.m @@ -25,15 +25,13 @@ #import "HippyPageCache.h" #import "DemoConfigs.h" -#import "HippyMethodInterceptorProtocol.h" - #import #import #import #import #import +#import -static NSString *const engineKey = @"Demo"; static NSString *formatLog(NSDate *timestamp, HippyLogLevel level, NSString *fileName, NSNumber *lineNumber, NSString *message) { static NSArray *logLevelMap; @@ -48,7 +46,7 @@ NSString *levelStr = level < 0 || level > logLevelMap.count ? logLevelMap[1] : logLevelMap[level]; if(fileName){ - return [[NSString alloc] initWithFormat:@"[%@][%@:%d][%@]%@", + return [[NSString alloc] initWithFormat:@"[%@][%@:%d][%@] %@", [formatter stringFromDate:timestamp], fileName.lastPathComponent, lineNumber.intValue, @@ -142,89 +140,49 @@ - (void)runHippyCache { } - (void)runHippyDemo { - NSDictionary *launchOptions = @{@"EnableTurbo": @(DEMO_ENABLE_TURBO), @"DebugMode": @(_isDebugMode)}; - NSString *uniqueEngineKey = [NSString stringWithFormat:@"%@_%u", engineKey, arc4random()]; - - _hippyBridge = [[HippyBridge alloc] initWithDelegate:self - moduleProvider:nil - launchOptions:launchOptions - executorKey:uniqueEngineKey]; - _hippyBridge.methodInterceptor = self; - - [_hippyBridge setInspectable:YES]; - - [self mountConnector:_hippyBridge]; -} - -- (void)mountConnector:(HippyBridge *)hippyBridge { - BOOL isSimulator = NO; -#if TARGET_IPHONE_SIMULATOR - isSimulator = YES; -#endif - -#if USE_NEW_LOAD - HippyRootView *rootView = [[HippyRootView alloc] initWithBridge:hippyBridge - moduleName:@"Demo" - initialProperties:@{@"isSimulator": @(isSimulator)} - delegate:self]; + // Necessary configuration: + NSString *moduleName = @"Demo"; + NSDictionary *launchOptions = @{ @"DebugMode": @(_isDebugMode) }; + NSDictionary *initialProperties = @{ @"isSimulator": @(TARGET_OS_SIMULATOR) }; - if (_isDebugMode) { - hippyBridge.sandboxDirectory = [_debugURL URLByDeletingLastPathComponent]; - [hippyBridge loadBundleURL:_debugURL completion:^(NSURL * _Nullable, NSError * _Nullable) { - [rootView runHippyApplication]; - }]; - } else { - NSURL *vendorBundleURL = [self vendorBundleURL]; - [hippyBridge loadBundleURL:vendorBundleURL completion:^(NSURL * _Nullable, NSError * _Nullable) { - NSLog(@"url %@ load finish", vendorBundleURL); - }]; - NSURL *indexBundleURL = [self indexBundleURL]; - hippyBridge.sandboxDirectory = [indexBundleURL URLByDeletingLastPathComponent]; - [hippyBridge loadBundleURL:indexBundleURL completion:^(NSURL * _Nullable, NSError * _Nullable) { - NSLog(@"url %@ load finish", indexBundleURL); - [rootView runHippyApplication]; - }]; - } - -#else + HippyBridge *bridge = nil; HippyRootView *rootView = nil; - if (_isDebugMode) { - hippyBridge.sandboxDirectory = [_debugURL URLByDeletingLastPathComponent]; - rootView = [[HippyRootView alloc] initWithBridge:hippyBridge - businessURL:_debugURL - moduleName:@"Demo" - initialProperties:@{@"isSimulator": @(isSimulator)} + bridge = [[HippyBridge alloc] initWithDelegate:self + bundleURL:_debugURL + moduleProvider:nil + launchOptions:launchOptions + executorKey:nil]; + rootView = [[HippyRootView alloc] initWithBridge:bridge + moduleName:moduleName + initialProperties:initialProperties delegate:self]; } else { NSURL *vendorBundleURL = [self vendorBundleURL]; NSURL *indexBundleURL = [self indexBundleURL]; - [hippyBridge loadBundleURL:vendorBundleURL - bundleType:HippyBridgeBundleTypeVendor - completion:^(NSURL * _Nullable url, NSError * _Nullable error) { - NSLog(@"url %@ load finish", vendorBundleURL); - }]; - hippyBridge.sandboxDirectory = [indexBundleURL URLByDeletingLastPathComponent]; - rootView = [[HippyRootView alloc] initWithBridge:hippyBridge + HippyBridge *bridge = [[HippyBridge alloc] initWithDelegate:self + bundleURL:vendorBundleURL + moduleProvider:nil + launchOptions:launchOptions + executorKey:nil]; + rootView = [[HippyRootView alloc] initWithBridge:bridge businessURL:indexBundleURL - moduleName:@"Demo" - initialProperties:@{@"isSimulator": @(isSimulator)} + moduleName:moduleName + initialProperties:initialProperties delegate:self]; } -#endif - + bridge.methodInterceptor = self; + [bridge setInspectable:YES]; + _hippyBridge = bridge; rootView.frame = self.contentAreaView.bounds; rootView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth; - [self.contentAreaView addSubview:rootView]; _hippyRootView = rootView; } -- (void)viewDidLayoutSubviews { - [super viewDidLayoutSubviews]; - _hippyRootView.frame = self.contentAreaView.bounds; -} + +#pragma mark - - (NSURL *)vendorBundleURL { NSString *path = nil; diff --git a/framework/ios/base/bridge/HippyBridge.mm b/framework/ios/base/bridge/HippyBridge.mm index e5517b92c36..0f5c1b5f81c 100644 --- a/framework/ios/base/bridge/HippyBridge.mm +++ b/framework/ios/base/bridge/HippyBridge.mm @@ -234,40 +234,24 @@ - (instancetype)initWithDelegate:(id)delegate _debugMode = [launchOptions[@"DebugMode"] boolValue]; _enableTurbo = !!launchOptions[@"EnableTurbo"] ? [launchOptions[@"EnableTurbo"] boolValue] : YES; _engineKey = executorKey.length > 0 ? executorKey : [NSString stringWithFormat:@"%p", self]; - _invalidateReason = HippyInvalidateReasonDealloc; - _valid = YES; _bundlesQueue = [[HippyBundleOperationQueue alloc] init]; - _startTime = footstone::TimePoint::SystemNow(); + HippyLogInfo(@"HippyBridge init begin, self:%p", self); + + // Set the log delegate for hippy core module registerLogDelegateToHippyCore(); - - HippyExecuteOnMainThread(^{ - self->_isOSNightMode = [HippyDeviceBaseInfo isUIScreenInOSDarkMode]; - self.cachedDimensionsInfo = hippyExportedDimensions(self); - }, YES); + // Setup [self setUp]; - [self addImageProviderClass:[HippyDefaultImageProvider class]]; - [self setVfsUriLoader:[self createURILoaderIfNeeded]]; - [self setUpNativeRenderManager]; - + // Record bridge instance for RedBox (Debug Only) [HippyBridge setCurrentBridge:self]; - - [self loadPendingVendorBundleURLIfNeeded]; - - // Set the default sandbox directory - [self setSandboxDirectory:[bundleURL URLByDeletingLastPathComponent]]; HippyLogInfo(@"HippyBridge init end, self:%p", self); } return self; } - (void)dealloc { - /** - * This runs only on the main thread, but crashes the subclass - * HippyAssertMainQueue(); - */ HippyLogInfo(@"[Hippy_OC_Log][Life_Circle],%@ dealloc %p", NSStringFromClass([self class]), self); [[NSNotificationCenter defaultCenter] removeObserver:self]; self.invalidateReason = HippyInvalidateReasonDealloc; @@ -442,6 +426,14 @@ - (void)requestReload { - (void)setUp { _valid = YES; + _startTime = footstone::TimePoint::SystemNow(); + + // Get global enviroment info + HippyExecuteOnMainThread(^{ + self->_isOSNightMode = [HippyDeviceBaseInfo isUIScreenInOSDarkMode]; + self.cachedDimensionsInfo = hippyExportedDimensions(self); + }, YES); + self.moduleSemaphore = dispatch_semaphore_create(0); @try { __weak HippyBridge *weakSelf = self; @@ -478,6 +470,16 @@ - (void)setUp { } @catch (NSException *exception) { HippyBridgeHandleException(exception, self); } + + [self addImageProviderClass:[HippyDefaultImageProvider class]]; + [self setVfsUriLoader:[self createURILoaderIfNeeded]]; + [self setUpNativeRenderManager]; + + // Load pending js bundles + [self loadPendingVendorBundleURLIfNeeded]; + + // Set the default sandbox directory + [self setSandboxDirectory:[_pendingLoadingVendorBundleURL URLByDeletingLastPathComponent]]; } @@ -1274,7 +1276,7 @@ - (void)setRootView:(UIView *)rootView { _rootNode->SetRootOrigin(rootView.frame.origin.x, rootView.frame.origin.y); //set rendermanager for dommanager - if (!domManager->GetRenderManager().lock()) { + if (domManager->GetRenderManager().lock() != _renderManager) { domManager->SetRenderManager(_renderManager); } //bind rootview and root node diff --git a/renderer/native/ios/renderer/HippyRootView.mm b/renderer/native/ios/renderer/HippyRootView.mm index 9b40d29c24b..a5389fed0e2 100644 --- a/renderer/native/ios/renderer/HippyRootView.mm +++ b/renderer/native/ios/renderer/HippyRootView.mm @@ -291,12 +291,6 @@ - (NSNumber *)hippyTag { return super.hippyTag; } -- (void)bridgeDidReload { - HippyAssertMainQueue(); - // Clear the hippyTag so it can be re-assigned - self.hippyTag = nil; -} - #pragma mark - Notification Handlers diff --git a/renderer/native/ios/renderer/HippyUIManager.mm b/renderer/native/ios/renderer/HippyUIManager.mm index 2891ddea9ab..451aa0c4298 100644 --- a/renderer/native/ios/renderer/HippyUIManager.mm +++ b/renderer/native/ios/renderer/HippyUIManager.mm @@ -245,6 +245,10 @@ - (void)invalidate { }); } +- (void)dealloc { + HippyLogInfo(@"[Hippy_OC_Log][Life_Circle], HippyUIManager(%p) dealloc", self); +} + #pragma mark Setter & Getter - (void)registRenderManager:(std::weak_ptr)renderManager {