Skip to content

Commit a63fd37

Browse files
douglowderfacebook-github-bot
authored andcommitted
Link both iOS and tvOS libraries with react-native link (fix #13783)
Summary: Fix issues with the react-native CLI when linking iOS and tvOS libraries to a project created with `react-native init`. (#13783) Verified the changes against test project at https://github.com/dlowder-salesforce/react-native-link-test. Both `react-native link react-native-svg` and `react-native unlink react-native-svg` work correctly on this project. Added new unit test for the new file added to `local-cli/link/ios`. [CLI] [BUGFIX] `react-native link` has been fixed to correctly link iOS and tvOS targets. [IOS] [BUGFIX] `react-native link` has been fixed to correctly link iOS and tvOS targets. Closes #17231 Differential Revision: D6837567 Pulled By: hramos fbshipit-source-id: 234d3d3966ae1b89cd16a37c95d303553f7ba5f5
1 parent 5fba82d commit a63fd37

11 files changed

+88
-9
lines changed

React/Modules/RCTRedBoxExtraDataViewController.m

+2-3
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,8 @@ - (instancetype)initWithStyle:(UITableViewCellStyle)style
4646
self.keyLabel.numberOfLines = 0;
4747
#if !TARGET_OS_TV
4848
self.keyLabel.lineBreakMode = UILineBreakModeWordWrap;
49-
#endif
5049
self.keyLabel.font = [UIFont fontWithName:@"Menlo-Regular" size:12.0f];
51-
50+
#endif
5251
self.valueLabel = [UILabel new];
5352
[self.contentView addSubview:self.valueLabel];
5453

@@ -67,8 +66,8 @@ - (instancetype)initWithStyle:(UITableViewCellStyle)style
6766
self.valueLabel.numberOfLines = 0;
6867
#if !TARGET_OS_TV
6968
self.valueLabel.lineBreakMode = UILineBreakModeWordWrap;
70-
#endif
7169
self.valueLabel.font = [UIFont fontWithName:@"Menlo-Regular" size:12.0f];
70+
#endif
7271
}
7372
return self;
7473
}

React/React.xcodeproj/project.pbxproj

