Skip to content

Implement C++ NativeModules APIs for TurboModules #4548

@vmoroz

Description

@vmoroz

Current RNW NativeModules (aka NativeModules 2.0) are plain C++ structs augmented with custom attributes that help to expose its members to JavaScript. The custom attributes are macros that implement static functions to provide registration through some "template magic" at compile time.

We see that the C++ TurboModules must share exactly the same implementation. The only difference is how these modules are registered. A TurboModule implementation will be checked against generated specification at compile time during registration.

From the Flow-based TurboModule specification file we will generate a constexpr function that helps validate signature of NativeModule's members. All TurboModule members will be matched by their names in this function. The constexpr functions are evaluated only at compile time and have no impact at runtime.

As alternative to the constexpr spec verification function, we could have an abstract virtual interface, but it would require us to have only one possible implementation for a function. In our case we want to expose the same flexibility as NativeModules 2.0 where the same async method can be implemented using different C++ method signatures. E.g. a simple method method could return result as a function return value, while complex method may return it using a callback, and have co-routine or not co-routine based implementation.

We must expose similar functionality for C#-based TurboModules. It will be a subject of different task.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions