Skip to content

Backwards compatible turbomodule library does not work on iOS with New Arch Enabled #386

@joshuayoes

Description

@joshuayoes

Description

The example project for Turbo module with backward compat does not provide an implementation for the multiply method for Turbo Modules on iOS when new architecture is enabled.

I was able to fix this by adding the following git diff, but it would be nice for the template to provide this. This was adapted from this example from the docs: https://reactnative.dev/docs/the-new-architecture/pillars-turbomodules#rtncalculatormm

--- a/ios/RTNCalculator.mm
+++ b/ios/RTNCalculator.mm
@@ -17,6 +17,11 @@ RCT_REMAP_METHOD(multiply,
 
 // Don't compile this code when we build for the old architecture.
 #ifdef RCT_NEW_ARCH_ENABLED
+- (void)multiply:(double)a b:(double)b resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject {
+    NSNumber *result = [[NSNumber alloc] initWithInteger:a*b];
+    resolve(result);
+}
+
 - (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:
     (const facebook::react::ObjCTurboModule::InitParams &)params
 {

Also see this commit: joshuayoes/RTNCalculator@6e860ef

This file should be updated: packages/create-react-native-library/templates/objc-library/ios/{%- project.name %}.mm

Or a new template like packages/create-react-native-library/templates/objc-library-mixed should be added.

Packages

  • create-react-native-library
  • react-native-builder-bob

Selected options

npx create-react-native-library@latest RTNCalculator

✔ What is the name of the npm package? … react-native-odometer
✔ What is the description for the package? …
✔ What is the name of package author? … Joshua Yoes
✔ What is the email address for the package author? … [email protected]
✔ What is the URL for the package author? … https://github.com/joshuayoes
✔ What is the URL for the repository? … https://github.com/joshuayoes/react-native-calculator
✔ What type of library do you want to develop? › Turbo module with backward compat
✔ Which languages do you want to use? › Java & Objective-C

Link to repro

https://github.com/joshuayoes/RTNCalculator

Environment

System:
    OS: macOS 13.2.1
    CPU: (10) arm64 Apple M1 Max
    Memory: 540.17 MB / 32.00 GB
    Shell: 5.8.1 - /bin/zsh
  Binaries:
    Node: 18.7.0 - ~/.asdf/installs/nodejs/18.7.0/bin/node
    Yarn: 1.22.19 - ~/.asdf/installs/nodejs/18.7.0/bin/yarn
    npm: 8.15.0 - ~/.asdf/plugins/nodejs/shims/npm
    Watchman: 2023.01.23.00 - /opt/homebrew/bin/watchman
  Managers:
    CocoaPods: 1.12.0 - /Users/joshuayoes/.asdf/shims/pod
  SDKs:
    iOS SDK:
      Platforms: DriverKit 22.2, iOS 16.2, macOS 13.1, tvOS 16.1, watchOS 9.1
    Android SDK:
      API Levels: 28, 29, 30, 31, 33
      Build Tools: 30.0.2, 30.0.3, 31.0.0, 33.0.0
      System Images: android-31 | ARM 64 v8a, android-33 | Google APIs ARM 64 v8a, android-33 | Google Play ARM 64 v8a
      Android NDK: 22.1.7171670
  IDEs:
    Android Studio: 2021.2 AI-212.5712.43.2112.8815526
    Xcode: 14.2/14C18 - /usr/bin/xcodebuild
  Languages:
    Java: 11.0.16.1 - /Users/joshuayoes/.asdf/shims/javac
  npmPackages:
    @react-native-community/cli: Not Found
    react: 18.2.0 => 18.2.0
    react-native: 0.71.7 => 0.71.7
    react-native-macos: Not Found
  npmGlobalPackages:
    *react-native*: Not Found

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions