Skip to content

Commit

Permalink
feat(ios): add inspectable for jscontext
Browse files Browse the repository at this point in the history
  • Loading branch information
ozonelmy authored and zealotchen0 committed May 25, 2023
1 parent fb29d4b commit e651e1b
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 0 deletions.
6 changes: 6 additions & 0 deletions ios/sdk/base/HippyBridge.h
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,12 @@ HIPPY_EXTERN NSString *HippyBridgeModuleNameForClass(Class bridgeModuleClass);
*/
- (void)setRedBoxShowEnabled:(BOOL)enabled;

/**
* Inspectable need to be set above ios16.4 system
* Default is YES for HIPPY_DEBUG mode
*/
- (void)setInspectable:(BOOL)isInspectable;

/**
* All registered bridge module classes.
*/
Expand Down
4 changes: 4 additions & 0 deletions ios/sdk/base/HippyBridge.mm
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,10 @@ - (void)setRedBoxShowEnabled:(BOOL)enabled {
#endif // HIPPY_DEBUG
}

- (void)setInspectable:(BOOL)isInspectable {
[self.batchedBridge.javaScriptExecutor setInspectable:isInspectable];
}

- (HippyOCTurboModule *)turboModuleWithName:(NSString *)name {
return [self.batchedBridge turboModuleWithName:name];
}
Expand Down
2 changes: 2 additions & 0 deletions ios/sdk/base/HippyJavaScriptExecutor.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ typedef void (^HippyJavaScriptCallback)(id result, NSError *error);
*/
- (void)flushedQueue:(HippyJavaScriptCallback)onComplete;

- (void)setInspectable:(BOOL)inspectable;

/**
* called when second bundle load
*/
Expand Down
22 changes: 22 additions & 0 deletions ios/sdk/base/executors/HippyJSCExecutor.mm
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,14 @@ - (JSContext *)JSContext {
JSGlobalContextRef contextRef = [self JSGlobalContextRef];
if (contextRef) {
_JSContext = [JSContext contextWithJSGlobalContextRef:contextRef];
#if HIPPY_DEBUG
#if defined(__IPHONE_16_4) && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_16_4
if (@available(iOS 16.4, *)) {
[_JSContext setInspectable:YES];
}
#endif //defined(__IPHONE_16_4) && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_16_4
#endif //HIPPY_DEBUG

HippyBridge *bridge = self.bridge;
if ([bridge isKindOfClass:[HippyBatchedBridge class]]) {
bridge = [(HippyBatchedBridge *)bridge parentBridge];
Expand Down Expand Up @@ -503,6 +511,20 @@ - (void)secondBundleLoadCompleted:(BOOL)success {

}

- (void)setInspectable:(BOOL)inspectable {
#if defined(__IPHONE_16_4) && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_16_4
if (@available(iOS 16.4, *)) {
__weak HippyJSCExecutor *weakSelf = self;
[self executeBlockOnJavaScriptQueue:^{
HippyJSCExecutor *strongSelf = weakSelf;
if (strongSelf) {
[[strongSelf JSContext] setInspectable:inspectable];
}
}];
}
#endif //defined(__IPHONE_16_4) && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_16_4
}

- (void)updateGlobalObjectBeforeExcuteSecondary{
if(![self.bridge.delegate respondsToSelector:@selector(objectsBeforeExecuteSecondaryCode)]){
return;
Expand Down

0 comments on commit e651e1b

Please sign in to comment.