Skip to content

Commit f3af7ce

Browse files
authored
fix: Add REACT_NATIVE_VERSION macro for backwards compatibility (#108)
1 parent eb80259 commit f3af7ce

File tree

9 files changed

+87
-14
lines changed

9 files changed

+87
-14
lines changed

example/ios/Podfile.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PODS:
22
- boost-for-react-native (1.63.0)
33
- DoubleConversion (1.1.6)
4-
- Example-Tests (0.1.2):
4+
- Example-Tests (0.1.4):
55
- React
66
- FBLazyVector (0.61.5)
77
- FBReactNativeSpec (0.61.5):
@@ -220,7 +220,7 @@ PODS:
220220
- React-cxxreact (= 0.61.5)
221221
- React-jsi (= 0.61.5)
222222
- ReactCommon/jscallinvoker (= 0.61.5)
223-
- ReactTestApp-DevSupport (0.1.2)
223+
- ReactTestApp-DevSupport (0.1.4)
224224
- ReactTestApp-Resources (1.0.0-dev)
225225
- SwiftLint (0.39.1)
226226
- Yoga (1.14.0)
@@ -327,7 +327,7 @@ EXTERNAL SOURCES:
327327
SPEC CHECKSUMS:
328328
boost-for-react-native: 39c7adb57c4e60d6c5479dd8623128eb5b3f0f2c
329329
DoubleConversion: 5805e889d232975c086db112ece9ed034df7a0b2
330-
Example-Tests: 6affe8047ddb57b68d6356dbc876e194ef9c64b8
330+
Example-Tests: a9469b2406804bcc1ac76e8f1c661f86ca653781
331331
FBLazyVector: aaeaf388755e4f29cd74acbc9e3b8da6d807c37f
332332
FBReactNativeSpec: 118d0d177724c2d67f08a59136eb29ef5943ec75
333333
Folly: 30e7936e1c45c08d884aa59369ed951a8e68cf51
@@ -352,7 +352,7 @@ SPEC CHECKSUMS:
352352
React-RCTText: 9ccc88273e9a3aacff5094d2175a605efa854dbe
353353
React-RCTVibration: a49a1f42bf8f5acf1c3e297097517c6b3af377ad
354354
ReactCommon: 198c7c8d3591f975e5431bec1b0b3b581aa1c5dd
355-
ReactTestApp-DevSupport: 67fa5247501557ce874d10b301a121e48966f926
355+
ReactTestApp-DevSupport: 33f1a78a766f1fe7931c3fbd0111439096dc2113
356356
ReactTestApp-Resources: c070f72dfcb2806d922eec6656259cbf7a4d2bcf
357357
SwiftLint: 55e96a4a4d537d4a3156859fc1c54bd24851a046
358358
Yoga: f2a7cd4280bfe2cca5a7aed98ba0eb3d1310f18b

example/macos/Podfile.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ PODS:
217217
- React-cxxreact (= 0.61.39)
218218
- React-jsi (= 0.61.39)
219219
- ReactCommon/jscallinvoker (= 0.61.39)
220-
- ReactTestApp-DevSupport (0.1.2)
220+
- ReactTestApp-DevSupport (0.1.4)
221221
- ReactTestApp-Resources (1.0.0-dev)
222222
- SwiftLint (0.39.2)
223223
- Yoga (1.14.0)
@@ -344,7 +344,7 @@ SPEC CHECKSUMS:
344344
React-RCTText: e81f5065516561545ae40f2c5b84d7b14fe6baec
345345
React-RCTVibration: 2ab29818330374b02167caac117d609159f360ab
346346
ReactCommon: e24f8c0d974cdb872d73cbd87cdfea9d72cfae26
347-
ReactTestApp-DevSupport: 67fa5247501557ce874d10b301a121e48966f926
347+
ReactTestApp-DevSupport: 33f1a78a766f1fe7931c3fbd0111439096dc2113
348348
ReactTestApp-Resources: c070f72dfcb2806d922eec6656259cbf7a4d2bcf
349349
SwiftLint: 22ccbbe3b8008684be5955693bab135e0ed6a447
350350
Yoga: 9cc54b8ca13d6fa87f8214c6eac97745e1df8092

ios/ReactTestApp.xcodeproj/project.pbxproj

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
/* Begin PBXBuildFile section */
1010
1914199A234B2DD800D856AE /* RCTDevSupport+UIScene.m in Sources */ = {isa = PBXBuildFile; fileRef = 19141999234B2DD800D856AE /* RCTDevSupport+UIScene.m */; };
1111
192DD201240FCAF5004E9CEB /* Manifest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 192DD200240FCAF5004E9CEB /* Manifest.swift */; };
12+
196C22622490CB7600449D3C /* React+Compatibility.m in Sources */ = {isa = PBXBuildFile; fileRef = 196C22602490CB7600449D3C /* React+Compatibility.m */; };
1213
196C7215232F1788006556ED /* ReactInstance.swift in Sources */ = {isa = PBXBuildFile; fileRef = 196C7214232F1788006556ED /* ReactInstance.swift */; };
1314
196C724123319A85006556ED /* QRCodeReaderDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 196C724023319A85006556ED /* QRCodeReaderDelegate.swift */; };
1415
1988284524105BEC005057FF /* UIViewController+ReactTestApp.m in Sources */ = {isa = PBXBuildFile; fileRef = 1988284424105BEC005057FF /* UIViewController+ReactTestApp.m */; };
@@ -44,6 +45,8 @@
4445
/* Begin PBXFileReference section */
4546
19141999234B2DD800D856AE /* RCTDevSupport+UIScene.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "RCTDevSupport+UIScene.m"; sourceTree = "<group>"; };
4647
192DD200240FCAF5004E9CEB /* Manifest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Manifest.swift; sourceTree = "<group>"; };
48+
196C22602490CB7600449D3C /* React+Compatibility.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "React+Compatibility.m"; sourceTree = "<group>"; };
49+
196C22612490CB7600449D3C /* React+Compatibility.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "React+Compatibility.h"; sourceTree = "<group>"; };
4750
196C7207232EF5DC006556ED /* ReactTestApp-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "ReactTestApp-Bridging-Header.h"; sourceTree = "<group>"; };
4851
196C7214232F1788006556ED /* ReactInstance.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReactInstance.swift; sourceTree = "<group>"; };
4952
196C7216232F6CD9006556ED /* ReactTestApp.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = ReactTestApp.entitlements; sourceTree = "<group>"; };
@@ -133,10 +136,12 @@
133136
192DD200240FCAF5004E9CEB /* Manifest.swift */,
134137
196C724023319A85006556ED /* QRCodeReaderDelegate.swift */,
135138
196C7214232F1788006556ED /* ReactInstance.swift */,
139+
196C7207232EF5DC006556ED /* ReactTestApp-Bridging-Header.h */,
136140
19141999234B2DD800D856AE /* RCTDevSupport+UIScene.m */,
141+
196C22612490CB7600449D3C /* React+Compatibility.h */,
142+
196C22602490CB7600449D3C /* React+Compatibility.m */,
137143
1988282224105BCC005057FF /* UIViewController+ReactTestApp.h */,
138144
1988284424105BEC005057FF /* UIViewController+ReactTestApp.m */,
139-
196C7207232EF5DC006556ED /* ReactTestApp-Bridging-Header.h */,
140145
19ECD0DB232ED427003D8557 /* Assets.xcassets */,
141146
19ECD0E0232ED427003D8557 /* LaunchScreen.storyboard */,
142147
19ECD0E3232ED427003D8557 /* Info.plist */,
@@ -432,6 +437,7 @@
432437
192DD201240FCAF5004E9CEB /* Manifest.swift in Sources */,
433438
196C724123319A85006556ED /* QRCodeReaderDelegate.swift in Sources */,
434439
1914199A234B2DD800D856AE /* RCTDevSupport+UIScene.m in Sources */,
440+
196C22622490CB7600449D3C /* React+Compatibility.m in Sources */,
435441
196C7215232F1788006556ED /* ReactInstance.swift in Sources */,
436442
19ECD0D8232ED425003D8557 /* SceneDelegate.swift in Sources */,
437443
1988284524105BEC005057FF /* UIViewController+ReactTestApp.m in Sources */,
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
//
2+
// Copyright (c) Microsoft Corporation
3+
//
4+
// This source code is licensed under the MIT license found in the
5+
// LICENSE file in the root directory of this source tree.
6+
//
7+
8+
#import <Foundation/Foundation.h>
9+
10+
@class RCTBridge;
11+
12+
void RTATriggerReloadCommand(RCTBridge *, NSString *reason);
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
//
2+
// Copyright (c) Microsoft Corporation
3+
//
4+
// This source code is licensed under the MIT license found in the
5+
// LICENSE file in the root directory of this source tree.
6+
//
7+
8+
#import "React+Compatibility.h"
9+
10+
#include <TargetConditionals.h>
11+
12+
#import <React/RCTBridge.h>
13+
14+
// `RCTReloadCommand.h` is excluded from `react-native-macos`
15+
// See https://github.com/microsoft/react-native-macos/blob/v0.61.39/React-Core.podspec#L66
16+
#if !TARGET_OS_OSX
17+
#import <React/RCTReloadCommand.h>
18+
#endif
19+
20+
void RTATriggerReloadCommand(RCTBridge *bridge, NSString *reason)
21+
{
22+
#if REACT_NATIVE_VERSION < 6200
23+
[bridge reload];
24+
#else
25+
RCTTriggerReloadCommandListeners(reason);
26+
#endif
27+
}

