Skip to content

Commit 62d0d52

Browse files
authored
Move ruby utils to module (#4245)
## Description In ruby, functions and variables are global by design. In #4232 we dealt with it by changing name of exported function. However, the correct approach would be to keep our utils in separate module. This has also been introduced in [Reanimated](software-mansion/react-native-reanimated#9617). ## Test plan `pod install`
1 parent 9a9f8b4 commit 62d0d52

2 files changed

Lines changed: 24 additions & 18 deletions

File tree

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ 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=#{rngh_get_react_native_minor_version()}"
8+
version_flag = "-DREACT_NATIVE_MINOR_VERSION=#{GestureHandlerUtils.get_react_native_minor_version()}"
99

1010
Pod::Spec.new do |s|
1111
# NPM package specification
Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,31 @@
1-
def rngh_try_to_parse_react_native_package_json(react_native_dir)
2-
react_native_package_json_path = File.join(react_native_dir, 'package.json')
1+
module GestureHandlerUtils
2+
module_function
33

4-
if !File.exist?(react_native_package_json_path)
5-
return nil
4+
def try_to_parse_react_native_package_json(react_native_dir)
5+
react_native_package_json_path = File.join(react_native_dir, 'package.json')
6+
7+
if !File.exist?(react_native_package_json_path)
8+
return nil
9+
end
10+
11+
return JSON.parse(File.read(react_native_package_json_path))
612
end
713

8-
return JSON.parse(File.read(react_native_package_json_path))
9-
end
14+
def get_react_native_minor_version()
15+
react_native_dir = File.dirname(`cd "#{Pod::Config.instance.installation_root.to_s}" && node --print "require.resolve('react-native/package.json')"`)
16+
react_native_json = try_to_parse_react_native_package_json(react_native_dir)
1017

11-
def rngh_get_react_native_minor_version()
12-
react_native_dir = File.dirname(`cd "#{Pod::Config.instance.installation_root.to_s}" && node --print "require.resolve('react-native/package.json')"`)
13-
react_native_json = rngh_try_to_parse_react_native_package_json(react_native_dir)
18+
if react_native_json == nil
19+
node_modules_dir = ENV["REACT_NATIVE_NODE_MODULES_DIR"]
20+
if node_modules_dir != nil
21+
react_native_json = try_to_parse_react_native_package_json(File.join(node_modules_dir, 'react-native'))
22+
end
23+
end
1424

15-
if react_native_json == nil
16-
node_modules_dir = ENV["REACT_NATIVE_NODE_MODULES_DIR"]
17-
react_native_json = rngh_try_to_parse_react_native_package_json(File.join(node_modules_dir, 'react-native'))
18-
end
25+
if react_native_json == nil
26+
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`.'
27+
end
1928

20-
if react_native_json == nil
21-
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`.'
29+
return react_native_json['version'].split('.')[1].to_i
2230
end
23-
24-
return react_native_json['version'].split('.')[1].to_i
2531
end

0 commit comments

Comments
 (0)