Skip to content

Commit 03acf57

Browse files
Mehdi Mulanifacebook-github-bot
Mehdi Mulani
authored andcommitted
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
1 parent 285d474 commit 03acf57

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

React/Fabric/Mounting/ComponentViews/SafeAreaView/RCTSafeAreaViewComponentView.mm

+11-2
Original file line numberDiff line numberDiff line change
@@ -49,16 +49,25 @@ - (instancetype)initWithFrame:(CGRect)frame
4949
return self;
5050
}
5151

52+
- (UIEdgeInsets)_safeAreaInsets
53+
{
54+
if (@available(iOS 11.0, tvOS 11.0, *)) {
55+
return self.safeAreaInsets;
56+
}
57+
58+
return UIEdgeInsetsZero;
59+
}
60+
5261
- (void)layoutSubviews
5362
{
5463
[super layoutSubviews];
5564
UIScrollView *scrollView = findScrollView(self);
5665
if (scrollView && CGSizeEqualToSize(scrollView.bounds.size, self.bounds.size)) {
57-
[scrollView setContentInset:self.safeAreaInsets];
66+
[scrollView setContentInset:self._safeAreaInsets];
5867
} else {
5968
if (_state != nullptr) {
6069
CGSize size = self.bounds.size;
61-
size.height -= self.safeAreaInsets.bottom;
70+
size.height -= self._safeAreaInsets.bottom;
6271
auto newState = SafeAreaViewState{RCTSizeFromCGSize(size)};
6372
_state->updateState(std::move(newState));
6473
}

0 commit comments

Comments
 (0)