diff --git a/ios/Fabric/RNCSafeAreaProviderComponentView.mm b/ios/Fabric/RNCSafeAreaProviderComponentView.mm index 47014bde..5f876ac9 100644 --- a/ios/Fabric/RNCSafeAreaProviderComponentView.mm +++ b/ios/Fabric/RNCSafeAreaProviderComponentView.mm @@ -58,7 +58,7 @@ - (void)invalidateSafeAreaInsets } UIEdgeInsets safeAreaInsets = self.safeAreaInsets; - CGRect frame = [self convertRect:self.bounds toView:nil]; + CGRect frame = [self convertRect:self.bounds toView:RNCParentViewController(self).view]; if (_initialInsetsSent && UIEdgeInsetsEqualToEdgeInsetsWithThreshold(safeAreaInsets, _currentSafeAreaInsets, 1.0 / RCTScreenScale()) && diff --git a/ios/RNCSafeAreaProvider.m b/ios/RNCSafeAreaProvider.m index 69d537b7..6652d7d3 100644 --- a/ios/RNCSafeAreaProvider.m +++ b/ios/RNCSafeAreaProvider.m @@ -49,7 +49,7 @@ - (void)invalidateSafeAreaInsets } UIEdgeInsets safeAreaInsets = self.safeAreaInsets; - CGRect frame = [self convertRect:self.bounds toView:nil]; + CGRect frame = [self convertRect:self.bounds toView:RNCParentViewController(self).view]; if (_initialInsetsSent && UIEdgeInsetsEqualToEdgeInsetsWithThreshold(safeAreaInsets, _currentSafeAreaInsets, 1.0 / RCTScreenScale()) && diff --git a/ios/RNCSafeAreaUtils.h b/ios/RNCSafeAreaUtils.h index 35f81816..f28e5e43 100644 --- a/ios/RNCSafeAreaUtils.h +++ b/ios/RNCSafeAreaUtils.h @@ -6,3 +6,5 @@ extern NSString *const RNCSafeAreaDidChange; RCT_EXTERN BOOL UIEdgeInsetsEqualToEdgeInsetsWithThreshold(UIEdgeInsets insets1, UIEdgeInsets insets2, CGFloat threshold); + +RCT_EXTERN UIViewController *RNCParentViewController(UIView *view); diff --git a/ios/RNCSafeAreaUtils.m b/ios/RNCSafeAreaUtils.m index c7fbe33c..357cd1f5 100644 --- a/ios/RNCSafeAreaUtils.m +++ b/ios/RNCSafeAreaUtils.m @@ -9,3 +9,15 @@ BOOL UIEdgeInsetsEqualToEdgeInsetsWithThreshold(UIEdgeInsets insets1, UIEdgeInse return ABS(insets1.left - insets2.left) <= threshold && ABS(insets1.right - insets2.right) <= threshold && ABS(insets1.top - insets2.top) <= threshold && ABS(insets1.bottom - insets2.bottom) <= threshold; } + +UIViewController *RNCParentViewController(UIView *view) +{ + UIResponder *responder = view.nextResponder; + while (responder != nil) { + if ([responder isKindOfClass:[UIViewController class]]) { + return (UIViewController *)responder; + } + responder = responder.nextResponder; + } + return nil; +}