Skip to content

Commit 4fefc0a

Browse files
feat: add new arch support to macos
1 parent 1a4aff2 commit 4fefc0a

File tree

5 files changed

+46
-4
lines changed

5 files changed

+46
-4
lines changed

ios/Fabric/RNCSafeAreaProviderComponentView.h

Lines changed: 4 additions & 0 deletions
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

Lines changed: 5 additions & 1 deletion
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

Lines changed: 4 additions & 0 deletions
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

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,34 @@ - (NSString *)description
4747
if (superDescription.length > 0 && [superDescription characterAtIndex:superDescription.length - 1] == '>') {
4848
superDescription = [superDescription substringToIndex:superDescription.length - 1];
4949
}
50+
51+
#if TARGET_OS_IPHONE
52+
NSString *providerViewSafeAreaInsetsString = NSStringFromUIEdgeInsets(_providerView.safeAreaInsets);
53+
NSString *currentSafeAreaInsetsString = NSStringFromUIEdgeInsets(_currentSafeAreaInsets);
54+
#elif TARGET_OS_OSX
55+
NSString *providerViewSafeAreaInsetsString;
56+
NSString *currentSafeAreaInsetsString;
57+
if (@available(macOS 11.0, *)) {
58+
providerViewSafeAreaInsetsString = [NSString stringWithFormat:@"{%f,%f,%f,%f}",
59+
_providerView.safeAreaInsets.top,
60+
_providerView.safeAreaInsets.left,
61+
_providerView.safeAreaInsets.bottom,
62+
_providerView.safeAreaInsets.right];
63+
currentSafeAreaInsetsString = [NSString stringWithFormat:@"{%f,%f,%f,%f}",
64+
_currentSafeAreaInsets.top,
65+
_currentSafeAreaInsets.left,
66+
_currentSafeAreaInsets.bottom,
67+
_currentSafeAreaInsets.right];
68+
} else {
69+
providerViewSafeAreaInsetsString = @"{0.0,0.0,0.0,0.0}";
70+
currentSafeAreaInsetsString = @"{0.0,0.0,0.0,0.0}";
71+
}
72+
#endif
5073

5174
return [NSString stringWithFormat:@"%@; RNCSafeAreaInsets = %@; appliedRNCSafeAreaInsets = %@>",
5275
superDescription,
53-
NSStringFromUIEdgeInsets(_providerView.safeAreaInsets),
54-
NSStringFromUIEdgeInsets(_currentSafeAreaInsets)];
76+
providerViewSafeAreaInsetsString,
77+
currentSafeAreaInsetsString];
5578
}
5679

5780
- (void)didMoveToWindow
@@ -80,12 +103,18 @@ - (void)updateStateIfNecessary
80103
if (_providerView == nil) {
81104
return;
82105
}
106+
#if TARGET_OS_IPHONE
83107
UIEdgeInsets safeAreaInsets = _providerView.safeAreaInsets;
84108

85109
if (UIEdgeInsetsEqualToEdgeInsetsWithThreshold(safeAreaInsets, _currentSafeAreaInsets, 1.0 / RCTScreenScale())) {
86110
return;
87111
}
88-
112+
#elif TARGET_OS_OSX
113+
NSEdgeInsets safeAreaInsets = _providerView.safeAreaInsets;
114+
if (NSEdgeInsetsEqualToEdgeInsetsWithThreshold(safeAreaInsets, _currentSafeAreaInsets, 1.0 / RCTScreenScale())) {
115+
return;
116+
}
117+
#endif
89118
_currentSafeAreaInsets = safeAreaInsets;
90119
[self updateState];
91120
}

ios/RNCSafeAreaUtils.h

Lines changed: 1 addition & 0 deletions
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)