-
I've been studying from ExecuteJsiTests.cpp to try to work out how to build a JSI-based native module. Unfortunately, although this file shows how to call I've also tried creating a JSI-based module using a manually-written Spec (as I don't understand any of the Codegen instructions), based on NativeBlobModuleSpec.g.h and BlobModule.h. However, On iOS and macOS, it's quite simple to write a JSI-based native module without Codegen and without Fabric. How would I do that in React Native Windows? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 4 replies
-
I came up with one possible approach. We declare the native class for our HostObject ( ReactNativeModule.hHere's the native module code:
banana.tsHere's how to call it in JavaScript-land:
Is there a more idiomatic approach than this, though? It seems a bit strange to do this all inline inside an And is it necessary to declare the classes inside the EDIT: Indeed, I've found that you can declare them in separate files just fine. |
Beta Was this translation helpful? Give feedback.
-
If you have a module written as a #include <TurboModuleProvider.h>
struct MySimpleTurboModule : facebook::react::TurboModule {
....
};
struct MySimpleTurboModulePackageProvider
: winrt::implements<MySimpleTurboModulePackageProvider, IReactPackageProvider> {
void CreatePackage(IReactPackageBuilder const &packageBuilder) noexcept {
AddTurboModuleProvider<MySimpleTurboModule>(packageBuilder, L"MySimpleTurboModule");
}
}; |
Beta Was this translation helpful? Give feedback.
-
Please check this test instead: https://github.com/microsoft/react-native-windows/blob/main/vnext/Microsoft.ReactNative.IntegrationTests/JsiTurboModuleTests.cpp The code in https://github.com/microsoft/react-native-windows/blob/main/vnext/Microsoft.ReactNative.IntegrationTests/ExecuteJsiTests.cpp shows how to use JSI in context of attributed Turbo Modules (they are designed after the Java and Objective-C Turbo Modules), not how to use the JSI Turbo Modules. |
Beta Was this translation helpful? Give feedback.
Please check this test instead: https://github.com/microsoft/react-native-windows/blob/main/vnext/Microsoft.ReactNative.IntegrationTests/JsiTurboModuleTests.cpp
It is an example how to apply @acoates-ms suggestion.
The code in https://github.com/microsoft/react-native-windows/blob/main/vnext/Microsoft.ReactNative.IntegrationTests/ExecuteJsiTests.cpp shows how to use JSI in context of attributed Turbo Modules (they are designed after the Java and Objective-C Turbo Modules), not how to use the JSI Turbo Modules.