Skip to content

Commit 48f41d9

Browse files
committed
Add conditional on iOS
1 parent 4132f6e commit 48f41d9

3 files changed

Lines changed: 31 additions & 2 deletions

File tree

packages/react-native-gesture-handler/RNGestureHandler.podspec

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
require "json"
2-
2+
require_relative '../../scripts/gesture_handler_utils'
33

44
is_gh_example_app = ENV["GH_EXAMPLE_APP_NAME"] != nil
55

66
compilation_metadata_dir = "CompilationDatabase"
77
compilation_metadata_generation_flag = is_gh_example_app ? '-gen-cdb-fragment-path ' + compilation_metadata_dir : ''
8+
version_flag = "-DREACT_NATIVE_MINOR_VERSION=#{get_react_native_minor_version()}"
89

910
Pod::Spec.new do |s|
1011
# NPM package specification
@@ -21,7 +22,7 @@ Pod::Spec.new do |s|
2122
s.requires_arc = true
2223
s.platforms = { ios: '11.0', tvos: '11.0', osx: '10.15', visionos: '1.0' }
2324
s.xcconfig = {
24-
"OTHER_CFLAGS" => "$(inherited) " + compilation_metadata_generation_flag
25+
"OTHER_CFLAGS" => "$(inherited) #{compilation_metadata_generation_flag} #{version_flag}"
2526
}
2627

2728
if defined?(install_modules_dependencies()) != nil

packages/react-native-gesture-handler/apple/RNGestureHandlerModule.mm

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,12 @@ void decorateRuntime(jsi::Runtime &runtime)
101101
if (!arguments[0].isObject()) {
102102
return jsi::Value::null();
103103
}
104+
105+
#if REACT_NATIVE_MINOR_VERSION >= 81
104106
auto shadowNode = Bridging<std::shared_ptr<const ShadowNode>>::fromJs(runtime, arguments[0]);
107+
#else
108+
auto shadowNode = shadowNodeFromValue(runtime, arguments[0]);
109+
#endif
105110

106111
if (dynamic_pointer_cast<const ParagraphShadowNode>(shadowNode)) {
107112
return jsi::Value(true);

scripts/gesture_handler_utils.rb

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
def try_to_parse_react_native_package_json(node_modules_dir)
2+
react_native_package_json_path = File.join(node_modules_dir, 'react-native/package.json')
3+
if !File.exist?(react_native_package_json_path)
4+
return nil
5+
end
6+
return JSON.parse(File.read(react_native_package_json_path))
7+
end
8+
9+
def get_react_native_minor_version()
10+
react_native_node_modules_dir = File.join(File.dirname(`cd "#{Pod::Config.instance.installation_root.to_s}" && node --print "require.resolve('react-native/package.json')"`), '..')
11+
react_native_json = try_to_parse_react_native_package_json(react_native_node_modules_dir)
12+
13+
if react_native_json == nil
14+
node_modules_dir = ENV["REACT_NATIVE_NODE_MODULES_DIR"]
15+
react_native_json = try_to_parse_react_native_package_json(node_modules_dir)
16+
end
17+
18+
if react_native_json == nil
19+
raise '[react-native-gesture-handler] Unable to recognize your `react-native` version. Please set environmental variable with `react-native` location: `export REACT_NATIVE_NODE_MODULES_DIR="<path to react-native>" && pod install`.'
20+
end
21+
22+
return react_native_json['version'].split('.')[1].to_i
23+
end

0 commit comments

Comments
 (0)