Skip to content

Commit

Permalink
feat: Specify RN version in iOS
Browse files Browse the repository at this point in the history
  • Loading branch information
mrousavy committed Jan 13, 2025
1 parent 403d618 commit febed96
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 5 deletions.
4 changes: 2 additions & 2 deletions example/ios/NitroExample.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -628,7 +628,7 @@
"$(inherited)",
" ",
);
REACT_NATIVE_PATH = "${PODS_ROOT}/../../../node_modules/react-native";
REACT_NATIVE_PATH = "${PODS_ROOT}/../../node_modules/react-native";
SDKROOT = iphoneos;
SWIFT_ACTIVE_COMPILATION_CONDITIONS = "$(inherited) DEBUG";
SWIFT_OBJC_INTEROP_MODE = objcxx;
Expand Down Expand Up @@ -705,7 +705,7 @@
"$(inherited)",
" ",
);
REACT_NATIVE_PATH = "${PODS_ROOT}/../../../node_modules/react-native";
REACT_NATIVE_PATH = "${PODS_ROOT}/../../node_modules/react-native";
SDKROOT = iphoneos;
SWIFT_OBJC_INTEROP_MODE = objcxx;
USE_HERMES = true;
Expand Down
4 changes: 2 additions & 2 deletions example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1895,8 +1895,8 @@ SPEC CHECKSUMS:
glog: 08b301085f15bcbb6ff8632a8ebaf239aae04e6a
hermes-engine: 1949ca944b195a8bde7cbf6316b9068e19cf53c6
NitroImage: ff97c5986ea4619abd3d6399b886eac84f5a4b65
NitroModules: bbe10b61d6fefce0176ba06e6a34eea92efb7704
RCT-Folly: bf5c0376ffe4dd2cf438dcf86db385df9fdce648
NitroModules: a34f99b308a3bb5d4fc37cdb532d9ea44899442c
RCT-Folly: 84578c8756030547307e4572ab1947de1685c599
RCTDeprecation: 063fc281b30b7dc944c98fe53a7e266dab1a8706
RCTRequired: 8eda2a5a745f6081157a4f34baac40b65fe02b31
RCTTypeSafety: 0f96bf6c99efc33eb43352212703854933f22930
Expand Down
4 changes: 3 additions & 1 deletion packages/react-native-nitro-modules/NitroModules.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
require "json"
require_relative './nitro_pod_utils'

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

Pod::UI.puts "[NitroModules] 🔥 Your app is boosted by nitro modules!"

Expand Down Expand Up @@ -61,7 +63,7 @@ Pod::Spec.new do |s|
# Enables stricter modular headers
"DEFINES_MODULE" => "YES",
# C++ compiler flags, mainly for folly.
"GCC_PREPROCESSOR_DEFINITIONS" => "$(inherited) FOLLY_NO_CONFIG FOLLY_CFG_NO_COROUTINES"
"GCC_PREPROCESSOR_DEFINITIONS" => "$(inherited) FOLLY_NO_CONFIG FOLLY_CFG_NO_COROUTINES REACT_NATIVE_VERSION=#{react_native_version}"
}

s.dependency 'React-jsi'
Expand Down
22 changes: 22 additions & 0 deletions packages/react-native-nitro-modules/nitro_pod_utils.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
require "json"

def get_react_native_package_path()
pod_root = Pod::Config.instance.installation_root.to_s
return `cd "#{pod_root}" && node --print "require.resolve('react-native/package.json')"`.strip!
end

def has_react_native()
react_native_package_path = get_react_native_package_path()
return File.exist?(react_native_package_path)
end

def get_react_native_version()
react_native_package_path = get_react_native_package_path()
if !File.exist?(react_native_package_path)
raise "[NitroModules] Couldn't find react-native path! File '#{react_native_package_path}' doesn't exist!"
end
react_native_package = JSON.parse(File.read(react_native_package_path))
react_native_version = react_native_package['version']
Pod::UI.puts "[NitroModules] Found react-native #{react_native_version} in #{File.dirname(react_native_package_path)}!"
return react_native_version.split('.')[1].to_i
end
1 change: 1 addition & 0 deletions packages/react-native-nitro-modules/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"cpp/",
"app.plugin.js",
"*.podspec",
"nitro_pod_utils.rb",
"README.md"
],
"keywords": [
Expand Down

0 comments on commit febed96

Please sign in to comment.