Skip to content

Commit

Permalink
Fix nested SafeAreaViews (#84)
Browse files Browse the repository at this point in the history
On iOS, nested safe area views do not get their padding applied. I think this is because `setSafeAreaInsets` overrides the existing selector - but we don't need to do that as we have `safeAreaInsetsDidChange`

This simplifies the logic a bit too
  • Loading branch information
jacobp100 authored May 25, 2020
1 parent 3b94bee commit f5aee03
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions ios/SafeAreaView/RNCSafeAreaView.m
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,10 @@ - (NSString *)description

- (void)safeAreaInsetsDidChange
{
[super safeAreaInsetsDidChange];
[self invalidateSafeAreaInsets];
}

- (void)invalidateSafeAreaInsets
{
[self setSafeAreaInsets:[self realOrEmulateSafeAreaInsets:self.emulateUnlessSupported]];
}

- (void)layoutSubviews
{
[super layoutSubviews];
Expand All @@ -62,15 +58,10 @@ - (void)layoutSubviews
}
}

- (void)updateLocalData
- (void)invalidateSafeAreaInsets
{
RNCSafeAreaViewLocalData *localData = [[RNCSafeAreaViewLocalData alloc] initWithInsets:_currentSafeAreaInsets
edges:_edges];
[_bridge.uiManager setLocalData:localData forView:self];
}
UIEdgeInsets safeAreaInsets = [self realOrEmulateSafeAreaInsets:self.emulateUnlessSupported];

- (void)setSafeAreaInsets:(UIEdgeInsets)safeAreaInsets
{
if (UIEdgeInsetsEqualToEdgeInsetsWithThreshold(safeAreaInsets, _currentSafeAreaInsets, 1.0 / RCTScreenScale())) {
return;
}
Expand All @@ -79,6 +70,13 @@ - (void)setSafeAreaInsets:(UIEdgeInsets)safeAreaInsets
[self updateLocalData];
}

- (void)updateLocalData
{
RNCSafeAreaViewLocalData *localData = [[RNCSafeAreaViewLocalData alloc] initWithInsets:_currentSafeAreaInsets
edges:_edges];
[_bridge.uiManager setLocalData:localData forView:self];
}

- (void)setEmulateUnlessSupported:(BOOL)emulateUnlessSupported
{
if (_emulateUnlessSupported == emulateUnlessSupported) {
Expand Down

0 comments on commit f5aee03

Please sign in to comment.