Skip to content

Commit 30469ed

Browse files
LeoNatanfacebook-github-bot
authored andcommittedMar 2, 2018
Expose React Native version as a symbol rather than macro
Summary: Add RCTGetReactNativeVersion() to expose version in native code. Right now, version is exposed internally to RN using a MACRO constant. This exposes a symbol (function) that can be called to retrieve the React Native version in iOS. Also exposed RCTVersion.h as a public header in the React project so it is available to developers. The motivation behind this is for https://github.com/wix/detox —we need to know what RN version the user has, if any, so we can properly handle support and abstract differences. Ran bump-oss-version.js to ensure the template is applied properly. Also compiled the project to make sure nothing is broken. [IOS] [ENHANCEMENT] [RCTVersion.h] - Expose version as a compile-time symbol for native queries <!-- Help reviewers and the release process by writing your own release notes **INTERNAL and MINOR tagged notes will not be included in the next version's final release notes.** CATEGORY [----------] TYPE [ CLI ] [-------------] LOCATION [ DOCS ] [ BREAKING ] [-------------] [ GENERAL ] [ BUGFIX ] [-{Component}-] [ INTERNAL ] [ ENHANCEMENT ] [ {File} ] [ IOS ] [ FEATURE ] [ {Directory} ] |-----------| [ ANDROID ] [ MINOR ] [ {Framework} ] - | {Message} | [----------] [-------------] [-------------] |-----------| [CATEGORY] [TYPE] [LOCATION] - MESSAGE EXAMPLES: [IOS] [BREAKING] [FlatList] - Change a thing that breaks other things [ANDROID] [BUGFIX] [TextInput] - Did a thing to TextInput [CLI] [FEATURE] [local-cli/info/info.js] - CLI easier to do things with [DOCS] [BUGFIX] [GettingStarted.md] - Accidentally a thing/word [GENERAL] [ENHANCEMENT] [Yoga] - Added new yoga thing/position [INTERNAL] [FEATURE] [./scripts] - Added thing to script that nobody will see --> Closes #18136 Differential Revision: D7141076 Pulled By: hramos fbshipit-source-id: 18a92b8c60d7b43fa0ed22597ea46a35cff73c56
1 parent 7be3d1c commit 30469ed

File tree

7 files changed

+86
-26
lines changed

7 files changed

+86
-26
lines changed
 

‎React/Base/RCTPlatform.m

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ + (BOOL)requiresMainQueueSetup
4545
@"systemName": [device systemName],
4646
@"interfaceIdiom": interfaceIdiom([device userInterfaceIdiom]),
4747
@"isTesting": @(RCTRunningInTestEnvironment()),
48-
@"reactNativeVersion": RCT_REACT_NATIVE_VERSION,
48+
@"reactNativeVersion": RCTGetReactNativeVersion(),
4949
};
5050
}
5151

‎React/Base/RCTVersion.h

+9-8
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
/**
2-
* @generated by scripts/bump-oss-version.js
3-
*
42
* Copyright (c) 2015-present, Facebook, Inc.
53
*
64
* This source code is licensed under the MIT license found in the
75
* LICENSE file in the root directory of this source tree.
86
*/
97

10-
#define RCT_REACT_NATIVE_VERSION @{ \
11-
@"major": @(0), \
12-
@"minor": @(0), \
13-
@"patch": @(0), \
14-
@"prerelease": [NSNull null], \
15-
}
8+
9+
#import <Foundation/Foundation.h>
10+
11+
extern NSString* const RCTVersionMajor;
12+
extern NSString* const RCTVersionMinor;
13+
extern NSString* const RCTVersionPatch;
14+
extern NSString* const RCTVersionPrerelease;
15+
16+
extern NSDictionary* RCTGetReactNativeVersion(void);

