Skip to content

Commit 0d4b34f

Browse files
authored
Remove REACT_NATIVE_MINOR_VERSION build flag (#4422)
## Description This PR removes the `REACT_NATIVE_MINOR_VERSION` build flag and fixes the `target_compile_reactnative_options` call in the Android `CMakeLists`. The only consumer of `REACT_NATIVE_MINOR_VERSION` was a >= 81 check in `RNGHRuntimeDecorator.cpp`, which is always true on supported react-native versions. If a version check becomes necessary in the future, react-native ships `<cxxreact/ReactNativeVersion.h>` with the `REACT_NATIVE_VERSION_MINOR` macro, available on all platforms and build systems. The `target_compile_reactnative_options` block added in #3688 never executed: it ran before `find_package(ReactAndroid)` defines `ReactAndroid_VERSION_MINOR`, referenced an undefined `LIB_TARGET_NAME`, and was missing the include of `react-native-flags.cmake` that defines the function. This PR fixes it to match how reanimated and worklets use it. Note that this applies RN_SERIALIZABLE_STATE and HERMES_V1_ENABLED=1 to our JNI target for the first time, matching how ReactAndroid itself is built. ## Test plan - basic-example builds and launches on iOS (pod install + yarn ios) - basic-example builds on Android (assembleDebug, -Wall -Werror, no new warnings) - compile_commands.json confirms RN_SERIALIZABLE_STATE and HERMES_V1_ENABLED=1 are applied to all translation units - basic-example builds under the experimental SwiftPM setup from react-native 0.87 - pod ipc spec evaluates the modified podspec cleanly
1 parent 3e4497e commit 0d4b34f

5 files changed

Lines changed: 6 additions & 56 deletions

File tree

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ 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=#{GestureHandlerUtils.get_react_native_minor_version()}"
98
use_worklets = GestureHandlerUtils.react_native_worklets_supports_stable_api()
109
worklets_flag = use_worklets ? '-DRNGH_USE_WORKLETS=1' : ''
1110

@@ -24,7 +23,7 @@ Pod::Spec.new do |s|
2423
s.requires_arc = true
2524
s.platforms = { ios: '15.1', tvos: '15.1', osx: '14.0', visionos: '1.0' }
2625
s.xcconfig = {
27-
"OTHER_CFLAGS" => "$(inherited) #{compilation_metadata_generation_flag} #{version_flag} #{worklets_flag}"
26+
"OTHER_CFLAGS" => "$(inherited) #{compilation_metadata_generation_flag} #{worklets_flag}"
2827
}
2928

3029
install_modules_dependencies(s);

packages/react-native-gesture-handler/android/build.gradle

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -146,12 +146,6 @@ def reactNativeArchitectures() {
146146

147147
def REACT_NATIVE_DIR = resolveReactNativeDirectory()
148148

149-
def reactProperties = new Properties()
150-
file("$REACT_NATIVE_DIR/ReactAndroid/gradle.properties").withInputStream { reactProperties.load(it) }
151-
152-
def REACT_NATIVE_VERSION = reactProperties.getProperty("VERSION_NAME")
153-
def REACT_NATIVE_MINOR_VERSION = REACT_NATIVE_VERSION.split("\\.")[1].toInteger()
154-
155149
repositories {
156150
mavenCentral()
157151
}
@@ -177,13 +171,11 @@ android {
177171
defaultConfig {
178172
minSdkVersion safeExtGet('minSdkVersion', 24)
179173
targetSdkVersion safeExtGet('targetSdkVersion', 33)
180-
buildConfigField "int", "REACT_NATIVE_MINOR_VERSION", REACT_NATIVE_MINOR_VERSION.toString()
181174

182175
externalNativeBuild {
183176
cmake {
184177
cppFlags "-O2", "-frtti", "-fexceptions", "-Wall", "-Werror", "-std=c++20", "-DANDROID"
185178
arguments "-DREACT_NATIVE_DIR=${REACT_NATIVE_DIR}",
186-
"-DREACT_NATIVE_MINOR_VERSION=${REACT_NATIVE_MINOR_VERSION}",
187179
"-DRNGH_USE_WORKLETS=${shouldUseRuntimeFromWorklets()}",
188180
"-DANDROID_STL=c++_shared",
189181
"-DANDROID_SUPPORT_FLEXIBLE_PAGE_SIZES=ON"

packages/react-native-gesture-handler/android/src/main/jni/CMakeLists.txt

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,8 @@
11
project(GestureHandler)
22
cmake_minimum_required(VERSION 3.9.0)
33

4-
string(
5-
APPEND
6-
CMAKE_CXX_FLAGS
7-
" -DREACT_NATIVE_MINOR_VERSION=${REACT_NATIVE_MINOR_VERSION}")
8-
94
set(CMAKE_VERBOSE_MAKEFILE ON)
10-
if(${REACT_NATIVE_MINOR_VERSION} GREATER_EQUAL 73)
11-
set(CMAKE_CXX_STANDARD 20)
12-
else()
13-
set(CMAKE_CXX_STANDARD 17)
14-
endif()
5+
set(CMAKE_CXX_STANDARD 20)
156

167
set(PACKAGE_NAME "gesturehandler")
178
set(RNGH_DIR "${CMAKE_SOURCE_DIR}/../../../../")
@@ -23,6 +14,8 @@ file(GLOB_RECURSE gesture_handler_shared_SRCS CONFIGURE_DEPENDS "${RNGH_DIR}/sha
2314
include(${REACT_ANDROID_DIR}/cmake-utils/folly-flags.cmake)
2415
add_compile_options(${folly_FLAGS})
2516

17+
include(${REACT_NATIVE_DIR}/ReactCommon/cmake-utils/react-native-flags.cmake)
18+
2619
add_library(${PACKAGE_NAME}
2720
SHARED
2821
${gesture_handler_SRCS}
@@ -38,13 +31,11 @@ target_include_directories(
3831
"${REACT_NATIVE_DIR}/ReactCommon"
3932
)
4033

41-
if(ReactAndroid_VERSION_MINOR GREATER_EQUAL 80)
42-
target_compile_reactnative_options(${LIB_TARGET_NAME} PRIVATE)
43-
endif()
44-
4534
find_package(ReactAndroid REQUIRED CONFIG)
4635
find_package(fbjni REQUIRED CONFIG)
4736

37+
target_compile_reactnative_options(${PACKAGE_NAME} PRIVATE)
38+
4839
target_link_libraries(
4940
${PACKAGE_NAME}
5041
ReactAndroid::reactnative

packages/react-native-gesture-handler/scripts/gesture_handler_utils.rb

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -5,34 +5,6 @@ module GestureHandlerUtils
55

66
MIN_REACT_NATIVE_WORKLETS_VERSION = Gem::Version.new('0.8.0')
77

8-
def try_to_parse_react_native_package_json(react_native_dir)
9-
react_native_package_json_path = File.join(react_native_dir, 'package.json')
10-
11-
if !File.exist?(react_native_package_json_path)
12-
return nil
13-
end
14-
15-
return JSON.parse(File.read(react_native_package_json_path))
16-
end
17-
18-
def get_react_native_minor_version()
19-
react_native_dir = File.dirname(`cd "#{Pod::Config.instance.installation_root.to_s}" && node --print "require.resolve('react-native/package.json')"`)
20-
react_native_json = try_to_parse_react_native_package_json(react_native_dir)
21-
22-
if react_native_json == nil
23-
node_modules_dir = ENV["REACT_NATIVE_NODE_MODULES_DIR"]
24-
if node_modules_dir != nil
25-
react_native_json = try_to_parse_react_native_package_json(File.join(node_modules_dir, 'react-native'))
26-
end
27-
end
28-
29-
if react_native_json == nil
30-
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`.'
31-
end
32-
33-
return react_native_json['version'].split('.')[1].to_i
34-
end
35-
368
def node_package_dir(package_name)
379
package_json_path = `cd "#{Pod::Config.instance.installation_root.to_s}" && node --print "require.resolve('#{package_name}/package.json')" 2>/dev/null`.strip
3810

packages/react-native-gesture-handler/shared/runtime/RNGHRuntimeDecorator.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,8 @@ void RNGHRuntimeDecorator::installRNRuntimeBindings(
3232
return jsi::Value::null();
3333
}
3434

35-
#if REACT_NATIVE_MINOR_VERSION >= 81
3635
auto shadowNode = Bridging<std::shared_ptr<const ShadowNode>>::fromJs(
3736
runtime, args[0]);
38-
#else
39-
auto shadowNode = shadowNodeFromValue(runtime, args[0]);
40-
#endif
4137

4238
#ifndef ANDROID
4339
if (dynamic_pointer_cast<const ParagraphShadowNode>(shadowNode)) {

0 commit comments

Comments
 (0)