ios/ReactTestApp/ReactInstance.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ final class ReactInstance: NSObject, RCTBridgeDelegate, RCTTurboModuleLookupDele
8585
// -[RCTWebSocketExecutor executeApplicationScript:sourceURL:onComplete:]
8686
RCTDevSettings().isDebuggingRemotely = false
8787
}
88-
bridge.reload()
88+
RTATriggerReloadCommand(bridge, "ReactTestApp")
8989
} else if let bridge = RCTBridge(delegate: self, launchOptions: nil) {
9090
self.bridge = bridge
9191

ios/ReactTestApp/ReactTestApp-Bridging-Header.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,5 @@
1717
#import <React/RCTVersion.h>
1818
#import <ReactTestApp-DevSupport/ReactTestApp-DevSupport.h>
1919

20+
#import "React+Compatibility.h"
2021
#import "UIViewController+ReactTestApp.h"

ios/test_app.rb

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -110,13 +110,8 @@ def use_react_native!(project_root, target_platform)
110110
project_root)
111111
end
112112

113-
# rubocop:disable Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
114-
def use_test_app_internal!(target_platform)
115-
assert(%i[ios macos].include?(target_platform), "Unsupported platform: #{target_platform}")
116-
117-
xcodeproj = 'ReactTestApp.xcodeproj'
113+
def make_project!(xcodeproj, project_root, target_platform)
118114
src_xcodeproj = File.join(__dir__, '..', target_platform.to_s, xcodeproj)
119-
project_root = find_project_root
120115
destination = File.join(nearest_node_modules(project_root), '.generated', target_platform.to_s)
121116
dst_xcodeproj = File.join(destination, xcodeproj)
122117

