Skip to content

Commit d53a60d

Browse files
chrfalchfacebook-github-bot
authored andcommitted
fix adding children (#51213)
Summary: See #51212 - children aren't updated correctly in an old arch native view using the interop layer under Fabric. This is caused by the mountChildComponentView method not updating the view, only adding the new view to a list that will be used on the next update to mount the child. This commit fixes this by adding the same pattern as in unmountChildComponentView where children are inserted directly if the underlying paperview is available in the adapter - otherwise it uses the mounting list as before. #Closes 51212 bypass-github-export-checks ## Changelog: [IOS] [FIXED] - fixed adding child views to a native view using the interop layer Pull Request resolved: #51213 Test Plan: **Previous output**: <image src="https://github.com/user-attachments/assets/472b95e7-0921-46c9-be6a-f31759c0cd26" width="200px" /> **After fix**: <image src="https://github.com/user-attachments/assets/554387cd-c264-483e-9c52-d9cd40b42601" width="200px" /> Reviewed By: sammy-SC Differential Revision: D74471278 Pulled By: cipolleschi fbshipit-source-id: 798f9e7be389359bd6e3aa1b6a6e9fb799fcb369
1 parent e9c8fee commit d53a60d

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

packages/react-native/React/Fabric/Mounting/ComponentViews/LegacyViewManagerInterop/RCTLegacyViewManagerInteropComponentView.mm

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -170,10 +170,24 @@ - (void)prepareForRecycle
170170

171171
- (void)mountChildComponentView:(UIView<RCTComponentViewProtocol> *)childComponentView index:(NSInteger)index
172172
{
173-
[_viewsToBeMounted addObject:@{
174-
kRCTLegacyInteropChildIndexKey : [NSNumber numberWithInteger:index],
175-
kRCTLegacyInteropChildComponentKey : childComponentView
176-
}];
173+
if (_adapter && index == _adapter.paperView.reactSubviews.count) {
174+
// This is a new child view that is being added to the end of the children array.
175+
// After the children is added, we need to call didUpdateReactSubviews to make sure that it is rendered.
176+
// Without this change, the new child will not be rendered right away because the didUpdateReactSubviews is not
177+
// called and the `finalizeUpdate` is not invoked.
178+
if ([childComponentView isKindOfClass:[RCTLegacyViewManagerInteropComponentView class]]) {
179+
UIView *target = ((RCTLegacyViewManagerInteropComponentView *)childComponentView).contentView;
180+
[_adapter.paperView insertReactSubview:target atIndex:index];
181+
} else {
182+
[_adapter.paperView insertReactSubview:childComponentView atIndex:index];
183+
}
184+
[_adapter.paperView didUpdateReactSubviews];
185+
} else {
186+
[_viewsToBeMounted addObject:@{
187+
kRCTLegacyInteropChildIndexKey : [NSNumber numberWithInteger:index],
188+
kRCTLegacyInteropChildComponentKey : childComponentView
189+
}];
190+
}
177191
}
178192

179193
- (void)unmountChildComponentView:(UIView<RCTComponentViewProtocol> *)childComponentView index:(NSInteger)index

0 commit comments

Comments
 (0)