Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions ios/Fabric/RNCSafeAreaProviderComponentView.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
#if TARGET_OS_IPHONE
#import <UIKit/UIKit.h>
#elif TARGET_OS_OSX
#import <AppKit/AppKit.h>
#endif

#import <React/RCTViewComponentView.h>

Expand Down
6 changes: 5 additions & 1 deletion ios/Fabric/RNCSafeAreaProviderComponentView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ - (instancetype)initWithFrame:(CGRect)frame
static const auto defaultProps = std::make_shared<const RNCSafeAreaProviderProps>();
_props = defaultProps;

#if !TARGET_OS_TV
#if !TARGET_OS_TV && !TARGET_OS_OSX
[NSNotificationCenter.defaultCenter addObserver:self
selector:@selector(invalidateSafeAreaInsets)
name:UIKeyboardDidShowNotification
Expand Down Expand Up @@ -67,7 +67,11 @@ - (void)invalidateSafeAreaInsets
CGRect frame = [self convertRect:self.bounds toView:RNCParentViewController(self).view];

if (_initialInsetsSent &&
#if TARGET_OS_IPHONE
UIEdgeInsetsEqualToEdgeInsetsWithThreshold(safeAreaInsets, _currentSafeAreaInsets, 1.0 / RCTScreenScale()) &&
#elif TARGET_OS_OSX
NSEdgeInsetsEqualToEdgeInsetsWithThreshold(safeAreaInsets, _currentSafeAreaInsets, 1.0 / RCTScreenScale()) &&
#endif
CGRectEqualToRect(frame, _currentFrame)) {
return;
}
Expand Down
4 changes: 4 additions & 0 deletions ios/Fabric/RNCSafeAreaViewComponentView.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
#if TARGET_OS_IPHONE
#import <UIKit/UIKit.h>
#elif TARGET_OS_OSX
#import <AppKit/AppKit.h>
#endif

#import <React/RCTViewComponentView.h>

Expand Down
28 changes: 25 additions & 3 deletions ios/Fabric/RNCSafeAreaViewComponentView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,26 @@ - (NSString *)description
superDescription = [superDescription substringToIndex:superDescription.length - 1];
}

#if TARGET_OS_IPHONE
NSString *providerViewSafeAreaInsetsString = NSStringFromUIEdgeInsets(_providerView.safeAreaInsets);
NSString *currentSafeAreaInsetsString = NSStringFromUIEdgeInsets(_currentSafeAreaInsets);
#elif TARGET_OS_OSX
NSString *providerViewSafeAreaInsetsString = [NSString stringWithFormat:@"{%f,%f,%f,%f}",
_providerView.safeAreaInsets.top,
_providerView.safeAreaInsets.left,
_providerView.safeAreaInsets.bottom,
_providerView.safeAreaInsets.right];
NSString *currentSafeAreaInsetsString = [NSString stringWithFormat:@"{%f,%f,%f,%f}",
_currentSafeAreaInsets.top,
_currentSafeAreaInsets.left,
_currentSafeAreaInsets.bottom,
_currentSafeAreaInsets.right];
#endif

return [NSString stringWithFormat:@"%@; RNCSafeAreaInsets = %@; appliedRNCSafeAreaInsets = %@>",
superDescription,
NSStringFromUIEdgeInsets(_providerView.safeAreaInsets),
NSStringFromUIEdgeInsets(_currentSafeAreaInsets)];
providerViewSafeAreaInsetsString,
currentSafeAreaInsetsString];
}

- (void)didMoveToWindow
Expand Down Expand Up @@ -80,12 +96,18 @@ - (void)updateStateIfNecessary
if (_providerView == nil) {
return;
}
#if TARGET_OS_IPHONE
UIEdgeInsets safeAreaInsets = _providerView.safeAreaInsets;

if (UIEdgeInsetsEqualToEdgeInsetsWithThreshold(safeAreaInsets, _currentSafeAreaInsets, 1.0 / RCTScreenScale())) {
return;
}

#elif TARGET_OS_OSX
NSEdgeInsets safeAreaInsets = _providerView.safeAreaInsets;
if (NSEdgeInsetsEqualToEdgeInsetsWithThreshold(safeAreaInsets, _currentSafeAreaInsets, 1.0 / RCTScreenScale())) {
return;
}
#endif
_currentSafeAreaInsets = safeAreaInsets;
[self updateState];
}
Expand Down
1 change: 1 addition & 0 deletions ios/RNCSafeAreaUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#import <UIKit/UIKit.h>
#elif TARGET_OS_OSX
#import <AppKit/AppKit.h>
typedef NSView UIView;
#endif

extern NSString *const RNCSafeAreaDidChange;
Expand Down
Loading