From 4fefc0a2694afca6d3466a994961af487c4eeb46 Mon Sep 17 00:00:00 2001 From: Gabriel Donadel Date: Mon, 24 Feb 2025 21:10:31 -0300 Subject: [PATCH 1/3] feat: add new arch support to macos --- ios/Fabric/RNCSafeAreaProviderComponentView.h | 4 +++ .../RNCSafeAreaProviderComponentView.mm | 6 +++- ios/Fabric/RNCSafeAreaViewComponentView.h | 4 +++ ios/Fabric/RNCSafeAreaViewComponentView.mm | 35 +++++++++++++++++-- ios/RNCSafeAreaUtils.h | 1 + 5 files changed, 46 insertions(+), 4 deletions(-) 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..b2f20b48 100644 --- a/ios/Fabric/RNCSafeAreaViewComponentView.mm +++ b/ios/Fabric/RNCSafeAreaViewComponentView.mm @@ -47,11 +47,34 @@ - (NSString *)description if (superDescription.length > 0 && [superDescription characterAtIndex:superDescription.length - 1] == '>') { 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 *currentSafeAreaInsetsString; + if (@available(macOS 11.0, *)) { + providerViewSafeAreaInsetsString = [NSString stringWithFormat:@"{%f,%f,%f,%f}", + _providerView.safeAreaInsets.top, + _providerView.safeAreaInsets.left, + _providerView.safeAreaInsets.bottom, + _providerView.safeAreaInsets.right]; + currentSafeAreaInsetsString = [NSString stringWithFormat:@"{%f,%f,%f,%f}", + _currentSafeAreaInsets.top, + _currentSafeAreaInsets.left, + _currentSafeAreaInsets.bottom, + _currentSafeAreaInsets.right]; + } else { + providerViewSafeAreaInsetsString = @"{0.0,0.0,0.0,0.0}"; + currentSafeAreaInsetsString = @"{0.0,0.0,0.0,0.0}"; + } +#endif return [NSString stringWithFormat:@"%@; RNCSafeAreaInsets = %@; appliedRNCSafeAreaInsets = %@>", superDescription, - NSStringFromUIEdgeInsets(_providerView.safeAreaInsets), - NSStringFromUIEdgeInsets(_currentSafeAreaInsets)]; + providerViewSafeAreaInsetsString, + currentSafeAreaInsetsString]; } - (void)didMoveToWindow @@ -80,12 +103,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; From d9e03b1219fcb4c94f40eb55d851b4f250ee25db Mon Sep 17 00:00:00 2001 From: Gabriel Donadel Date: Tue, 25 Feb 2025 09:30:48 -0300 Subject: [PATCH 2/3] Remove macOS version check --- ios/Fabric/RNCSafeAreaViewComponentView.mm | 29 ++++++++-------------- 1 file changed, 11 insertions(+), 18 deletions(-) diff --git a/ios/Fabric/RNCSafeAreaViewComponentView.mm b/ios/Fabric/RNCSafeAreaViewComponentView.mm index b2f20b48..81ab4a79 100644 --- a/ios/Fabric/RNCSafeAreaViewComponentView.mm +++ b/ios/Fabric/RNCSafeAreaViewComponentView.mm @@ -47,28 +47,21 @@ - (NSString *)description if (superDescription.length > 0 && [superDescription characterAtIndex:superDescription.length - 1] == '>') { 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 *currentSafeAreaInsetsString; - if (@available(macOS 11.0, *)) { - providerViewSafeAreaInsetsString = [NSString stringWithFormat:@"{%f,%f,%f,%f}", - _providerView.safeAreaInsets.top, - _providerView.safeAreaInsets.left, - _providerView.safeAreaInsets.bottom, - _providerView.safeAreaInsets.right]; - currentSafeAreaInsetsString = [NSString stringWithFormat:@"{%f,%f,%f,%f}", - _currentSafeAreaInsets.top, - _currentSafeAreaInsets.left, - _currentSafeAreaInsets.bottom, - _currentSafeAreaInsets.right]; - } else { - providerViewSafeAreaInsetsString = @"{0.0,0.0,0.0,0.0}"; - currentSafeAreaInsetsString = @"{0.0,0.0,0.0,0.0}"; - } + 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 = %@>", From b5e5223197b1acb83651295ac31b0935ed11cfa5 Mon Sep 17 00:00:00 2001 From: Gabriel Donadel Date: Tue, 25 Feb 2025 19:40:30 -0300 Subject: [PATCH 3/3] Fix formatting --- ios/Fabric/RNCSafeAreaViewComponentView.mm | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ios/Fabric/RNCSafeAreaViewComponentView.mm b/ios/Fabric/RNCSafeAreaViewComponentView.mm index 81ab4a79..827fa4dd 100644 --- a/ios/Fabric/RNCSafeAreaViewComponentView.mm +++ b/ios/Fabric/RNCSafeAreaViewComponentView.mm @@ -58,10 +58,10 @@ - (NSString *)description _providerView.safeAreaInsets.bottom, _providerView.safeAreaInsets.right]; NSString *currentSafeAreaInsetsString = [NSString stringWithFormat:@"{%f,%f,%f,%f}", - _currentSafeAreaInsets.top, - _currentSafeAreaInsets.left, - _currentSafeAreaInsets.bottom, - _currentSafeAreaInsets.right]; + _currentSafeAreaInsets.top, + _currentSafeAreaInsets.left, + _currentSafeAreaInsets.bottom, + _currentSafeAreaInsets.right]; #endif return [NSString stringWithFormat:@"%@; RNCSafeAreaInsets = %@; appliedRNCSafeAreaInsets = %@>",