Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: TurboModule method signature mismatch in Swift by removing external parameter label #352

Conversation

dmitry-blackwave
Copy link
Contributor

Overview

This PR fixes an issue while building RN app based on 0.76.

image image

Problem

When calling the trackNotificationResponseReceived method via TurboModule for React Native, a compilation failure occurred at the parameter mapping stage between JavaScript and Swift/Objective-C. Debug logs revealed that the trackNotificationResponseReceived:(NSDictionary *)payload method was not recognized correctly because the arguments array was passed as null.

Solution

To remove this inconsistency, we added _ (an unnamed label) to Swift class for the payload parameter in the trackNotificationResponseReceived and trackNotificationReceived methods. This made both methods more compatible with Objective-C because _ removes the need to specify the parameter name when calling it, thus eliminating signature differences and allowing TurboModule to recognize the method correctly.

Logs

#3	0x000000010b31a394 in std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>::basic_string[abi:de180100]<0> at Developer/SDKs/iPhoneSimulator18.0.sdk/usr/include/c++/v1/string:953

#4	0x000000010b319f3c in std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>::basic_string[abi:de180100]<0> at Developer/SDKs/iPhoneSimulator18.0.sdk/usr/include/c++/v1/string:952

#5	0x000000010c228800 in facebook::react::(anonymous namespace)::parseExportedMethods at node_modules/react-native/ReactCommon/react/nativemodule/core/platform/ios/ReactCommon/RCTInteropTurboModule.mm:127
...

I've also added some logs to identify the problematic methods:

RCTInteropTurboModule.parseExportedMethods:

...
    NSMethodSignature *objCMethodSignature = [moduleClass instanceMethodSignatureForSelector:objCMethodSelector];
      NSLog(@"\n\n---\n\nJs method name: %@\n\n\n\nobj name: %s\n\narguments: %@\n\nselector: %s\n\nsignature: %@\n\nclass: %@\n\n---\n\n", jsMethodName, methodInfo->objcName, arguments, objCMethodSelector, objCMethodSignature, moduleClass);
    std::string objCMethodReturnType = [objCMethodSignature methodReturnType];
...

Other methods:

---

Js method name: supportedEvents



obj name: supportedEvents

arguments: (null)

selector: supportedEvents

signature: <NSMethodSignature: 0xb21a5f2c0267cedf>

class: CioRctInAppMessaging

---


---

Js method name: dismissMessage



obj name: dismissMessage

arguments: (null)

selector: dismissMessage

signature: <NSMethodSignature: 0xb21a5f2c02676087>

class: CioRctInAppMessaging

---

Broken one:

Js method name: trackNotificationResponseReceived



obj name: trackNotificationResponseReceived : (nonnull NSDictionary *) payload]

arguments: (
    "<RCTMethodArgument: 0x6000003898c0>"
)

selector: trackNotificationResponseReceived:

signature: (null)

class: CioRctPushMessaging

@Shahroz16 Shahroz16 changed the title Fix TurboModule method signature mismatch in Swift by removing external parameter label fix: TurboModule method signature mismatch in Swift by removing external parameter label Oct 30, 2024
Copy link
Contributor

@mrehan27 mrehan27 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the changes @dmitry-blackwave! Initial testing shows the updates work well with React Native 0.76. I'll proceed with merging the PR. We plan to release the changes soon after some additional testing. Thanks again for your contributions. Please keep them coming 🎉

@mrehan27 mrehan27 changed the title fix: TurboModule method signature mismatch in Swift by removing external parameter label chore: TurboModule method signature mismatch in Swift by removing external parameter label Nov 18, 2024
@mrehan27 mrehan27 merged commit 2172838 into customerio:main Nov 18, 2024
4 of 7 checks passed
@dmitry-blackwave dmitry-blackwave deleted the fix/remove-external-parameter-label-pushmessaging branch November 18, 2024 12:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants