Skip to content

Commit

Permalink
fix(ios): turbo module not get called on destroyInstance event
Browse files Browse the repository at this point in the history
  • Loading branch information
wwwcg committed Apr 10, 2024
1 parent aebad43 commit a967be0
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 17 deletions.
2 changes: 1 addition & 1 deletion docs/en-us/guide/jsi.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ HippyRootView *rootView = [[HippyRootView alloc] initWithBridge:nil
shareOptions:nil
debugMode:YES
delegate:nil];
rootView.bridge.enableTurbo = YES;
[rootView.bridge setTurboModuleEnabled:YES];

```

Expand Down
2 changes: 1 addition & 1 deletion docs/guide/jsi.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ HippyRootView *rootView = [[HippyRootView alloc] initWithBridge:nil
shareOptions:nil
debugMode:YES
delegate:nil];
rootView.bridge.enableTurbo = YES;
[rootView.bridge setTurboModuleEnabled:YES];

```

Expand Down
16 changes: 15 additions & 1 deletion examples/hippy-react-demo/src/main.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import { Hippy } from '@hippy/react';
import { ConsoleModule, Hippy, NetworkModule } from '@hippy/react';
import App from './app';
import {
getTurboConfig,
printTurboConfig,
} from './externals/Turbo/demoTurbo';

global.Hippy.on('uncaughtException', (err) => {
console.error('uncaughtException error', err.stack, err.message);
Expand All @@ -10,6 +14,16 @@ global.Hippy.on('unhandledRejection', (reason) => {
console.error('unhandledRejection reason', reason);
});

global.Hippy.on('destroyInstance', () => {
console.error('on Hippy destroyInstance !!!');
// test call turbo module
printTurboConfig(getTurboConfig());
// test call c++ module
ConsoleModule.log('on Hippy destroyInstance !!!');
// test call native module
NetworkModule.setCookie('https://hippyjs.org', 'name=hippy;network=mobile');
});

new Hippy({
appName: 'Demo',
entryPage: App,
Expand Down
14 changes: 11 additions & 3 deletions examples/ios-demo/HippyDemo/TestModule.m
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,20 @@ - (dispatch_queue_t)methodQueue

NSURL *url = [NSURL URLWithString:urlString];
NSDictionary *launchOptions = @{@"EnableTurbo": @(DEMO_ENABLE_TURBO), @"DebugMode": @(YES)};
HippyBridge *bridge = [[HippyBridge alloc] initWithDelegate:self bundleURL:url moduleProvider:nil launchOptions:launchOptions executorKey:@"Demo"];
HippyRootView *rootView = [[HippyRootView alloc] initWithBridge:bridge moduleName:@"Demo" initialProperties:@{@"isSimulator": @(isSimulator)} shareOptions:nil delegate:nil];
HippyBridge *bridge = [[HippyBridge alloc] initWithDelegate:self
bundleURL:url
moduleProvider:nil
launchOptions:launchOptions
executorKey:@"Demo"];
HippyRootView *rootView = [[HippyRootView alloc] initWithBridge:bridge
moduleName:@"Demo"
initialProperties:@{@"isSimulator": @(isSimulator)}
shareOptions:nil
delegate:nil];
rootView.backgroundColor = [UIColor whiteColor];
rootView.frame = vc.view.bounds;
[vc.view addSubview:rootView];
vc.modalPresentationStyle = UIModalPresentationFullScreen;
vc.modalPresentationStyle = UIModalPresentationPageSheet;
[nav presentViewController:vc animated:YES completion:NULL];
}

Expand Down
4 changes: 0 additions & 4 deletions ios/sdk/base/HippyBatchedBridge.mm
Original file line number Diff line number Diff line change
Expand Up @@ -717,10 +717,6 @@ - (BOOL)debugMode {
return _parentBridge.debugMode ?: NO;
}

- (BOOL)enableTurbo {
return _parentBridge.enableTurbo;
}

- (void)setExecutorClass:(Class)executorClass {
HippyAssertMainQueue();
_parentBridge.executorClass = executorClass;
Expand Down
16 changes: 10 additions & 6 deletions ios/sdk/base/HippyBridge.h
Original file line number Diff line number Diff line change
Expand Up @@ -259,8 +259,6 @@ HIPPY_EXTERN NSString *HippyBridgeModuleNameForClass(Class bridgeModuleClass);

@property (nonatomic, assign) BOOL debugMode;

@property (nonatomic, assign) BOOL enableTurbo;

@property (nonatomic, strong) NSMutableDictionary *shareOptions;

@property (nonatomic, strong) NSString *moduleName;
Expand All @@ -279,11 +277,17 @@ HIPPY_EXTERN NSString *HippyBridgeModuleNameForClass(Class bridgeModuleClass);

#pragma mark - Turbo Module

/**
* Get the turbo module for a given name.
*/
- (HippyOCTurboModule *)turboModuleWithName:(NSString *)name;
/// Whether TurboModule is enabled,
/// default YES.
@property (nonatomic, assign, readonly) BOOL enableTurbo;

/// Turn on/off turbo module
/// - Parameter enabled: YES or NO
- (void)setTurboModuleEnabled:(BOOL)enabled;

/// Get the turbo module for a given name.
/// - Parameter name: module name
- (HippyOCTurboModule *)turboModuleWithName:(NSString *)name;

@end

Expand Down
7 changes: 6 additions & 1 deletion ios/sdk/base/HippyBridge.mm
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,12 @@ - (void)setOSNightMode:(BOOL)isOSNightMode withRootViewTag:(NSNumber *)rootViewT
[self.batchedBridge setOSNightMode:isOSNightMode withRootViewTag:rootViewTag];
}

#pragma mark -
#pragma mark - Turbo Module

- (void)setTurboModuleEnabled:(BOOL)enabled {
_enableTurbo = enabled;
[self.batchedBridge setTurboModuleEnabled:enabled];
}

- (HippyOCTurboModule *)turboModuleWithName:(NSString *)name {
return [self.batchedBridge turboModuleWithName:name];
Expand Down

0 comments on commit a967be0

Please sign in to comment.