Skip to content
This repository was archived by the owner on Jul 1, 2025. It is now read-only.

A collection of sample React Native Libraries that will show you how to use the New Architecture (Fabric & TurboModules) step-by-step.

License

Notifications You must be signed in to change notification settings

react-native-community/RNNewArchitectureLibraries

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 

Repository files navigation

RUN

This run starts from the feat/back-turbomodule-070 branch. Start from there up to the [TurboModule] Test the Turbomodule section. Then, follow the steps below to move your logic to a Swift implementation file.

Table of contents

Steps

  1. cd NewArchitecture - It has been created in this step.
  2. yarn add react-native@0.71.0-rc.3
  1. Open the calculator/calculator.podspec file
  2. Update it as it follows:
require "json"

package = JSON.parse(File.read(File.join(__dir__, "package.json")))

-folly_version = '2021.07.22.00'
-folly_compiler_flags = '-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1 -Wno-comma -Wno-shorten-64-to-32'

Pod::Spec.new do |s|
  s.name            = "calculator"
  s.version         = package["version"]
  s.summary         = package["description"]
  s.description     = package["description"]
  s.homepage        = package["homepage"]
  s.license         = package["license"]
  s.platforms       = { :ios => "11.0" }
  s.author          = package["author"]
  s.source          = { :git => package["repository"], :tag => "#{s.version}" }

  s.source_files    = "ios/**/*.{h,m,mm,swift}"

+  s.pod_target_xcconfig    = {
+    "DEFINE_MODULES" => "YES",
+    "BUILD_LIBRARY_FOR_DISTRIBUTION" => "YES",
+    "SWIFT_OBJC_BRIDGING_HEADER" => "../../node_modules/calculator/ios/calculator-Bridging-Header.h"
+  }

+  install_modules_dependencies(s)
-  # This guard prevent to install the dependencies when we run `pod install` in the old architecture.
-  if ENV['RCT_NEW_ARCH_ENABLED'] == '1' then
-      s.compiler_flags = folly_compiler_flags + " -DRCT_NEW_ARCH_ENABLED=1"
-      s.pod_target_xcconfig    = {
-          "HEADER_SEARCH_PATHS" => "\"$(PODS_ROOT)/boost\"",
-          "CLANG_CXX_LANGUAGE_STANDARD" => "c++17"
-      }
-
-      s.dependency "React-Codegen"
-      s.dependency "RCT-Folly", folly_version
-      s.dependency "RCTRequired"
-      s.dependency "RCTTypeSafety"
-      s.dependency "ReactCommon/turbomodule/core"
-  end
end
  1. Create a new file: calculator/ios/calculator-Bridging-Header.h with the following content
    //
    // Add the Objective-C headers that must imported by Swift files
    //
    Note: This file is used to specify some headers files that the Swift code should be able to import. For this example, it will stay empty. However, it is required to properly build the project.
  2. Create a new file calculator/ios/Calculator.swift with the implementation of the logic:
    import Foundation
    
    @objc
    class Calculator: NSObject {
    
      @objc
      static func add(a: Int, b: Int) -> Int {
        return a+b;
      }
    }

About

A collection of sample React Native Libraries that will show you how to use the New Architecture (Fabric & TurboModules) step-by-step.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published