@@ -137,6 +132,32 @@ def use_test_app_internal!(target_platform)
137132
FileUtils.ln_sf(source, File.join(destination, 'ReactTestAppShared'))
138133
end
139134

135+
react_native = Pathname.new(resolve_module('react-native'))
136+
version = package_version(react_native.to_s)
137+
version = version[:major].to_i * 10_000 + version[:minor].to_i * 100 + version[:patch].to_i
138+
version_macro = "REACT_NATIVE_VERSION=#{version}"
139+
140+
app_project = Xcodeproj::Project.open(dst_xcodeproj)
141+
app_project.native_targets.each do |target|
142+
next if target.name != 'ReactTestApp'
143+
144+
target.build_configurations.each do |config|
145+
config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= ['$(inherited)', version_macro]
146+
end
147+
end
148+
app_project.save
149+
150+
dst_xcodeproj
151+
end
152+
153+
# rubocop:disable Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
154+
def use_test_app_internal!(target_platform)
155+
assert(%i[ios macos].include?(target_platform), "Unsupported platform: #{target_platform}")
156+
157+
xcodeproj = 'ReactTestApp.xcodeproj'
158+
project_root = find_project_root
159+
dst_xcodeproj = make_project!(xcodeproj, project_root, target_platform)
160+
140161
require_relative(autolink_script_path)
141162

