Skip to content

Commit fdbd735

Browse files
committed
Match surrounding style in the container fix and its tests
1 parent 63243ca commit fdbd735

2 files changed

Lines changed: 15 additions & 12 deletions

File tree

‎packages/react-native/React/Fabric/Mounting/ComponentViews/View/RCTViewComponentView.mm‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -893,7 +893,8 @@ - (void)prepareForRecycle
893893
894894
// Drop the clipping container of the previous owner. Fabric mounts a view's
895895
// children before it applies that view's props, so a container left in place
896-
// would receive the next owner's children.
896+
// would receive the next owner's children. With the flag cleared, this getter
897+
// moves any remaining subviews out and removes the container.
897898
_useCustomContainerView = NO;
898899
[self currentContainerView];
899900
@@ -1159,9 +1160,9 @@ - (UIView *)currentContainerView
11591160
// shadows, outlines), where they sit when no container is used.
11601161
// `insertSubview:atIndex:` counts sublayers, so appending them after
11611162
// those layers would shift every later mount by one.
1162-
NSUInteger index = 0;
1163-
for (UIView *subview in _containerView.subviews) {
1164-
[effectiveContentView insertSubview:subview atIndex:index++];
1163+
NSArray<UIView *> *subviews = _containerView.subviews;
1164+
for (NSUInteger index = 0; index < subviews.count; index++) {
1165+
[effectiveContentView insertSubview:subviews[index] atIndex:index];
11651166
}
11661167
effectiveContentView.clipsToBounds = _containerView.clipsToBounds;
11671168
effectiveContentView.layer.mask = _containerView.layer.mask;

‎packages/react-native/React/Tests/Mounting/RCTViewComponentViewContainerTests.mm‎

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@
3535

3636
static void applyProps(RCTViewComponentView *view, const Props::Shared &props)
3737
{
38-
[view updateProps:props oldProps:view.props];
38+
// Like the mounting layer does for an Insert, pass no old props: the view
39+
// diffs against its own.
40+
[view updateProps:props oldProps:nullptr];
3941
LayoutMetrics layoutMetrics;
4042
layoutMetrics.frame.size = {100, 40};
4143
[view updateLayoutMetrics:layoutMetrics oldLayoutMetrics:EmptyLayoutMetrics];
@@ -73,15 +75,15 @@ @implementation RCTViewComponentViewContainerTests
7375
- (void)testChildrenMovedOutOfContainerStayBelowSelfDrawnLayers
7476
{
7577
RCTViewComponentView *parent = [RCTViewComponentView new];
76-
applyProps(parent, makeProps(/* clips */ true, /* hasBoxShadow */ true));
78+
applyProps(parent, makeProps(/*clips=*/true, /*hasBoxShadow=*/true));
7779

7880
RCTViewComponentView *first = [RCTViewComponentView new];
7981
RCTViewComponentView *second = [RCTViewComponentView new];
8082
[parent mountChildComponentView:first index:0];
8183
[parent mountChildComponentView:second index:1];
8284
XCTAssertNotEqual(first.superview, parent, @"children of a clipping view with a box shadow go into a container");
8385

84-
applyProps(parent, makeProps(/* clips */ false, /* hasBoxShadow */ true));
86+
applyProps(parent, makeProps(/*clips=*/false, /*hasBoxShadow=*/true));
8587
XCTAssertEqual(first.superview, parent);
8688
XCTAssertEqual(parent.layer.sublayers.firstObject, first.layer, @"children must precede the box shadow layer");
8789

@@ -100,7 +102,7 @@ - (void)testChildrenMovedOutOfContainerStayBelowSelfDrawnLayers
100102
- (void)testRecycledViewDropsContainerBeforeNextOwnerMountsChildren
101103
{
102104
RCTViewComponentView *view = [RCTViewComponentView new];
103-
applyProps(view, makeProps(/* clips */ true, /* hasBoxShadow */ true));
105+
applyProps(view, makeProps(/*clips=*/true, /*hasBoxShadow=*/true));
104106
RCTViewComponentView *previousChild = [RCTViewComponentView new];
105107
[view mountChildComponentView:previousChild index:0];
106108
UIView *previousContainer = previousChild.superview;
@@ -115,7 +117,7 @@ - (void)testRecycledViewDropsContainerBeforeNextOwnerMountsChildren
115117
RCTViewComponentView *first = [RCTViewComponentView new];
116118
[view mountChildComponentView:first index:0];
117119
XCTAssertEqual(first.superview, view);
118-
applyProps(view, makeProps(/* clips */ false, /* hasBoxShadow */ true));
120+
applyProps(view, makeProps(/*clips=*/false, /*hasBoxShadow=*/true));
119121
XCTAssertFalse(view.clipsToBounds);
120122

121123
RCTViewComponentView *second = [RCTViewComponentView new];
@@ -132,12 +134,12 @@ - (void)testRecycledViewDropsContainerBeforeNextOwnerMountsChildren
132134
- (void)testRecycledViewKeepsClippingForNextOwnerThatClips
133135
{
134136
RCTViewComponentView *view = [RCTViewComponentView new];
135-
applyProps(view, makeProps(/* clips */ true, /* hasBoxShadow */ true));
137+
applyProps(view, makeProps(/*clips=*/true, /*hasBoxShadow=*/true));
136138
[view prepareForRecycle];
137139

138140
RCTViewComponentView *child = [RCTViewComponentView new];
139141
[view mountChildComponentView:child index:0];
140-
applyProps(view, makeProps(/* clips */ true, /* hasBoxShadow */ false));
142+
applyProps(view, makeProps(/*clips=*/true, /*hasBoxShadow=*/false));
141143

142144
XCTAssertEqual(child.superview, view);
143145
XCTAssertTrue(view.clipsToBounds);
@@ -148,7 +150,7 @@ - (void)testRecycledViewKeepsClippingForNextOwnerThatClips
148150
- (void)testRecycledViewMovesContentViewOutOfContainer
149151
{
150152
RCTViewComponentView *view = [RCTViewComponentView new];
151-
applyProps(view, makeProps(/* clips */ true, /* hasBoxShadow */ true));
153+
applyProps(view, makeProps(/*clips=*/true, /*hasBoxShadow=*/true));
152154
UIView *contentView = [UIView new];
153155
view.contentView = contentView;
154156
XCTAssertNotEqual(contentView.superview, view);

0 commit comments

Comments
 (0)