Skip to content

Commit

Permalink
fix: measure frame relative to nearest view controller
Browse files Browse the repository at this point in the history
  • Loading branch information
janicduplessis committed Jun 28, 2024
1 parent b4ae2f8 commit ab10a80
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 2 deletions.
2 changes: 1 addition & 1 deletion ios/Fabric/RNCSafeAreaProviderComponentView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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()) &&
Expand Down
2 changes: 1 addition & 1 deletion ios/RNCSafeAreaProvider.m
Original file line number Diff line number Diff line change
Expand Up @@ -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()) &&
Expand Down
2 changes: 2 additions & 0 deletions ios/RNCSafeAreaUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ extern NSString *const RNCSafeAreaDidChange;

RCT_EXTERN BOOL
UIEdgeInsetsEqualToEdgeInsetsWithThreshold(UIEdgeInsets insets1, UIEdgeInsets insets2, CGFloat threshold);

RCT_EXTERN UIViewController *RNCParentViewController(UIView *view);
12 changes: 12 additions & 0 deletions ios/RNCSafeAreaUtils.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

0 comments on commit ab10a80

Please sign in to comment.