Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(iOS): look through whole ancestor chain when looking for screenview from content wrapper #2683

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 19 additions & 4 deletions ios/RNSScreenContentWrapper.mm
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,30 @@ - (void)attachToAncestorScreenViewStartingFrom:(nonnull RNSScreen *)screenCtrl

- (void)attachToAncestorScreenView
{
if (![self.reactSuperview isKindOfClass:RNSScreenView.class]) {
RCTLogError(@"Expected reactSuperview to be a RNSScreenView. Found %@", self.reactSuperview);
RNSScreen *_Nullable screen =
static_cast<RNSScreen *_Nullable>([[self findFirstScreenViewAncestor] reactViewController]);
if (screen == nil) {
RCTLogError(@"Failed to find parent screen controller from %@.", self);
return;
}

RNSScreen *screen = (RNSScreen *)[self.reactSuperview reactViewController];
[self attachToAncestorScreenViewStartingFrom:screen];
}

- (nullable RNSScreenView *)findFirstScreenViewAncestor
{
UIView *currentView = self;

// In standard scenario this should do only a single iteration.
// Haven't got repro, but we got reports that there are scenarios
// when there are intermediate views between screen view & the content wrapper.
// https://github.com/software-mansion/react-native-screens/pull/2683
do {
currentView = currentView.reactSuperview;
} while (currentView != nil && ![currentView isKindOfClass:RNSScreenView.class]);

return static_cast<RNSScreenView *_Nullable>(currentView);
}

#ifdef RCT_NEW_ARCH_ENABLED

#pragma mark - RCTComponentViewProtocol
Expand Down
Loading