Skip to content

Commit fee2881

Browse files
feat: add new arch support to macos (#591)
* feat: add new arch support to macos * Remove macOS version check * Fix formatting
1 parent 1a4aff2 commit fee2881

5 files changed

+39
-4
lines changed

ios/Fabric/RNCSafeAreaProviderComponentView.h

+4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1+
#if TARGET_OS_IPHONE
12
#import <UIKit/UIKit.h>
3+
#elif TARGET_OS_OSX
4+
#import <AppKit/AppKit.h>
5+
#endif
26

37
#import <React/RCTViewComponentView.h>
48

ios/Fabric/RNCSafeAreaProviderComponentView.mm

+5-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ - (instancetype)initWithFrame:(CGRect)frame
3131
static const auto defaultProps = std::make_shared<const RNCSafeAreaProviderProps>();
3232
_props = defaultProps;
3333

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

6969
if (_initialInsetsSent &&
70+
#if TARGET_OS_IPHONE
7071
UIEdgeInsetsEqualToEdgeInsetsWithThreshold(safeAreaInsets, _currentSafeAreaInsets, 1.0 / RCTScreenScale()) &&
72+
#elif TARGET_OS_OSX
73+
NSEdgeInsetsEqualToEdgeInsetsWithThreshold(safeAreaInsets, _currentSafeAreaInsets, 1.0 / RCTScreenScale()) &&
74+
#endif
7175
CGRectEqualToRect(frame, _currentFrame)) {
7276
return;
7377
}

ios/Fabric/RNCSafeAreaViewComponentView.h

+4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1+
#if TARGET_OS_IPHONE
12
#import <UIKit/UIKit.h>
3+
#elif TARGET_OS_OSX
4+
#import <AppKit/AppKit.h>
5+
#endif
26

37
#import <React/RCTViewComponentView.h>
48

ios/Fabric/RNCSafeAreaViewComponentView.mm

+25-3
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,26 @@ - (NSString *)description
4848
superDescription = [superDescription substringToIndex:superDescription.length - 1];
4949
}
5050

51+
#if TARGET_OS_IPHONE
52+
NSString *providerViewSafeAreaInsetsString = NSStringFromUIEdgeInsets(_providerView.safeAreaInsets);
53+
NSString *currentSafeAreaInsetsString = NSStringFromUIEdgeInsets(_currentSafeAreaInsets);
54+
#elif TARGET_OS_OSX
55+
NSString *providerViewSafeAreaInsetsString = [NSString stringWithFormat:@"{%f,%f,%f,%f}",
56+
_providerView.safeAreaInsets.top,
57+
_providerView.safeAreaInsets.left,
58+
_providerView.safeAreaInsets.bottom,
59+
_providerView.safeAreaInsets.right];
60+
NSString *currentSafeAreaInsetsString = [NSString stringWithFormat:@"{%f,%f,%f,%f}",
61+
_currentSafeAreaInsets.top,
62+
_currentSafeAreaInsets.left,
63+
_currentSafeAreaInsets.bottom,
64+
_currentSafeAreaInsets.right];
65+
#endif
66+
5167
return [NSString stringWithFormat:@"%@; RNCSafeAreaInsets = %@; appliedRNCSafeAreaInsets = %@>",
5268
superDescription,
53-
NSStringFromUIEdgeInsets(_providerView.safeAreaInsets),
54-
NSStringFromUIEdgeInsets(_currentSafeAreaInsets)];
69+
providerViewSafeAreaInsetsString,
70+
currentSafeAreaInsetsString];
5571
}
5672

5773
- (void)didMoveToWindow
@@ -80,12 +96,18 @@ - (void)updateStateIfNecessary
8096
if (_providerView == nil) {
8197
return;
8298
}
99+
#if TARGET_OS_IPHONE
83100
UIEdgeInsets safeAreaInsets = _providerView.safeAreaInsets;
84101

85102
if (UIEdgeInsetsEqualToEdgeInsetsWithThreshold(safeAreaInsets, _currentSafeAreaInsets, 1.0 / RCTScreenScale())) {
86103
return;
87104
}
88-
105+
#elif TARGET_OS_OSX
106+
NSEdgeInsets safeAreaInsets = _providerView.safeAreaInsets;
107+
if (NSEdgeInsetsEqualToEdgeInsetsWithThreshold(safeAreaInsets, _currentSafeAreaInsets, 1.0 / RCTScreenScale())) {
108+
return;
109+
}
110+
#endif
89111
_currentSafeAreaInsets = safeAreaInsets;
90112
[self updateState];
91113
}

ios/RNCSafeAreaUtils.h

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#import <UIKit/UIKit.h>
55
#elif TARGET_OS_OSX
66
#import <AppKit/AppKit.h>
7+
typedef NSView UIView;
78
#endif
89

910
extern NSString *const RNCSafeAreaDidChange;

0 commit comments

Comments
 (0)