diff --git a/ios/Fabric/RNCSafeAreaProviderComponentView.h b/ios/Fabric/RNCSafeAreaProviderComponentView.h index 00389cab..b6cb8e0f 100644 --- a/ios/Fabric/RNCSafeAreaProviderComponentView.h +++ b/ios/Fabric/RNCSafeAreaProviderComponentView.h @@ -1,4 +1,8 @@ +#if TARGET_OS_IPHONE #import +#elif TARGET_OS_OSX +#import +#endif #import diff --git a/ios/Fabric/RNCSafeAreaProviderComponentView.mm b/ios/Fabric/RNCSafeAreaProviderComponentView.mm index 35927d18..d16aea4a 100644 --- a/ios/Fabric/RNCSafeAreaProviderComponentView.mm +++ b/ios/Fabric/RNCSafeAreaProviderComponentView.mm @@ -31,7 +31,7 @@ - (instancetype)initWithFrame:(CGRect)frame static const auto defaultProps = std::make_shared(); _props = defaultProps; -#if !TARGET_OS_TV +#if !TARGET_OS_TV && !TARGET_OS_OSX [NSNotificationCenter.defaultCenter addObserver:self selector:@selector(invalidateSafeAreaInsets) name:UIKeyboardDidShowNotification @@ -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; } diff --git a/ios/Fabric/RNCSafeAreaViewComponentView.h b/ios/Fabric/RNCSafeAreaViewComponentView.h index 222d8f67..2fc212df 100644 --- a/ios/Fabric/RNCSafeAreaViewComponentView.h +++ b/ios/Fabric/RNCSafeAreaViewComponentView.h @@ -1,4 +1,8 @@ +#if TARGET_OS_IPHONE #import +#elif TARGET_OS_OSX +#import +#endif #import diff --git a/ios/Fabric/RNCSafeAreaViewComponentView.mm b/ios/Fabric/RNCSafeAreaViewComponentView.mm index 68c218d4..827fa4dd 100644 --- a/ios/Fabric/RNCSafeAreaViewComponentView.mm +++ b/ios/Fabric/RNCSafeAreaViewComponentView.mm @@ -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 @@ -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]; } diff --git a/ios/RNCSafeAreaUtils.h b/ios/RNCSafeAreaUtils.h index 739e35eb..28961246 100644 --- a/ios/RNCSafeAreaUtils.h +++ b/ios/RNCSafeAreaUtils.h @@ -4,6 +4,7 @@ #import #elif TARGET_OS_OSX #import +typedef NSView UIView; #endif extern NSString *const RNCSafeAreaDidChange;