Skip to content
Permalink
Browse files
Fix use of safeAreaInsets for old versions of iOS
Summary:
This would cause a crash on iOS 9.3 because this method does not exist on UIView on that platform. By wrapping it in an availability check, we provide some safety.

Changelog: [iOS] [Fixed] safeAreaInsets call would crash on older versions of iOS

Reviewed By: fkgozali

Differential Revision: D18118025

fbshipit-source-id: fb7e517b3bcb3e0ba11ae81d8bf8397abc227e04
  • Loading branch information
Mehdi Mulani authored and facebook-github-bot committed Oct 24, 2019
1 parent 285d474 commit 03acf57b767553acbee4ff589055fbd239ffffbb
Showing 1 changed file with 11 additions and 2 deletions.
@@ -49,16 +49,25 @@ - (instancetype)initWithFrame:(CGRect)frame
return self;
}

- (UIEdgeInsets)_safeAreaInsets
{
if (@available(iOS 11.0, tvOS 11.0, *)) {
return self.safeAreaInsets;
}

return UIEdgeInsetsZero;
}

- (void)layoutSubviews
{
[super layoutSubviews];
UIScrollView *scrollView = findScrollView(self);
if (scrollView && CGSizeEqualToSize(scrollView.bounds.size, self.bounds.size)) {
[scrollView setContentInset:self.safeAreaInsets];
[scrollView setContentInset:self._safeAreaInsets];
} else {
if (_state != nullptr) {
CGSize size = self.bounds.size;
size.height -= self.safeAreaInsets.bottom;
size.height -= self._safeAreaInsets.bottom;
auto newState = SafeAreaViewState{RCTSizeFromCGSize(size)};
_state->updateState(std::move(newState));
}

0 comments on commit 03acf57

Please sign in to comment.