From 991d8c43fcdaf61b8543fd0bca60411d475113ed Mon Sep 17 00:00:00 2001 From: wwwcg Date: Wed, 18 Sep 2024 22:34:43 +0800 Subject: [PATCH] fix(ios): resolve compatibility issue when using ResponseSenderBlock The problem occurs only in UI components, Methods in modules are not affected. --- .../ios/base/modules/HippyModuleMethod.mm | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/framework/ios/base/modules/HippyModuleMethod.mm b/framework/ios/base/modules/HippyModuleMethod.mm index 507ccec7c21..3490b40217a 100644 --- a/framework/ios/base/modules/HippyModuleMethod.mm +++ b/framework/ios/base/modules/HippyModuleMethod.mm @@ -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){ @@ -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) { @@ -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) {