142163
platform :ios, '12.0' if target_platform == :ios

macos/ReactTestApp.xcodeproj/project.pbxproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
193EF08F247A799D00BE8C79 /* Manifest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 193EF08E247A799D00BE8C79 /* Manifest.swift */; };
1515
193EF093247A830200BE8C79 /* UIViewController+ReactTestApp.m in Sources */ = {isa = PBXBuildFile; fileRef = 193EF091247A830200BE8C79 /* UIViewController+ReactTestApp.m */; };
1616
193EF098247B130700BE8C79 /* ReactInstance.swift in Sources */ = {isa = PBXBuildFile; fileRef = 193EF097247B130700BE8C79 /* ReactInstance.swift */; };
17+
196C22652490CBAB00449D3C /* React+Compatibility.m in Sources */ = {isa = PBXBuildFile; fileRef = 196C22632490CBAB00449D3C /* React+Compatibility.m */; };
1718
/* End PBXBuildFile section */
1819

1920
/* Begin PBXContainerItemProxy section */
@@ -50,6 +51,8 @@
5051
193EF092247A830200BE8C79 /* UIViewController+ReactTestApp.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "UIViewController+ReactTestApp.h"; path = "../ReactTestAppShared/UIViewController+ReactTestApp.h"; sourceTree = "<group>"; };
5152
193EF094247A84DA00BE8C79 /* ReactTestApp-Bridging-Header.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "ReactTestApp-Bridging-Header.h"; path = "../ReactTestAppShared/ReactTestApp-Bridging-Header.h"; sourceTree = "<group>"; };
5253
193EF097247B130700BE8C79 /* ReactInstance.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = ReactInstance.swift; path = ../ReactTestAppShared/ReactInstance.swift; sourceTree = "<group>"; };
54+
196C22632490CBAB00449D3C /* React+Compatibility.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = "React+Compatibility.m"; path = "../ReactTestAppShared/React+Compatibility.m"; sourceTree = "<group>"; };
55+
196C22642490CBAB00449D3C /* React+Compatibility.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "React+Compatibility.h"; path = "../ReactTestAppShared/React+Compatibility.h"; sourceTree = "<group>"; };
5356
/* End PBXFileReference section */
5457

5558
/* Begin PBXFrameworksBuildPhase section */
@@ -105,6 +108,8 @@
105108
193EF097247B130700BE8C79 /* ReactInstance.swift */,
106109
193EF064247A736200BE8C79 /* ViewController.swift */,
107110
193EF094247A84DA00BE8C79 /* ReactTestApp-Bridging-Header.h */,
111+
196C22642490CBAB00449D3C /* React+Compatibility.h */,
112+
196C22632490CBAB00449D3C /* React+Compatibility.m */,
108113
193EF092247A830200BE8C79 /* UIViewController+ReactTestApp.h */,
109114
193EF091247A830200BE8C79 /* UIViewController+ReactTestApp.m */,
110115
193EF066247A736300BE8C79 /* Assets.xcassets */,
@@ -286,6 +291,7 @@
286291
files = (
287292
193EF063247A736200BE8C79 /* AppDelegate.swift in Sources */,
288293
193EF08F247A799D00BE8C79 /* Manifest.swift in Sources */,
294+
196C22652490CBAB00449D3C /* React+Compatibility.m in Sources */,
289295
193EF098247B130700BE8C79 /* ReactInstance.swift in Sources */,
290296
193EF065247A736200BE8C79 /* ViewController.swift in Sources */,
291297
193EF093247A830200BE8C79 /* UIViewController+ReactTestApp.m in Sources */,

0 commit comments

Comments
 (0)