Skip to content

Commit

Permalink
fix(ios): resolve compatibility issue when using ResponseSenderBlock (#…
Browse files Browse the repository at this point in the history
…4040)

The problem occurs only in UI components,
Methods in modules are not affected.
  • Loading branch information
wwwcg committed Sep 19, 2024
1 parent 0dd6f91 commit dee0b45
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions framework/ios/base/modules/HippyModuleMethod.mm
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,11 @@ - (void)processMethodSignature {
// so it is not a Number anymore.
// See NativeRenderManager::CallFunction() for more.
// TODO: add more type check for safe
blockArg = json;
blockArg = ^(NSArray *args){
// Since the block passed from UIManager's dispatchFunction method is of type HippyPromiseResolve,
// a small conversion is required here to avoid compatibility issues.
((HippyPromiseResolveBlock)json)(args.count > 0 ? args.firstObject : NSNull.null);
};
} else {
__weak HippyBridge *weakBridge = bridge;
blockArg = ^(NSArray *args){
Expand All @@ -325,7 +329,11 @@ - (void)processMethodSignature {
// so it is not a Number anymore.
// See NativeRenderManager::CallFunction() for more.
// TODO: add more type check for safe
blockArg = json;
blockArg = ^(NSError *error) {
// Since the block passed from UIManager's dispatchFunction method is of type HippyPromiseResolve,
// a small conversion is required here to avoid compatibility issues.
((HippyPromiseResolveBlock)json)(HippyJSErrorFromNSError(error));
};
} else {
__weak HippyBridge *weakBridge = bridge;
blockArg = ^(NSError *error) {
Expand Down Expand Up @@ -368,7 +376,12 @@ - (void)processMethodSignature {
// so it is not a Number anymore.
// See NativeRenderManager::CallFunction() for more.
// TODO: add more type check for safe
blockArg = json;
blockArg = ^(NSString *code, NSString *message, NSError *error) {
// Since the block passed from UIManager's dispatchFunction method is of type HippyPromiseResolve,
// a small conversion is required here to avoid compatibility issues.
NSDictionary *errorJSON = HippyJSErrorFromCodeMessageAndNSError(code, message, error);
((HippyPromiseResolveBlock)json)(errorJSON);
};
} else {
__weak HippyBridge *weakBridge = bridge;
blockArg = ^(NSString *code, NSString *message, NSError *error) {
Expand Down

0 comments on commit dee0b45

Please sign in to comment.