+4
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,7 @@
256256
27595AD61E575C7800CCE2B1 /* Platform.h in Headers */ = {isa = PBXBuildFile; fileRef = 3D92B0D21E03699D0018521A /* Platform.h */; };
257257
27595AD71E575C7800CCE2B1 /* SampleCxxModule.h in Headers */ = {isa = PBXBuildFile; fileRef = 3D92B0D41E03699D0018521A /* SampleCxxModule.h */; };
258258
27595AD81E575C7800CCE2B1 /* SystraceSection.h in Headers */ = {isa = PBXBuildFile; fileRef = 3D92B0D51E03699D0018521A /* SystraceSection.h */; };
259+
2D0EB9F32021067800CAF88A /* RCTUIUtils.m in Sources */ = {isa = PBXBuildFile; fileRef = F1EFDA4E201F660F00EE6E4C /* RCTUIUtils.m */; };
259260
2D16E68E1FA4FD3900B85C8A /* RCTTVNavigationEventEmitter.h in Copy Headers */ = {isa = PBXBuildFile; fileRef = 3D0B842D1EC0B51200B2BD8E /* RCTTVNavigationEventEmitter.h */; };
260261
2D1D83CD1F74E2CE00615550 /* libprivatedata-tvOS.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 9936F32F1F5F2E5B0010BF04 /* libprivatedata-tvOS.a */; };
261262
2D1D83CE1F74E2DA00615550 /* libdouble-conversion.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 3D383D621EBD27B9005632C8 /* libdouble-conversion.a */; };
@@ -328,6 +329,7 @@
328329
2D3B5EF11D9B09E700451313 /* UIView+React.m in Sources */ = {isa = PBXBuildFile; fileRef = 13E067541A70F44B002CDEE1 /* UIView+React.m */; };
329330
2D74EAFA1DAE9590003B751B /* RCTMultipartDataTask.m in Sources */ = {isa = PBXBuildFile; fileRef = 006FC4131D9B20820057AAAD /* RCTMultipartDataTask.m */; };
330331
2D8C2E331DA40441000EE098 /* RCTMultipartStreamReader.m in Sources */ = {isa = PBXBuildFile; fileRef = 001BFCCF1D8381DE008E587E /* RCTMultipartStreamReader.m */; };
332+
2DCCC3151FE48142007C5315 /* RCTRedBoxExtraDataViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = FEFAAC9C1FDB89B40057BBE0 /* RCTRedBoxExtraDataViewController.m */; };
331333
2DD0EFE11DA84F2800B0C975 /* RCTStatusBarManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 13723B4F1A82FD3C00F88898 /* RCTStatusBarManager.m */; };
332334
352DCFF01D19F4C20056D623 /* RCTI18nUtil.m in Sources */ = {isa = PBXBuildFile; fileRef = 352DCFEF1D19F4C20056D623 /* RCTI18nUtil.m */; };
333335
369123E11DDC75850095B341 /* RCTJSCSamplingProfiler.m in Sources */ = {isa = PBXBuildFile; fileRef = 369123E01DDC75850095B341 /* RCTJSCSamplingProfiler.m */; };
@@ -4108,6 +4110,7 @@
41084110
598FD1931F817284006C54CB /* PrivateDataBase.cpp in Sources */,
41094111
3DC159E41E83E1AE007B1282 /* RCTRootContentView.m in Sources */,
41104112
3D80D91B1DF6F8200028D040 /* RCTPlatform.m in Sources */,
4113+
2D0EB9F32021067800CAF88A /* RCTUIUtils.m in Sources */,
41114114
2DD0EFE11DA84F2800B0C975 /* RCTStatusBarManager.m in Sources */,
41124115
2D3B5EC91D9B095C00451313 /* RCTBorderDrawing.m in Sources */,
41134116
66CD94B81F1045E700CB3C7C /* RCTMaskedViewManager.m in Sources */,
@@ -4166,6 +4169,7 @@
41664169
C606692F1F3CC60500E67165 /* RCTModuleMethod.mm in Sources */,
41674170
2D3B5E9F1D9B08AF00451313 /* RCTKeyCommands.m in Sources */,
41684171
2D3B5EA51D9B08C700451313 /* RCTRootView.m in Sources */,
4172+
2DCCC3151FE48142007C5315 /* RCTRedBoxExtraDataViewController.m in Sources */,
41694173
13134C871E296B2A00B9F3CB /* RCTCxxBridge.mm in Sources */,
41704174
CF2731C31E7B8DF30044CA4F /* RCTDeviceInfo.m in Sources */,
41714175
599FAA3F1FB274980058CCF6 /* RCTSurfaceRootShadowView.m in Sources */,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/**
2+
* Copyright (c) 2013-present, Facebook, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the BSD-style license found in the
6+
* LICENSE file in the root directory of this source tree. An additional grant
7+
* of patent rights can be found in the PATENTS file in the same directory.
8+
*
9+
* All rights reserved.
10+
*
11+
* @emails oncall+javascript_foundation
12+
*/
13+
14+
'use strict';
15+
16+
const xcode = require('xcode');
17+
const getTargets = require('../../ios/getTargets');
18+
const path = require('path');
19+
20+
const project = xcode.project(
21+
path.join(__dirname, '../../__fixtures__/project.pbxproj')
22+
);
23+
24+
describe('ios::getTargets', () => {
25+
beforeEach(() => {
26+
project.parseSync();
27+
});
28+
29+
it('should return an array of project targets', () => {
30+
const targets = getTargets(project);
31+
expect(targets.length).toBe(2);
32+
expect(targets[0].name).toContain('Basic.app');
33+
expect(targets[1].name).toContain('BasicTests.xctest');
34+
});
35+
});

