Remove the legacy arch by default (#54894)

Summary:
This change remove the legacy arch by default from React Native iOS.

Users can still put the code back by using `RCT_REMOVE_LEGACY_ARCH=0 bundle exec pod install`

## Changelog:
[iOS][Breaking] - Remove legacy arch by default

Pull Request resolved: https://github.com/facebook/react-native/pull/54894

Test Plan:
Tested with RNTester that the app build correctly.
Also verified that the artifacts produced by the prebuilds are smaller than the one built before the change.

Reviewed By: vzaidman

Differential Revision: D89276102

Pulled By: cipolleschi

fbshipit-source-id: b865311c73e4f5b5b3e0b327e065f33605782e66
This commit is contained in:
Riccardo Cipolleschi authored and meta-codesync[bot] committed 2025-12-17 14:54:54 -08:00
1 parent 33005a48fe
commit c7f433a413
8 files changed
+28 -954

No files matched your search

+1
View File
@@ -923,6 +923,7 @@ extension Target {
.define("DEBUG", .when(configuration: .debug)),
.define("NDEBUG", .when(configuration: .release)),
.define("USE_HERMES", to: "1"),
.define("RCT_REMOVE_LEGACY_ARCH", to: "1"),
] + defines + cxxCommonHeaderPaths
return .target(
@@ -88,6 +88,9 @@ def use_react_native! (
# Users can still turn them off and build from source by setting the environment variable to 0.
ENV['RCT_USE_RN_DEP'] = ENV['RCT_USE_RN_DEP'] == '0' ? '0' : '1'
ENV['RCT_USE_PREBUILT_RNCORE'] = ENV['RCT_USE_PREBUILT_RNCORE'] == '0' ? '0' : '1'
# Make `REMOVE_LEGACY_ARCH` enabled by default. This will build React Native
# excluding the legacy arch unless the user turns this flag off explicitly.
ENV['RCT_REMOVE_LEGACY_ARCH'] = ENV['RCT_REMOVE_LEGACY_ARCH'] == '0' ? '0' : '1'
ReactNativePodsUtils.check_minimum_required_xcode()
@@ -1,198 +0,0 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#import <UIKit/UIKit.h>
#import <XCTest/XCTest.h>
#import <React/RCTUIManager.h>
#import <React/UIView+React.h>
@interface RCTUIManager (Testing)
- (void)_manageChildren:(NSNumber *)containerReactTag
moveFromIndices:(NSArray *)moveFromIndices
moveToIndices:(NSArray *)moveToIndices
addChildReactTags:(NSArray *)addChildReactTags
addAtIndices:(NSArray *)addAtIndices
removeAtIndices:(NSArray *)removeAtIndices
registry:(NSMutableDictionary<NSNumber *, id<RCTComponent>> *)registry;
@property (nonatomic, readonly) NSMutableDictionary<NSNumber *, UIView *> *viewRegistry;
@end
@interface RCTUIManagerScenarioTests : XCTestCase
@property (nonatomic, readwrite, strong) RCTUIManager *uiManager;
@end
@implementation RCTUIManagerScenarioTests
- (void)setUp
{
[super setUp];
_uiManager = [RCTUIManager new];
// Register 20 views to use in the tests
for (NSInteger i = 1; i <= 20; i++) {
UIView *registeredView = [UIView new];
registeredView.reactTag = @(i);
_uiManager.viewRegistry[@(i)] = registeredView;
}
}
- (void)testManagingChildrenToAddViews
{
UIView *containerView = _uiManager.viewRegistry[@20];
NSMutableArray *addedViews = [NSMutableArray array];
NSArray *tagsToAdd = @[ @1, @2, @3, @4, @5 ];
NSArray *addAtIndices = @[ @0, @1, @2, @3, @4 ];
for (NSNumber *tag in tagsToAdd) {
[addedViews addObject:_uiManager.viewRegistry[tag]];
}
// Add views 1-5 to view 20
[_uiManager _manageChildren:@20
moveFromIndices:nil
moveToIndices:nil
addChildReactTags:tagsToAdd
addAtIndices:addAtIndices
removeAtIndices:nil
registry:(NSMutableDictionary<NSNumber *, id<RCTComponent>> *)_uiManager.viewRegistry];
[_uiManager.viewRegistry[@20] didUpdateReactSubviews];
XCTAssertTrue(
[[containerView reactSubviews] count] == 5,
@"Expect to have 5 react subviews after calling manage children \
with 5 tags to add, instead have %lu",
(unsigned long)[[containerView reactSubviews] count]);
for (UIView *view in addedViews) {
XCTAssertTrue([view superview] == containerView, @"Expected to have manage children successfully add children");
[view removeFromSuperview];
}
}
- (void)testManagingChildrenToRemoveViews
{
UIView *containerView = _uiManager.viewRegistry[@20];
NSMutableArray *removedViews = [NSMutableArray array];
NSArray *removeAtIndices = @[ @0, @4, @8, @12, @16 ];
for (NSNumber *index in removeAtIndices) {
NSNumber *reactTag = @(index.integerValue + 2);
[removedViews addObject:_uiManager.viewRegistry[reactTag]];
}
for (NSInteger i = 2; i < 20; i++) {
UIView *view = _uiManager.viewRegistry[@(i)];
[containerView insertReactSubview:view atIndex:containerView.reactSubviews.count];
}
// Remove views 1-5 from view 20
[_uiManager _manageChildren:@20
moveFromIndices:nil
moveToIndices:nil
addChildReactTags:nil
addAtIndices:nil
removeAtIndices:removeAtIndices
registry:(NSMutableDictionary<NSNumber *, id<RCTComponent>> *)_uiManager.viewRegistry];
[_uiManager.viewRegistry[@20] didUpdateReactSubviews];
XCTAssertEqual(
containerView.reactSubviews.count,
(NSUInteger)13,
@"Expect to have 13 react subviews after calling manage children\
with 5 tags to remove and 18 prior children, instead have %zd",
containerView.reactSubviews.count);
for (UIView *view in removedViews) {
XCTAssertTrue([view superview] == nil, @"Expected to have manage children successfully remove children");
// After removing views are unregistered - we need to reregister
_uiManager.viewRegistry[view.reactTag] = view;
}
for (NSInteger i = 2; i < 20; i++) {
UIView *view = _uiManager.viewRegistry[@(i)];
if (![removedViews containsObject:view]) {
XCTAssertTrue(
[view superview] == containerView,
@"Should not have removed view with react tag %ld during delete but did",
(long)i);
[view removeFromSuperview];
}
}
}
// We want to start with views 1-10 added at indices 0-9
// Then we'll remove indices 2, 3, 5 and 8
// Add views 11 and 12 to indices 0 and 6
// And move indices 4 and 9 to 1 and 7
// So in total it goes from:
// [1,2,3,4,5,6,7,8,9,10]
// to
// [11,5,1,2,7,8,12,10]
- (void)testManagingChildrenToAddRemoveAndMove
{
UIView *containerView = _uiManager.viewRegistry[@20];
NSArray *removeAtIndices = @[ @2, @3, @5, @8 ];
NSArray *addAtIndices = @[ @0, @6 ];
NSArray *tagsToAdd = @[ @11, @12 ];
NSArray *moveFromIndices = @[ @4, @9 ];
NSArray *moveToIndices = @[ @1, @7 ];
// We need to keep these in array to keep them around
NSMutableArray *viewsToRemove = [NSMutableArray array];
for (NSUInteger i = 0; i < removeAtIndices.count; i++) {
NSNumber *reactTagToRemove = @([removeAtIndices[i] integerValue] + 1);
UIView *viewToRemove = _uiManager.viewRegistry[reactTagToRemove];
[viewsToRemove addObject:viewToRemove];
}
for (NSInteger i = 1; i < 11; i++) {
UIView *view = _uiManager.viewRegistry[@(i)];
[containerView insertReactSubview:view atIndex:containerView.reactSubviews.count];
}
[_uiManager _manageChildren:@20
moveFromIndices:moveFromIndices
moveToIndices:moveToIndices
addChildReactTags:tagsToAdd
addAtIndices:addAtIndices
removeAtIndices:removeAtIndices
registry:(NSMutableDictionary<NSNumber *, id<RCTComponent>> *)_uiManager.viewRegistry];
XCTAssertTrue(
[[containerView reactSubviews] count] == 8,
@"Expect to have 8 react subviews after calling manage children,\
instead have the following subviews %@",
[containerView reactSubviews]);
NSArray *expectedReactTags = @[ @11, @5, @1, @2, @7, @8, @12, @10 ];
for (NSUInteger i = 0; i < containerView.subviews.count; i++) {
XCTAssertEqualObjects(
[[containerView reactSubviews][i] reactTag],
expectedReactTags[i],
@"Expected subview at index %ld to have react tag #%@ but has tag #%@",
(long)i,
expectedReactTags[i],
[[containerView reactSubviews][i] reactTag]);
}
// Clean up after ourselves
for (NSInteger i = 1; i < 13; i++) {
UIView *view = _uiManager.viewRegistry[@(i)];
[view removeFromSuperview];
}
for (UIView *view in viewsToRemove) {
_uiManager.viewRegistry[view.reactTag] = view;
}
}
@end
@@ -33,12 +33,9 @@
E7DB20D922B2BAA6005AC45F /* RCTAnimationUtilsTests.m in Sources */ = {isa = PBXBuildFile; fileRef = E7DB20B222B2BAA4005AC45F /* RCTAnimationUtilsTests.m */; };
E7DB20DA22B2BAA6005AC45F /* RNTesterUnitTestsBundle.js in Resources */ = {isa = PBXBuildFile; fileRef = E7DB20B322B2BAA4005AC45F /* RNTesterUnitTestsBundle.js */; };
E7DB20DB22B2BAA6005AC45F /* RCTNativeAnimatedNodesManagerTests.m in Sources */ = {isa = PBXBuildFile; fileRef = E7DB20BE22B2BAA4005AC45F /* RCTNativeAnimatedNodesManagerTests.m */; };
E7DB20DC22B2BAA6005AC45F /* RCTUIManagerTests.m in Sources */ = {isa = PBXBuildFile; fileRef = E7DB20BF22B2BAA4005AC45F /* RCTUIManagerTests.m */; };
E7DB20DD22B2BAA6005AC45F /* RCTEventDispatcherTests.m in Sources */ = {isa = PBXBuildFile; fileRef = E7DB20C022B2BAA4005AC45F /* RCTEventDispatcherTests.m */; };
E7DB20DE22B2BAA6005AC45F /* RCTUnicodeDecodeTests.m in Sources */ = {isa = PBXBuildFile; fileRef = E7DB20C122B2BAA4005AC45F /* RCTUnicodeDecodeTests.m */; };
E7DB20DF22B2BAA6005AC45F /* RCTImageLoaderTests.m in Sources */ = {isa = PBXBuildFile; fileRef = E7DB20C222B2BAA4005AC45F /* RCTImageLoaderTests.m */; };
E7DB20E022B2BAA6005AC45F /* RCTMethodArgumentTests.m in Sources */ = {isa = PBXBuildFile; fileRef = E7DB20C322B2BAA4005AC45F /* RCTMethodArgumentTests.m */; };
E7DB20E122B2BAA6005AC45F /* RCTShadowViewTests.m in Sources */ = {isa = PBXBuildFile; fileRef = E7DB20C422B2BAA4005AC45F /* RCTShadowViewTests.m */; };
E7DB20E222B2BAA6005AC45F /* RCTGzipTests.m in Sources */ = {isa = PBXBuildFile; fileRef = E7DB20C522B2BAA4005AC45F /* RCTGzipTests.m */; };
E7DB20E322B2BAA6005AC45F /* RCTAllocationTests.m in Sources */ = {isa = PBXBuildFile; fileRef = E7DB20C622B2BAA5005AC45F /* RCTAllocationTests.m */; };
E7DB20E422B2BAA6005AC45F /* RCTFormatErrorTests.m in Sources */ = {isa = PBXBuildFile; fileRef = E7DB20C722B2BAA5005AC45F /* RCTFormatErrorTests.m */; };
@@ -51,11 +48,8 @@
E7DB20EB22B2BAA6005AC45F /* RCTConvert_YGValueTests.m in Sources */ = {isa = PBXBuildFile; fileRef = E7DB20CE22B2BAA5005AC45F /* RCTConvert_YGValueTests.m */; };
E7DB20EC22B2BAA6005AC45F /* RCTMultipartStreamReaderTests.m in Sources */ = {isa = PBXBuildFile; fileRef = E7DB20CF22B2BAA5005AC45F /* RCTMultipartStreamReaderTests.m */; };
E7DB20ED22B2BAA6005AC45F /* RCTURLUtilsTests.m in Sources */ = {isa = PBXBuildFile; fileRef = E7DB20D022B2BAA5005AC45F /* RCTURLUtilsTests.m */; };
E7DB20EE22B2BAA6005AC45F /* RCTViewTests.m in Sources */ = {isa = PBXBuildFile; fileRef = E7DB20E022B2BAA5005AC45F /* RCTViewTests.m */; };
E7DB213122B2C649005AC45F /* JavaScriptCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E7DB213022B2C649005AC45F /* JavaScriptCore.framework */; };
E7DB216222B2F3EC005AC45F /* RNTesterTestModule.m in Sources */ = {isa = PBXBuildFile; fileRef = E7DB215D22B2F3EC005AC45F /* RNTesterTestModule.m */; };
E7DB216322B2F3EC005AC45F /* RCTLoggingTests.m in Sources */ = {isa = PBXBuildFile; fileRef = E7DB215E22B2F3EC005AC45F /* RCTLoggingTests.m */; };
E7DB216422B2F3EC005AC45F /* RCTUIManagerScenarioTests.m in Sources */ = {isa = PBXBuildFile; fileRef = E7DB215F22B2F3EC005AC45F /* RCTUIManagerScenarioTests.m */; };
E7DB216722B2F69F005AC45F /* JavaScriptCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E7DB213022B2C649005AC45F /* JavaScriptCore.framework */; };
E7DB218C22B41FCD005AC45F /* XCTest.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E7DB218B22B41FCD005AC45F /* XCTest.framework */; };
F0D621C32BBB9E38005960AC /* PrivacyInfo.xcprivacy in Resources */ = {isa = PBXBuildFile; fileRef = F0D621C22BBB9E38005960AC /* PrivacyInfo.xcprivacy */; };
@@ -121,12 +115,9 @@
E7DB20B222B2BAA4005AC45F /* RCTAnimationUtilsTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTAnimationUtilsTests.m; sourceTree = "<group>"; };
E7DB20B322B2BAA4005AC45F /* RNTesterUnitTestsBundle.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; path = RNTesterUnitTestsBundle.js; sourceTree = "<group>"; };
E7DB20BE22B2BAA4005AC45F /* RCTNativeAnimatedNodesManagerTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTNativeAnimatedNodesManagerTests.m; sourceTree = "<group>"; };
E7DB20BF22B2BAA4005AC45F /* RCTUIManagerTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTUIManagerTests.m; sourceTree = "<group>"; };
E7DB20C022B2BAA4005AC45F /* RCTEventDispatcherTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTEventDispatcherTests.m; sourceTree = "<group>"; };
E7DB20C122B2BAA4005AC45F /* RCTUnicodeDecodeTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTUnicodeDecodeTests.m; sourceTree = "<group>"; };
E7DB20C222B2BAA4005AC45F /* RCTImageLoaderTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTImageLoaderTests.m; sourceTree = "<group>"; };
E7DB20C322B2BAA4005AC45F /* RCTMethodArgumentTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTMethodArgumentTests.m; sourceTree = "<group>"; };
E7DB20C422B2BAA4005AC45F /* RCTShadowViewTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTShadowViewTests.m; sourceTree = "<group>"; };
E7DB20C522B2BAA4005AC45F /* RCTGzipTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTGzipTests.m; sourceTree = "<group>"; };
E7DB20C622B2BAA5005AC45F /* RCTAllocationTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTAllocationTests.m; sourceTree = "<group>"; };
E7DB20C722B2BAA5005AC45F /* RCTFormatErrorTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTFormatErrorTests.m; sourceTree = "<group>"; };
@@ -139,7 +130,6 @@
E7DB20CE22B2BAA5005AC45F /* RCTConvert_YGValueTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTConvert_YGValueTests.m; sourceTree = "<group>"; };
E7DB20CF22B2BAA5005AC45F /* RCTMultipartStreamReaderTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTMultipartStreamReaderTests.m; sourceTree = "<group>"; };
E7DB20D022B2BAA5005AC45F /* RCTURLUtilsTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTURLUtilsTests.m; sourceTree = "<group>"; };
E7DB20E022B2BAA5005AC45F /* RCTViewTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTViewTests.m; sourceTree = "<group>"; };
E7DB20F022B2BD53005AC45F /* libDoubleConversion.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; path = libDoubleConversion.a; sourceTree = BUILT_PRODUCTS_DIR; };
E7DB20F222B2BD53005AC45F /* libFolly.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; path = libFolly.a; sourceTree = BUILT_PRODUCTS_DIR; };
E7DB20F422B2BD53005AC45F /* libglog.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; path = libglog.a; sourceTree = BUILT_PRODUCTS_DIR; };
@@ -164,8 +154,6 @@
E7DB215322B2F332005AC45F /* RNTesterIntegrationTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = RNTesterIntegrationTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
E7DB215722B2F332005AC45F /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
E7DB215D22B2F3EC005AC45F /* RNTesterTestModule.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RNTesterTestModule.m; sourceTree = "<group>"; };
E7DB215E22B2F3EC005AC45F /* RCTLoggingTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTLoggingTests.m; sourceTree = "<group>"; };
E7DB215F22B2F3EC005AC45F /* RCTUIManagerScenarioTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTUIManagerScenarioTests.m; sourceTree = "<group>"; };
E7DB218B22B41FCD005AC45F /* XCTest.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = XCTest.framework; sourceTree = DEVELOPER_DIR; };
F0D621C22BBB9E38005960AC /* PrivacyInfo.xcprivacy */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xml; path = PrivacyInfo.xcprivacy; sourceTree = "<group>"; };
/* End PBXFileReference section */
@@ -332,7 +320,6 @@
E7DB20CE22B2BAA5005AC45F /* RCTConvert_YGValueTests.m */,
383889D923A7398900D06C3E /* RCTConvert_UIColorTests.m */,
E7DB20C822B2BAA5005AC45F /* RCTDevMenuTests.m */,
E7DB20C022B2BAA4005AC45F /* RCTEventDispatcherTests.m */,
E7DB20AF22B2BAA4005AC45F /* RCTFontTests.m */,
E7DB20C722B2BAA5005AC45F /* RCTFormatErrorTests.m */,
E7DB20C522B2BAA4005AC45F /* RCTGzipTests.m */,
@@ -349,11 +336,8 @@
A975CA6B2C05EADE0043F72A /* RCTNetworkTaskTests.m */,
E7DB20BE22B2BAA4005AC45F /* RCTNativeAnimatedNodesManagerTests.m */,
E7DB20AD22B2BAA3005AC45F /* RCTPerformanceLoggerTests.m */,
E7DB20C422B2BAA4005AC45F /* RCTShadowViewTests.m */,
E7DB20BF22B2BAA4005AC45F /* RCTUIManagerTests.m */,
E7DB20C122B2BAA4005AC45F /* RCTUnicodeDecodeTests.m */,
E7DB20D022B2BAA5005AC45F /* RCTURLUtilsTests.m */,
E7DB20E022B2BAA5005AC45F /* RCTViewTests.m */,
E7DB20B322B2BAA4005AC45F /* RNTesterUnitTestsBundle.js */,
);
path = RNTesterUnitTests;
@@ -363,8 +347,6 @@
isa = PBXGroup;
children = (
E7C1241922BEC44B00DA25C0 /* RNTesterIntegrationTests.m */,
E7DB215E22B2F3EC005AC45F /* RCTLoggingTests.m */,
E7DB215F22B2F3EC005AC45F /* RCTUIManagerScenarioTests.m */,
E7DB215D22B2F3EC005AC45F /* RNTesterTestModule.m */,
E7DB215722B2F332005AC45F /* Info.plist */,
);
@@ -518,10 +500,14 @@
inputFileListPaths = (
"${PODS_ROOT}/Target Support Files/Pods-RNTester/Pods-RNTester-frameworks-${CONFIGURATION}-input-files.xcfilelist",
);
inputPaths = (
);
name = "[CP] Embed Pods Frameworks";
outputFileListPaths = (
"${PODS_ROOT}/Target Support Files/Pods-RNTester/Pods-RNTester-frameworks-${CONFIGURATION}-output-files.xcfilelist",
);
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-RNTester/Pods-RNTester-frameworks.sh\"\n";
@@ -557,10 +543,14 @@
inputFileListPaths = (
"${PODS_ROOT}/Target Support Files/Pods-RNTesterIntegrationTests/Pods-RNTesterIntegrationTests-resources-${CONFIGURATION}-input-files.xcfilelist",
);
inputPaths = (
);
name = "[CP] Copy Pods Resources";
outputFileListPaths = (
"${PODS_ROOT}/Target Support Files/Pods-RNTesterIntegrationTests/Pods-RNTesterIntegrationTests-resources-${CONFIGURATION}-output-files.xcfilelist",
);
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-RNTesterIntegrationTests/Pods-RNTesterIntegrationTests-resources.sh\"\n";
@@ -574,10 +564,14 @@
inputFileListPaths = (
"${PODS_ROOT}/Target Support Files/Pods-RNTesterUnitTests/Pods-RNTesterUnitTests-resources-${CONFIGURATION}-input-files.xcfilelist",
);
inputPaths = (
);
name = "[CP] Copy Pods Resources";
outputFileListPaths = (
"${PODS_ROOT}/Target Support Files/Pods-RNTesterUnitTests/Pods-RNTesterUnitTests-resources-${CONFIGURATION}-output-files.xcfilelist",
);
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-RNTesterUnitTests/Pods-RNTesterUnitTests-resources.sh\"\n";
@@ -625,10 +619,14 @@
inputFileListPaths = (
"${PODS_ROOT}/Target Support Files/Pods-RNTesterIntegrationTests/Pods-RNTesterIntegrationTests-frameworks-${CONFIGURATION}-input-files.xcfilelist",
);
inputPaths = (
);
name = "[CP] Embed Pods Frameworks";
outputFileListPaths = (
"${PODS_ROOT}/Target Support Files/Pods-RNTesterIntegrationTests/Pods-RNTesterIntegrationTests-frameworks-${CONFIGURATION}-output-files.xcfilelist",
);
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-RNTesterIntegrationTests/Pods-RNTesterIntegrationTests-frameworks.sh\"\n";
@@ -664,10 +662,14 @@
inputFileListPaths = (
"${PODS_ROOT}/Target Support Files/Pods-RNTester/Pods-RNTester-resources-${CONFIGURATION}-input-files.xcfilelist",
);
inputPaths = (
);
name = "[CP] Copy Pods Resources";
outputFileListPaths = (
"${PODS_ROOT}/Target Support Files/Pods-RNTester/Pods-RNTester-resources-${CONFIGURATION}-output-files.xcfilelist",
);
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-RNTester/Pods-RNTester-resources.sh\"\n";
@@ -703,10 +705,14 @@
inputFileListPaths = (
"${PODS_ROOT}/Target Support Files/Pods-RNTesterUnitTests/Pods-RNTesterUnitTests-frameworks-${CONFIGURATION}-input-files.xcfilelist",
);
inputPaths = (
);
name = "[CP] Embed Pods Frameworks";
outputFileListPaths = (
"${PODS_ROOT}/Target Support Files/Pods-RNTesterUnitTests/Pods-RNTesterUnitTests-frameworks-${CONFIGURATION}-output-files.xcfilelist",
);
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-RNTesterUnitTests/Pods-RNTesterUnitTests-frameworks.sh\"\n";
@@ -742,17 +748,13 @@
E7DB20E822B2BAA6005AC45F /* RCTModuleMethodTests.mm in Sources */,
E7DB20E222B2BAA6005AC45F /* RCTGzipTests.m in Sources */,
E7DB20ED22B2BAA6005AC45F /* RCTURLUtilsTests.m in Sources */,
E7DB20EE22B2BAA6005AC45F /* RCTViewTests.m in Sources */,
E7DB20D322B2BAA6005AC45F /* RCTBlobManagerTests.m in Sources */,
E7DB20DC22B2BAA6005AC45F /* RCTUIManagerTests.m in Sources */,
E7DB20E322B2BAA6005AC45F /* RCTAllocationTests.m in Sources */,
383889DA23A7398900D06C3E /* RCTConvert_UIColorTests.m in Sources */,
E7DB20E622B2BAA6005AC45F /* RCTImageLoaderHelpers.m in Sources */,
E7DB20D622B2BAA6005AC45F /* RCTFontTests.m in Sources */,
E7DB20DB22B2BAA6005AC45F /* RCTNativeAnimatedNodesManagerTests.m in Sources */,
E7DB20E722B2BAA6005AC45F /* RCTConvert_NSURLTests.m in Sources */,
E7DB20DD22B2BAA6005AC45F /* RCTEventDispatcherTests.m in Sources */,
E7DB20E122B2BAA6005AC45F /* RCTShadowViewTests.m in Sources */,
E7DB20EA22B2BAA6005AC45F /* RCTImageUtilTests.m in Sources */,
E7DB20D722B2BAA6005AC45F /* RCTModuleInitTests.m in Sources */,
E7DB20E522B2BAA6005AC45F /* RCTDevMenuTests.m in Sources */,
@@ -771,8 +773,6 @@
files = (
E7DB216222B2F3EC005AC45F /* RNTesterTestModule.m in Sources */,
E7C1241A22BEC44B00DA25C0 /* RNTesterIntegrationTests.m in Sources */,
E7DB216322B2F3EC005AC45F /* RCTLoggingTests.m in Sources */,
E7DB216422B2F3EC005AC45F /* RCTUIManagerScenarioTests.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -1,278 +0,0 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#import <UIKit/UIKit.h>
#import <XCTest/XCTest.h>
#import "OCMock/OCMock.h"
#import <React/RCTEventDispatcher.h>
@interface RCTTestEvent : NSObject <RCTEvent>
@property (atomic, assign, readwrite) BOOL canCoalesce;
@end
@implementation RCTTestEvent {
NSDictionary<NSString *, id> *_body;
}
@synthesize viewTag = _viewTag;
@synthesize eventName = _eventName;
@synthesize coalescingKey = _coalescingKey;
- (instancetype)initWithViewTag:(NSNumber *)viewTag
eventName:(NSString *)eventName
body:(NSDictionary<NSString *, id> *)body
coalescingKey:(uint16_t)coalescingKey
{
if (self = [super init]) {
_viewTag = viewTag;
_eventName = eventName;
_body = body;
_canCoalesce = YES;
_coalescingKey = coalescingKey;
}
return self;
}
- (id<RCTEvent>)coalesceWithEvent:(id<RCTEvent>)newEvent
{
return newEvent;
}
+ (NSString *)moduleDotMethod
{
return @"MyCustomEventemitter.emit";
}
- (NSArray *)arguments
{
return @[ _eventName, _body ];
}
@end
@interface RCTDummyBridge : RCTBridge
- (void)dispatchBlock:(dispatch_block_t)block queue:(dispatch_queue_t)queue;
@end
@implementation RCTDummyBridge
- (void)dispatchBlock:(dispatch_block_t __unused)block queue:(dispatch_queue_t __unused)queue
{
}
@end
@interface RCTEventDispatcherTests : XCTestCase
@end
@implementation RCTEventDispatcherTests {
id _bridge;
RCTEventDispatcher *_eventDispatcher;
RCTCallableJSModules *_callableJSModules;
NSString *_eventName;
NSDictionary<NSString *, id> *_body;
RCTTestEvent *_testEvent;
NSString *_JSMethod;
}
- (void)setUp
{
[super setUp];
_bridge = [OCMockObject mockForClass:[RCTDummyBridge class]];
_callableJSModules = [RCTCallableJSModules new];
[_callableJSModules setBridge:_bridge];
_eventDispatcher = [RCTEventDispatcher new];
[_eventDispatcher setValue:_bridge forKey:@"bridge"];
[_eventDispatcher setValue:_callableJSModules forKey:@"callableJSModules"];
[_eventDispatcher initialize];
_eventName = RCTNormalizeInputEventName(@"sampleEvent");
_body = @{@"foo" : @"bar"};
_testEvent = [[RCTTestEvent alloc] initWithViewTag:nil eventName:_eventName body:_body coalescingKey:0];
_JSMethod = [[_testEvent class] moduleDotMethod];
}
- (void)testLegacyEventsAreImmediatelyDispatched
{
[[_bridge expect] enqueueJSCall:@"RCTDeviceEventEmitter" method:@"emit" args:[_testEvent arguments] completion:NULL];
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
[_eventDispatcher sendDeviceEventWithName:_eventName body:_body];
#pragma clang diagnostic pop
[_bridge verify];
}
- (void)testNonCoalescingEventIsImmediatelyDispatched
{
_testEvent.canCoalesce = NO;
[[_bridge expect] dispatchBlock:OCMOCK_ANY queue:RCTJSThread];
[_eventDispatcher sendEvent:_testEvent];
[_bridge verify];
}
- (void)testCoalescingEventIsImmediatelyDispatched
{
_testEvent.canCoalesce = YES;
[[_bridge expect] dispatchBlock:OCMOCK_ANY queue:RCTJSThread];
[_eventDispatcher sendEvent:_testEvent];
[_bridge verify];
}
- (void)testMultipleEventsResultInOnlyOneDispatchAfterTheFirstOne
{
[[_bridge expect] dispatchBlock:OCMOCK_ANY queue:RCTJSThread];
[_eventDispatcher sendEvent:_testEvent];
[_eventDispatcher sendEvent:_testEvent];
[_eventDispatcher sendEvent:_testEvent];
[_eventDispatcher sendEvent:_testEvent];
[_eventDispatcher sendEvent:_testEvent];
[_bridge verify];
}
- (void)testRunningTheDispatchedBlockResultInANewOneBeingEnqueued
{
__block dispatch_block_t eventsEmittingBlock;
[[_bridge expect] dispatchBlock:[OCMArg checkWithBlock:^(dispatch_block_t block) {
eventsEmittingBlock = block;
return YES;
}]
queue:RCTJSThread];
[_eventDispatcher sendEvent:_testEvent];
[_bridge verify];
// eventsEmittingBlock would be called when js is no longer busy, which will result in emitting events
[self _expectBridgeJSCall:[[_testEvent class] moduleDotMethod] args:[_testEvent arguments]];
eventsEmittingBlock();
[_bridge verify];
[[_bridge expect] dispatchBlock:OCMOCK_ANY queue:RCTJSThread];
[_eventDispatcher sendEvent:_testEvent];
[_bridge verify];
}
- (void)testBasicCoalescingReturnsLastEvent
{
__block dispatch_block_t eventsEmittingBlock;
[[_bridge expect] dispatchBlock:[OCMArg checkWithBlock:^(dispatch_block_t block) {
eventsEmittingBlock = block;
return YES;
}]
queue:RCTJSThread];
[self _expectBridgeJSCall:[[_testEvent class] moduleDotMethod] args:[_testEvent arguments]];
RCTTestEvent *ignoredEvent = [[RCTTestEvent alloc] initWithViewTag:nil
eventName:_eventName
body:@{@"other" : @"body"}
coalescingKey:0];
[_eventDispatcher sendEvent:ignoredEvent];
[_eventDispatcher sendEvent:_testEvent];
eventsEmittingBlock();
[_bridge verify];
}
- (void)testDifferentEventTypesDontCoalesce
{
NSString *firstEventName = RCTNormalizeInputEventName(@"firstEvent");
RCTTestEvent *firstEvent = [[RCTTestEvent alloc] initWithViewTag:nil
eventName:firstEventName
body:_body
coalescingKey:0];
__block dispatch_block_t eventsEmittingBlock;
[[_bridge expect] dispatchBlock:[OCMArg checkWithBlock:^(dispatch_block_t block) {
eventsEmittingBlock = block;
return YES;
}]
queue:RCTJSThread];
[self _expectBridgeJSCall:[[_testEvent class] moduleDotMethod] args:[firstEvent arguments]];
[self _expectBridgeJSCall:[[_testEvent class] moduleDotMethod] args:[_testEvent arguments]];
[_eventDispatcher sendEvent:firstEvent];
[_eventDispatcher sendEvent:_testEvent];
eventsEmittingBlock();
[_bridge verify];
}
- (void)testDifferentViewTagsDontCoalesce
{
RCTTestEvent *firstEvent = [[RCTTestEvent alloc] initWithViewTag:@(1)
eventName:_eventName
body:_body
coalescingKey:0];
RCTTestEvent *secondEvent = [[RCTTestEvent alloc] initWithViewTag:@(2)
eventName:_eventName
body:_body
coalescingKey:0];
__block dispatch_block_t eventsEmittingBlock;
[[_bridge expect] dispatchBlock:[OCMArg checkWithBlock:^(dispatch_block_t block) {
eventsEmittingBlock = block;
return YES;
}]
queue:RCTJSThread];
[self _expectBridgeJSCall:[[firstEvent class] moduleDotMethod] args:[firstEvent arguments]];
[self _expectBridgeJSCall:[[secondEvent class] moduleDotMethod] args:[secondEvent arguments]];
[_eventDispatcher sendEvent:firstEvent];
[_eventDispatcher sendEvent:secondEvent];
eventsEmittingBlock();
[_bridge verify];
}
- (void)testSameEventTypesWithDifferentCoalesceKeysDontCoalesce
{
NSString *eventName = RCTNormalizeInputEventName(@"firstEvent");
RCTTestEvent *firstEvent = [[RCTTestEvent alloc] initWithViewTag:nil eventName:eventName body:_body coalescingKey:0];
RCTTestEvent *secondEvent = [[RCTTestEvent alloc] initWithViewTag:nil eventName:eventName body:_body coalescingKey:1];
__block dispatch_block_t eventsEmittingBlock;
[[_bridge expect] dispatchBlock:[OCMArg checkWithBlock:^(dispatch_block_t block) {
eventsEmittingBlock = block;
return YES;
}]
queue:RCTJSThread];
[self _expectBridgeJSCall:[[_testEvent class] moduleDotMethod] args:[firstEvent arguments]];
[self _expectBridgeJSCall:[[_testEvent class] moduleDotMethod] args:[secondEvent arguments]];
[_eventDispatcher sendEvent:firstEvent];
[_eventDispatcher sendEvent:secondEvent];
[_eventDispatcher sendEvent:firstEvent];
[_eventDispatcher sendEvent:secondEvent];
[_eventDispatcher sendEvent:secondEvent];
[_eventDispatcher sendEvent:firstEvent];
[_eventDispatcher sendEvent:firstEvent];
eventsEmittingBlock();
[_bridge verify];
}
- (void)_expectBridgeJSCall:(NSString *)moduleDotMethod args:(NSArray *)args
{
NSArray<NSString *> *const components = [moduleDotMethod componentsSeparatedByString:@"."];
NSString *const moduleName = components[0];
NSString *const methodName = components[1];
[[_bridge expect] enqueueJSCall:moduleName method:methodName args:args completion:NULL];
}
@end
@@ -1,206 +0,0 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#import <XCTest/XCTest.h>
#import <React/RCTRootShadowView.h>
#import <React/RCTShadowView+Layout.h>
#import <React/RCTShadowView.h>
@interface RCTShadowViewTests : XCTestCase
@property (nonatomic, strong) RCTRootShadowView *parentView;
@end
@implementation RCTShadowViewTests
- (void)setUp
{
[super setUp];
self.parentView = [RCTRootShadowView new];
YGNodeStyleSetFlexDirection(self.parentView.yogaNode, YGFlexDirectionColumn);
YGNodeStyleSetWidth(self.parentView.yogaNode, 440);
YGNodeStyleSetHeight(self.parentView.yogaNode, 440);
self.parentView.reactTag = @1; // must be valid rootView tag
}
// Just a basic sanity test to ensure css-layout is applied correctly in the context of our shadow view hierarchy.
//
// ====================================
// || header ||
// ====================================
// || || || ||
// || left || center || right ||
// || || || ||
// ====================================
// || footer ||
// ====================================
//
- (void)testApplyingLayoutRecursivelyToShadowView
{
RCTShadowView *leftView = [self _shadowViewWithConfig:^(YGNodeRef node) {
YGNodeStyleSetFlex(node, 1);
}];
RCTShadowView *centerView = [self _shadowViewWithConfig:^(YGNodeRef node) {
YGNodeStyleSetFlex(node, 2);
YGNodeStyleSetMargin(node, YGEdgeLeft, 10);
YGNodeStyleSetMargin(node, YGEdgeRight, 10);
}];
RCTShadowView *rightView = [self _shadowViewWithConfig:^(YGNodeRef node) {
YGNodeStyleSetFlex(node, 1);
}];
RCTShadowView *mainView = [self _shadowViewWithConfig:^(YGNodeRef node) {
YGNodeStyleSetFlexDirection(node, YGFlexDirectionRow);
YGNodeStyleSetFlex(node, 2);
YGNodeStyleSetMargin(node, YGEdgeTop, 10);
YGNodeStyleSetMargin(node, YGEdgeBottom, 10);
}];
[mainView insertReactSubview:leftView atIndex:0];
[mainView insertReactSubview:centerView atIndex:1];
[mainView insertReactSubview:rightView atIndex:2];
RCTShadowView *headerView = [self _shadowViewWithConfig:^(YGNodeRef node) {
YGNodeStyleSetFlex(node, 1);
}];
RCTShadowView *footerView = [self _shadowViewWithConfig:^(YGNodeRef node) {
YGNodeStyleSetFlex(node, 1);
}];
YGNodeStyleSetPadding(self.parentView.yogaNode, YGEdgeLeft, 10);
YGNodeStyleSetPadding(self.parentView.yogaNode, YGEdgeTop, 10);
YGNodeStyleSetPadding(self.parentView.yogaNode, YGEdgeRight, 10);
YGNodeStyleSetPadding(self.parentView.yogaNode, YGEdgeBottom, 10);
[self.parentView insertReactSubview:headerView atIndex:0];
[self.parentView insertReactSubview:mainView atIndex:1];
[self.parentView insertReactSubview:footerView atIndex:2];
[self.parentView layoutWithAffectedShadowViews:[NSPointerArray weakObjectsPointerArray]];
XCTAssertTrue(
CGRectEqualToRect([self.parentView measureLayoutRelativeToAncestor:self.parentView], CGRectMake(0, 0, 440, 440)));
XCTAssertTrue(UIEdgeInsetsEqualToEdgeInsets([self.parentView paddingAsInsets], UIEdgeInsetsMake(10, 10, 10, 10)));
XCTAssertTrue(
CGRectEqualToRect([headerView measureLayoutRelativeToAncestor:self.parentView], CGRectMake(10, 10, 420, 100)));
XCTAssertTrue(
CGRectEqualToRect([mainView measureLayoutRelativeToAncestor:self.parentView], CGRectMake(10, 120, 420, 200)));
XCTAssertTrue(
CGRectEqualToRect([footerView measureLayoutRelativeToAncestor:self.parentView], CGRectMake(10, 330, 420, 100)));
XCTAssertTrue(
CGRectEqualToRect([leftView measureLayoutRelativeToAncestor:self.parentView], CGRectMake(10, 120, 100, 200)));
XCTAssertTrue(
CGRectEqualToRect([centerView measureLayoutRelativeToAncestor:self.parentView], CGRectMake(120, 120, 200, 200)));
XCTAssertTrue(
CGRectEqualToRect([rightView measureLayoutRelativeToAncestor:self.parentView], CGRectMake(330, 120, 100, 200)));
}
- (void)testAncestorCheck
{
RCTShadowView *centerView = [self _shadowViewWithConfig:^(YGNodeRef node) {
YGNodeStyleSetFlex(node, 1);
}];
RCTShadowView *mainView = [self _shadowViewWithConfig:^(YGNodeRef node) {
YGNodeStyleSetFlex(node, 1);
}];
[mainView insertReactSubview:centerView atIndex:0];
RCTShadowView *footerView = [self _shadowViewWithConfig:^(YGNodeRef node) {
YGNodeStyleSetFlex(node, 1);
}];
[self.parentView insertReactSubview:mainView atIndex:0];
[self.parentView insertReactSubview:footerView atIndex:1];
XCTAssertTrue([centerView viewIsDescendantOf:mainView]);
XCTAssertFalse([footerView viewIsDescendantOf:mainView]);
}
- (void)testAssignsSuggestedWidthDimension
{
[self
_withShadowViewWithStyle:^(YGNodeRef node) {
YGNodeStyleSetPositionType(node, YGPositionTypeAbsolute);
YGNodeStyleSetPosition(node, YGEdgeLeft, 0);
YGNodeStyleSetPosition(node, YGEdgeTop, 0);
YGNodeStyleSetHeight(node, 10);
}
assertRelativeLayout:CGRectMake(0, 0, 3, 10)
withIntrinsicContentSize:CGSizeMake(3, UIViewNoIntrinsicMetric)];
}
- (void)testAssignsSuggestedHeightDimension
{
[self
_withShadowViewWithStyle:^(YGNodeRef node) {
YGNodeStyleSetPositionType(node, YGPositionTypeAbsolute);
YGNodeStyleSetPosition(node, YGEdgeLeft, 0);
YGNodeStyleSetPosition(node, YGEdgeTop, 0);
YGNodeStyleSetWidth(node, 10);
}
assertRelativeLayout:CGRectMake(0, 0, 10, 4)
withIntrinsicContentSize:CGSizeMake(UIViewNoIntrinsicMetric, 4)];
}
- (void)testDoesNotOverrideDimensionStyleWithSuggestedDimensions
{
[self
_withShadowViewWithStyle:^(YGNodeRef node) {
YGNodeStyleSetPositionType(node, YGPositionTypeAbsolute);
YGNodeStyleSetPosition(node, YGEdgeLeft, 0);
YGNodeStyleSetPosition(node, YGEdgeTop, 0);
YGNodeStyleSetWidth(node, 10);
YGNodeStyleSetHeight(node, 10);
}
assertRelativeLayout:CGRectMake(0, 0, 10, 10)
withIntrinsicContentSize:CGSizeMake(3, 4)];
}
- (void)testDoesNotAssignSuggestedDimensionsWhenStyledWithFlexAttribute
{
float parentWidth = YGNodeStyleGetWidth(self.parentView.yogaNode).value;
float parentHeight = YGNodeStyleGetHeight(self.parentView.yogaNode).value;
[self
_withShadowViewWithStyle:^(YGNodeRef node) {
YGNodeStyleSetFlex(node, 1);
}
assertRelativeLayout:CGRectMake(0, 0, parentWidth, parentHeight)
withIntrinsicContentSize:CGSizeMake(3, 4)];
}
- (void)_withShadowViewWithStyle:(void (^)(YGNodeRef node))configBlock
assertRelativeLayout:(CGRect)expectedRect
withIntrinsicContentSize:(CGSize)contentSize
{
RCTShadowView *view = [self _shadowViewWithConfig:configBlock];
[self.parentView insertReactSubview:view atIndex:0];
view.intrinsicContentSize = contentSize;
[self.parentView layoutWithAffectedShadowViews:[NSPointerArray weakObjectsPointerArray]];
CGRect actualRect = [view measureLayoutRelativeToAncestor:self.parentView];
XCTAssertTrue(
CGRectEqualToRect(expectedRect, actualRect),
@"Expected layout to be %@, got %@",
NSStringFromCGRect(expectedRect),
NSStringFromCGRect(actualRect));
}
- (RCTShadowView *)_shadowViewWithConfig:(void (^)(YGNodeRef node))configBlock
{
RCTShadowView *shadowView = [RCTShadowView new];
configBlock(shadowView.yogaNode);
return shadowView;
}
@end
@@ -1,200 +0,0 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#import <XCTest/XCTest.h>
#import <React/RCTUIManager.h>
#import <React/UIView+React.h>
@interface RCTUIManager (Testing)
- (void)_manageChildren:(NSNumber *)containerReactTag
moveFromIndices:(NSArray *)moveFromIndices
moveToIndices:(NSArray *)moveToIndices
addChildReactTags:(NSArray *)addChildReactTags
addAtIndices:(NSArray *)addAtIndices
removeAtIndices:(NSArray *)removeAtIndices
registry:(NSDictionary<NSNumber *, id<RCTComponent>> *)registry;
@property (nonatomic, copy, readonly) NSMutableDictionary<NSNumber *, UIView *> *viewRegistry;
@end
@interface RCTUIManagerTests : XCTestCase
@property (nonatomic, readwrite, strong) RCTUIManager *uiManager;
@end
@implementation RCTUIManagerTests
- (void)setUp
{
[super setUp];
_uiManager = [RCTUIManager new];
// Register 20 views to use in the tests
for (NSInteger i = 1; i <= 20; i++) {
UIView *registeredView = [UIView new];
registeredView.reactTag = @(i);
_uiManager.viewRegistry[@(i)] = registeredView;
}
}
- (void)testManagingChildrenToAddViews
{
UIView *containerView = _uiManager.viewRegistry[@20];
NSMutableArray *addedViews = [NSMutableArray array];
NSArray *tagsToAdd = @[ @1, @2, @3, @4, @5 ];
NSArray *addAtIndices = @[ @0, @1, @2, @3, @4 ];
for (NSNumber *tag in tagsToAdd) {
[addedViews addObject:_uiManager.viewRegistry[tag]];
}
// Add views 1-5 to view 20
[_uiManager _manageChildren:@20
moveFromIndices:nil
moveToIndices:nil
addChildReactTags:tagsToAdd
addAtIndices:addAtIndices
removeAtIndices:nil
registry:_uiManager.viewRegistry];
[containerView didUpdateReactSubviews];
XCTAssertTrue(
[[containerView reactSubviews] count] == 5,
@"Expect to have 5 react subviews after calling manage children \
with 5 tags to add, instead have %lu",
(unsigned long)[[containerView reactSubviews] count]);
for (UIView *view in addedViews) {
XCTAssertTrue(
[view reactSuperview] == containerView, @"Expected to have manage children successfully add children");
[view removeFromSuperview];
}
}
- (void)testManagingChildrenToRemoveViews
{
UIView *containerView = _uiManager.viewRegistry[@20];
NSMutableArray *removedViews = [NSMutableArray array];
NSArray *removeAtIndices = @[ @0, @4, @8, @12, @16 ];
for (NSNumber *index in removeAtIndices) {
NSNumber *reactTag = @(index.integerValue + 2);
[removedViews addObject:_uiManager.viewRegistry[reactTag]];
}
for (NSInteger i = 2; i < 20; i++) {
UIView *view = _uiManager.viewRegistry[@(i)];
[containerView insertReactSubview:view atIndex:containerView.reactSubviews.count];
}
// Remove views 1-5 from view 20
[_uiManager _manageChildren:@20
moveFromIndices:nil
moveToIndices:nil
addChildReactTags:nil
addAtIndices:nil
removeAtIndices:removeAtIndices
registry:_uiManager.viewRegistry];
[containerView didUpdateReactSubviews];
XCTAssertEqual(
containerView.reactSubviews.count,
(NSUInteger)13,
@"Expect to have 13 react subviews after calling manage children\
with 5 tags to remove and 18 prior children, instead have %zd",
containerView.reactSubviews.count);
for (UIView *view in removedViews) {
XCTAssertTrue([view reactSuperview] == nil, @"Expected to have manage children successfully remove children");
// After removing views are unregistered - we need to reregister
_uiManager.viewRegistry[view.reactTag] = view;
}
for (NSInteger i = 2; i < 20; i++) {
UIView *view = _uiManager.viewRegistry[@(i)];
if (![removedViews containsObject:view]) {
XCTAssertTrue(
[view superview] == containerView,
@"Should not have removed view with react tag %ld during delete but did",
(long)i);
[view removeFromSuperview];
}
}
}
// We want to start with views 1-10 added at indices 0-9
// Then we'll remove indices 2, 3, 5 and 8
// Add views 11 and 12 to indices 0 and 6
// And move indices 4 and 9 to 1 and 7
// So in total it goes from:
// [1,2,3,4,5,6,7,8,9,10]
// to
// [11,5,1,2,7,8,12,10]
- (void)testManagingChildrenToAddRemoveAndMove
{
UIView *containerView = _uiManager.viewRegistry[@20];
NSArray *removeAtIndices = @[ @2, @3, @5, @8 ];
NSArray *addAtIndices = @[ @0, @6 ];
NSArray *tagsToAdd = @[ @11, @12 ];
NSArray *moveFromIndices = @[ @4, @9 ];
NSArray *moveToIndices = @[ @1, @7 ];
// We need to keep these in array to keep them around
NSMutableArray *viewsToRemove = [NSMutableArray array];
for (NSUInteger i = 0; i < removeAtIndices.count; i++) {
NSNumber *reactTagToRemove = @([removeAtIndices[i] integerValue] + 1);
UIView *viewToRemove = _uiManager.viewRegistry[reactTagToRemove];
[viewsToRemove addObject:viewToRemove];
}
for (NSInteger i = 1; i < 11; i++) {
UIView *view = _uiManager.viewRegistry[@(i)];
[containerView insertReactSubview:view atIndex:containerView.reactSubviews.count];
}
[_uiManager _manageChildren:@20
moveFromIndices:moveFromIndices
moveToIndices:moveToIndices
addChildReactTags:tagsToAdd
addAtIndices:addAtIndices
removeAtIndices:removeAtIndices
registry:_uiManager.viewRegistry];
[containerView didUpdateReactSubviews];
XCTAssertTrue(
[[containerView reactSubviews] count] == 8,
@"Expect to have 8 react subviews after calling manage children,\
instead have the following subviews %@",
[containerView reactSubviews]);
NSArray *expectedReactTags = @[ @11, @5, @1, @2, @7, @8, @12, @10 ];
for (NSUInteger i = 0; i < containerView.subviews.count; i++) {
XCTAssertEqualObjects(
[[containerView reactSubviews][i] reactTag],
expectedReactTags[i],
@"Expected subview at index %ld to have react tag #%@ but has tag #%@",
(long)i,
expectedReactTags[i],
[[containerView reactSubviews][i] reactTag]);
}
// Clean up after ourselves
for (NSInteger i = 1; i < 13; i++) {
UIView *view = _uiManager.viewRegistry[@(i)];
[view removeFromSuperview];
}
for (UIView *view in viewsToRemove) {
_uiManager.viewRegistry[view.reactTag] = view;
}
}
@end
@@ -1,48 +0,0 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#import <XCTest/XCTest.h>
#import "OCMock/OCMock.h"
#import <React/RCTAutoInsetsProtocol.h>
#import <React/RCTMockDef.h>
#import <React/RCTScrollView.h>
#import <React/RCTView.h>
#import <React/RCTViewUtils.h>
RCT_MOCK_REF(RCTView, RCTContentInsets);
UIEdgeInsets gContentInsets;
static UIEdgeInsets RCTContentInsetsMock(__unused UIView *view)
{
return gContentInsets;
}
@interface RCTViewTests : XCTestCase
@end
@implementation RCTViewTests
- (void)testAutoAdjustInsetsUpdateOffsetNo
{
RCT_MOCK_SET(RCTView, RCTContentInsets, RCTContentInsetsMock);
RCTScrollView *parentView = OCMClassMock([RCTScrollView class]);
OCMStub([parentView contentInset]).andReturn(UIEdgeInsetsMake(1, 1, 1, 1));
OCMStub([parentView automaticallyAdjustContentInsets]).andReturn(YES);
UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:CGRectZero];
gContentInsets = UIEdgeInsetsMake(1, 2, 3, 4);
[RCTView autoAdjustInsetsForView:parentView withScrollView:scrollView updateOffset:NO];
XCTAssertTrue(UIEdgeInsetsEqualToEdgeInsets(scrollView.contentInset, UIEdgeInsetsMake(2, 3, 4, 5)));
XCTAssertTrue(UIEdgeInsetsEqualToEdgeInsets(scrollView.verticalScrollIndicatorInsets, UIEdgeInsetsMake(2, 3, 4, 5)));
RCT_MOCK_RESET(RCTView, RCTContentInsets);
}
@end