‎React/Base/RCTVersion.m

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/**
2+
* @generated by scripts/bump-oss-version.js
3+
*
4+
* Copyright (c) 2015-present, Facebook, Inc.
5+
*
6+
* This source code is licensed under the MIT license found in the
7+
* LICENSE file in the root directory of this source tree.
8+
*/
9+
10+
#import "RCTVersion.h"
11+
12+
NSString* const RCTVersionMajor = @"major";
13+
NSString* const RCTVersionMinor = @"minor";
14+
NSString* const RCTVersionPatch = @"patch";
15+
NSString* const RCTVersionPrerelease = @"prerelease";
16+
17+
static NSDictionary* __rnVersion;
18+
19+
__attribute__((constructor))
20+
static void __makeVersion()
21+
{
22+
__rnVersion = @{
23+
RCTVersionMajor: @(0),
24+
RCTVersionMinor: @(0),
25+
RCTVersionPatch: @(0),
26+
RCTVersionPrerelease: [NSNull null],
27+
};
28+
}
29+
30+
NSDictionary* RCTGetReactNativeVersion(void)
31+
{
32+
return __rnVersion;
33+
}

‎React/React.xcodeproj/project.pbxproj

+8
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,9 @@
334334
352DCFF01D19F4C20056D623 /* RCTI18nUtil.m in Sources */ = {isa = PBXBuildFile; fileRef = 352DCFEF1D19F4C20056D623 /* RCTI18nUtil.m */; };
335335
369123E11DDC75850095B341 /* RCTJSCSamplingProfiler.m in Sources */ = {isa = PBXBuildFile; fileRef = 369123E01DDC75850095B341 /* RCTJSCSamplingProfiler.m */; };
336336
391E86A41C623EC800009732 /* RCTTouchEvent.m in Sources */ = {isa = PBXBuildFile; fileRef = 391E86A21C623EC800009732 /* RCTTouchEvent.m */; };
337+
39C50FF92046EACF00CEE534 /* RCTVersion.h in Copy Headers */ = {isa = PBXBuildFile; fileRef = 199B8A6E1F44DB16005DEF67 /* RCTVersion.h */; };
338+
39C50FFB2046EE3500CEE534 /* RCTVersion.m in Sources */ = {isa = PBXBuildFile; fileRef = 39C50FFA2046EE3500CEE534 /* RCTVersion.m */; };
339+
39C50FFC2046EE3500CEE534 /* RCTVersion.m in Sources */ = {isa = PBXBuildFile; fileRef = 39C50FFA2046EE3500CEE534 /* RCTVersion.m */; };
337340
3D05745A1DE5FFF500184BB4 /* RCTJavaScriptLoader.mm in Sources */ = {isa = PBXBuildFile; fileRef = AC70D2E81DE489E4002E6351 /* RCTJavaScriptLoader.mm */; };
338341
3D0B84221EC0B3F600B2BD8E /* RCTResizeMode.h in Copy Headers */ = {isa = PBXBuildFile; fileRef = 3D1FA0851DE4F3A000E03CC6 /* RCTResizeMode.h */; };
339342
3D0B84231EC0B40D00B2BD8E /* RCTImageLoader.h in Copy Headers */ = {isa = PBXBuildFile; fileRef = 3D1FA0831DE4F3A000E03CC6 /* RCTImageLoader.h */; };
@@ -1589,6 +1592,7 @@
15891592
dstPath = include/React;
15901593
dstSubfolderSpec = 16;
15911594
files = (
1595+
39C50FF92046EACF00CEE534 /* RCTVersion.h in Copy Headers */,
15921596
591F78DE202ADB8F004A668C /* RCTLayout.h in Copy Headers */,
15931597
59EDBCBD1FDF4E43003573DE /* RCTScrollableProtocol.h in Copy Headers */,
15941598
59EDBCBE1FDF4E43003573DE /* (null) in Copy Headers */,
@@ -2059,6 +2063,7 @@
20592063
369123E01DDC75850095B341 /* RCTJSCSamplingProfiler.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTJSCSamplingProfiler.m; sourceTree = "<group>"; };
20602064
391E86A21C623EC800009732 /* RCTTouchEvent.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTTouchEvent.m; sourceTree = "<group>"; };
20612065
391E86A31C623EC800009732 /* RCTTouchEvent.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTTouchEvent.h; sourceTree = "<group>"; };
2066+
39C50FFA2046EE3500CEE534 /* RCTVersion.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTVersion.m; sourceTree = "<group>"; };
20622067
3D0B84281EC0B49400B2BD8E /* RCTTVRemoteHandler.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTTVRemoteHandler.h; sourceTree = "<group>"; };
20632068
3D0B84291EC0B49400B2BD8E /* RCTTVRemoteHandler.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTTVRemoteHandler.m; sourceTree = "<group>"; };
20642069
3D0B842D1EC0B51200B2BD8E /* RCTTVNavigationEventEmitter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTTVNavigationEventEmitter.h; sourceTree = "<group>"; };
@@ -2997,6 +3002,7 @@
29973002
83CBBA4F1A601E3B00E9B192 /* RCTUtils.h */,
29983003
83CBBA501A601E3B00E9B192 /* RCTUtils.m */,
29993004
199B8A6E1F44DB16005DEF67 /* RCTVersion.h */,
3005+
39C50FFA2046EE3500CEE534 /* RCTVersion.m */,
30003006
599FAA291FB274970058CCF6 /* Surface */,
30013007
);
30023008
path = Base;
@@ -4153,6 +4159,7 @@
41534159
5960C1BC1F0804A00066FD5B /* RCTLayoutAnimationGroup.m in Sources */,
41544160
2D3B5ECF1D9B096F00451313 /* RCTFont.mm in Sources */,
41554161
2D3B5ED51D9B098000451313 /* RCTModalHostViewController.m in Sources */,
4162+
39C50FFC2046EE3500CEE534 /* RCTVersion.m in Sources */,
41564163
2D3B5EBC1D9B092600451313 /* RCTKeyboardObserver.m in Sources */,
41574164
657734931EE8356100A0E9EA /* RCTInspector.mm in Sources */,
41584165
59EB6DBE1EBD6FC90072A5E7 /* RCTUIManagerObserverCoordinator.mm in Sources */,
@@ -4467,6 +4474,7 @@
44674474
13D9FEEB1CDCCECF00158BD7 /* RCTEventEmitter.m in Sources */,
44684475
599FAA3E1FB274980058CCF6 /* RCTSurfaceRootShadowView.m in Sources */,
44694476
AC70D2E91DE489E4002E6351 /* RCTJavaScriptLoader.mm in Sources */,
4477+
39C50FFB2046EE3500CEE534 /* RCTVersion.m in Sources */,
44704478
14F7A0EC1BDA3B3C003C6C10 /* RCTPerfMonitor.m in Sources */,
44714479
5960C1B71F0804A00066FD5B /* RCTLayoutAnimation.m in Sources */,
44724480
13134C9E1E296B2A00B9F3CB /* RCTCxxModule.mm in Sources */,