local-cli/link/ios/getTargets.js

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/**
2+
* Given xcodeproj it returns list of targets
3+
*/
4+
module.exports = function getTargets(project) {
5+
let targets = project.getFirstProject().firstProject.targets;
6+
let nativeTargetSection = project.pbxNativeTargetSection();
7+
return targets.map(function(target) {
8+
let key = target.value;
9+
let configurationListId = project.pbxNativeTargetSection()[key].buildConfigurationList;
10+
let configurationList = project.pbxXCConfigurationList()[configurationListId];
11+
let buildConfigurationId = configurationList.buildConfigurations[0].value;
12+
let buildConfiguration = project.pbxXCBuildConfigurationSection()[buildConfigurationId];
13+
return {
14+
uuid: key,
15+
target: nativeTargetSection[key],
16+
name: nativeTargetSection[key].productReference_comment,
17+
isTVOS: (buildConfiguration.buildSettings.SDKROOT && (buildConfiguration.buildSettings.SDKROOT.indexOf('appletv') !== -1)) || false
18+
}
19+
});
20+
};

local-cli/link/ios/registerNativeModule.js

+24-4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const addToHeaderSearchPaths = require('./addToHeaderSearchPaths');
77
const getHeadersInFolder = require('./getHeadersInFolder');
88
const getHeaderSearchPath = require('./getHeaderSearchPath');
99
const getProducts = require('./getProducts');
10+
const getTargets = require('./getTargets');
1011
const createGroupWithMessage = require('./createGroupWithMessage');
1112
const addFileToProject = require('./addFileToProject');
1213
const addProjectToLibraries = require('./addProjectToLibraries');
@@ -31,12 +32,31 @@ module.exports = function registerNativeModuleIOS(dependencyConfig, projectConfi
3132
path.relative(projectConfig.sourceDir, dependencyConfig.projectPath)
3233
);
3334

35+
const targets = getTargets(project);
36+
3437
addProjectToLibraries(libraries, file);
3538

36-
getProducts(dependencyProject).forEach(product => {
37-
project.addStaticLibrary(product, {
38-
target: project.getFirstTarget().uuid,
39-
});
39+
getTargets(dependencyProject).forEach(product => {
40+
var i;
41+
if (!product.isTVOS) {
42+
for (i=0; i<targets.length; i++) {
43+
if(!targets[i].isTVOS) {
44+
project.addStaticLibrary(product.name, {
45+
target: targets[i].uuid
46+
});
47+
}
48+
}
49+
}
50+
51+
if (product.isTVOS) {
52+
for (i=0; i<targets.length; i++) {
53+
if(targets[i].isTVOS) {
54+
project.addStaticLibrary(product.name, {
55+
target: targets[i].uuid
56+
});
57+
}
58+
}
59+
}
4060
});
4161

4262
addSharedLibraries(project, dependencyConfig.sharedLibraries);

local-cli/link/ios/unregisterNativeModule.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const isEmpty = require('lodash').isEmpty;
66

77
const getGroup = require('./getGroup');
88
const getProducts = require('./getProducts');
9+
const getTargets = require('./getTargets');
910
const getHeadersInFolder = require('./getHeadersInFolder');
1011
const getHeaderSearchPath = require('./getHeaderSearchPath');
1112
const removeProjectFromProject = require('./removeProjectFromProject');
@@ -32,8 +33,8 @@ module.exports = function unregisterNativeModule(dependencyConfig, projectConfig
3233

3334
removeProjectFromLibraries(libraries, file);
3435

35-
getProducts(dependencyProject).forEach(product => {
36-
removeFromStaticLibraries(project, product, {
36+
getTargets(dependencyProject).forEach(target => {
37+
removeFromStaticLibraries(project, target.name, {
3738
target: project.getFirstTarget().uuid,
3839
});
3940
});

0 commit comments

Comments
 (0)