react-native-macos/React
Ramanpreet Nara 8618a5824f Add support for argument conversion via RCTConvert
Summary:
With our current infra, we support automatic conversion of method arguments using `RCTConvert`.

```
RCT_EXPORT_METHOD(foo:(RCTSound*) sound)
{
  //...
}
```

```
interface RCTConvert (RCTSound)
+ (RCTSound *) RCTSound: (NSDictionary *) dict;
end

implementation RCTConvert (RCTSound)
+ (RCTSound *) RCTSound: (NSDictionary *) dict
{
  //...
}
end
```

```
export interface Spec extends TurboModule {
  +foo: (dict: Object) => void,
}
```

With this setup, when we call the foo method on the TurboModule in JS, we'd first convert `dict` from a JS Object to an `NSDictionary`. Then, because the `foo` method has an argument of type`RCTSound*`, and because `RCTConvert` has a method called `RCTSound`, before we invoke the `foo` NativeModule native method, we first convert the `NSDictionary` to `RCTSound` using `[RCTConvert RCTSound:obj]`. Essentially, if an argument type of a TurboModule method is neither a primitive type nor a struct (i.e: is an identifier), and it corresponds to a selector on `RCTConvert`, we call `[RCTConvert argumentType:obj]` to convert `obj` to the type `argumentType` before passing in `obj` as an argument to the NativeModule method call.

**Note:** I originally planned on using `NSMethodSignature` to get the argument types. Unfortunately, while the Objective C Runtime lets us know that the type is an identifier, it doesn't inform us which identifier it is. In other words, at runtime, we can't determine whether identifier represents `RCTSound *` or some other Objective C class. I figure this also the reason why the old code relies on the `RCT_EXPORT_METHOD` macros to implement this very same feature: https://git.io/fjJsC. It uses `NSMethodSignature` to switch on the argument type, and then uses the `RCTMethodInfo` struct to parse the argument type name, from which it constructs the RCTConvert selector.

One caveat of the current solution is that it won't work work unless we decorate our TurboModule methods with `RCT_EXPORT_METHOD`.

Reviewed By: fkgozali

Differential Revision: D14582661

fbshipit-source-id: 3c7dfb2059f031dba7495f12cbdf406b14f0b5b4
2019-03-22 16:23:40 -07:00
..
Base Add support for argument conversion via RCTConvert 2019-03-22 16:23:40 -07:00
CxxBridge Introduce Module Setup Metric (#23859) 2019-03-22 10:43:00 -07:00
CxxModule Silence Xcode warning (#23880) 2019-03-12 22:08:21 -07:00
CxxUtils Update copyright headers to yearless format 2018-09-11 15:33:07 -07:00
DevSupport TM iOS: disable remote debugging toggle when TurboModule is active 2019-03-01 14:30:35 -08:00
Fabric Add copy for surface registry when return enumerator (#24056) 2019-03-21 23:37:18 -07:00
Inspector Don't reconnect inspector if connection refused (#22625) 2019-02-21 12:52:39 -08:00
Modules - add more iOS flags into AccessibilityInfo (#23913) 2019-03-15 11:34:20 -07:00
Profiler Fix PerfMonitor appearance when reloading JS (#24073) 2019-03-21 03:21:15 -07:00
React.xcodeproj Move Bridge RCTSurfacePresenterStub category implementation to .m file (#23888) 2019-03-15 11:22:53 -07:00
UIUtils Update copyright headers to yearless format 2018-09-11 15:33:07 -07:00
Views Fixed minuteInterval invalid in time mode (#23923) 2019-03-15 11:34:20 -07:00
React-Core.podspec Split React.podspec into separate podspecs for each Xcode project (#23559) 2019-02-21 18:35:44 -08:00
React-DevSupport.podspec Split React.podspec into separate podspecs for each Xcode project (#23559) 2019-02-21 18:35:44 -08:00
React-RCTFabric.podspec Fabric: working podspecs & works in RNTester (#23803) 2019-03-15 23:59:22 -07:00
third-party.xcconfig Upgrade folly to v2018.10.22.00 for iOS (#21976) 2018-10-29 12:13:11 -07:00