‎scripts/bump-oss-version.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ fs.writeFileSync(
6767
);
6868

6969
fs.writeFileSync(
70-
'React/Base/RCTVersion.h',
71-
cat('scripts/versiontemplates/RCTVersion.h.template')
70+
'React/Base/RCTVersion.m',
71+
cat('scripts/versiontemplates/RCTVersion.m.template')
7272
.replace('${major}', `@(${major})`)
7373
.replace('${minor}', `@(${minor})`)
7474
.replace('${patch}', `@(${patch})`)

‎scripts/versiontemplates/RCTVersion.h.template

-15
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/**
2+
* @generated by scripts/bump-oss-version.js
3+
*
4+
* Copyright (c) 2015-present, Facebook, Inc.
5+
*
6+
* This source code is licensed under the MIT license found in the
7+
* LICENSE file in the root directory of this source tree.
8+
*/
9+
10+
#import "RCTVersion.h"
11+
12+
NSString* const RCTVersionMajor = @"major";
13+
NSString* const RCTVersionMinor = @"minor";
14+
NSString* const RCTVersionPatch = @"patch";
15+
NSString* const RCTVersionPrerelease = @"prerelease";
16+
17+
static NSDictionary* __rnVersion;
18+
19+
__attribute__((constructor))
20+
static void __makeVersion()
21+
{
22+
__rnVersion = @{
23+
RCTVersionMajor: ${major},
24+
RCTVersionMinor: ${minor},
25+
RCTVersionPatch: ${patch},
26+
RCTVersionPrerelease: ${prerelease},
27+
};
28+
}
29+
30+
NSDictionary* RCTGetReactNativeVersion(void)
31+
{
32+
return __rnVersion;
33+
}

0 commit comments

Comments
 (0)
Please sign in to comment.