|
11 | 11 |
|
12 | 12 | @implementation RNCSafeAreaView {
|
13 | 13 | __weak RCTBridge *_bridge;
|
| 14 | +#if TARGET_OS_IPHONE |
14 | 15 | UIEdgeInsets _currentSafeAreaInsets;
|
| 16 | +#elif TARGET_OS_OSX |
| 17 | + NSEdgeInsets _currentSafeAreaInsets; |
| 18 | +#endif |
15 | 19 | RNCSafeAreaViewMode _mode;
|
16 | 20 | RNCSafeAreaViewEdges _edges;
|
17 | 21 | __weak RNCSafeAreaProvider *_Nullable _providerView;
|
@@ -41,16 +45,35 @@ - (NSString *)description
|
41 | 45 | if (superDescription.length > 0 && [superDescription characterAtIndex:superDescription.length - 1] == '>') {
|
42 | 46 | superDescription = [superDescription substringToIndex:superDescription.length - 1];
|
43 | 47 | }
|
| 48 | + |
| 49 | +#if TARGET_OS_IPHONE |
| 50 | + NSString *providerViewSafeAreaInsetsString = NSStringFromUIEdgeInsets(_providerView.safeAreaInsets); |
| 51 | + NSString *currentSafeAreaInsetsString = NSStringFromUIEdgeInsets(_currentSafeAreaInsets); |
| 52 | +#elif TARGET_OS_OSX |
| 53 | + NSString *providerViewSafeAreaInsetsString; |
| 54 | + NSString *currentSafeAreaInsetsString; |
| 55 | + if (@available(macOS 11.0, *)) { |
| 56 | + providerViewSafeAreaInsetsString = [NSString stringWithFormat:@"{%f,%f,%f,%f}", _providerView.safeAreaInsets.top, _providerView.safeAreaInsets.left, _providerView.safeAreaInsets.bottom, _providerView.safeAreaInsets.right]; |
| 57 | + currentSafeAreaInsetsString = [NSString stringWithFormat:@"{%f,%f,%f,%f}", _currentSafeAreaInsets.top, _currentSafeAreaInsets.left, _currentSafeAreaInsets.bottom, _currentSafeAreaInsets.right]; |
| 58 | + } else { |
| 59 | + providerViewSafeAreaInsetsString = @"{0.0,0.0,0.0,0.0}"; |
| 60 | + currentSafeAreaInsetsString = @"{0.0,0.0,0.0,0.0}"; |
| 61 | + } |
| 62 | +#endif |
44 | 63 |
|
45 | 64 | return [NSString stringWithFormat:@"%@; RNCSafeAreaInsets = %@; appliedRNCSafeAreaInsets = %@>",
|
46 | 65 | superDescription,
|
47 |
| - NSStringFromUIEdgeInsets(_providerView.safeAreaInsets), |
48 |
| - NSStringFromUIEdgeInsets(_currentSafeAreaInsets)]; |
| 66 | + providerViewSafeAreaInsetsString, |
| 67 | + currentSafeAreaInsetsString]; |
49 | 68 | }
|
50 | 69 |
|
51 | 70 | - (void)didMoveToWindow
|
52 | 71 | {
|
| 72 | +#if TARGET_OS_IPHONE |
53 | 73 | UIView *previousProviderView = _providerView;
|
| 74 | +#elif TARGET_OS_OSX |
| 75 | + NSView *previousProviderView = _providerView; |
| 76 | +#endif |
54 | 77 | _providerView = [self findNearestProvider];
|
55 | 78 |
|
56 | 79 | [self invalidateSafeAreaInsets];
|
@@ -79,19 +102,29 @@ - (void)invalidateSafeAreaInsets
|
79 | 102 | if (_providerView == nil) {
|
80 | 103 | return;
|
81 | 104 | }
|
| 105 | +#if TARGET_OS_IPHONE |
82 | 106 | UIEdgeInsets safeAreaInsets = _providerView.safeAreaInsets;
|
83 |
| - |
84 | 107 | if (UIEdgeInsetsEqualToEdgeInsetsWithThreshold(safeAreaInsets, _currentSafeAreaInsets, 1.0 / RCTScreenScale())) {
|
85 | 108 | return;
|
86 | 109 | }
|
| 110 | +#elif TARGET_OS_OSX |
| 111 | + NSEdgeInsets safeAreaInsets = _providerView.safeAreaInsets; |
| 112 | + if (NSEdgeInsetsEqualToEdgeInsetsWithThreshold(safeAreaInsets, _currentSafeAreaInsets, 1.0 / RCTScreenScale())) { |
| 113 | + return; |
| 114 | + } |
| 115 | +#endif |
87 | 116 |
|
88 | 117 | _currentSafeAreaInsets = safeAreaInsets;
|
89 | 118 | [self updateLocalData];
|
90 | 119 | }
|
91 | 120 |
|
92 | 121 | - (nullable RNCSafeAreaProvider *)findNearestProvider
|
93 | 122 | {
|
| 123 | +#if TARGET_OS_IPHONE |
94 | 124 | UIView *current = self.reactSuperview;
|
| 125 | +#elif TARGET_OS_OSX |
| 126 | + NSView *current = self.reactSuperview; |
| 127 | +#endif |
95 | 128 | while (current != nil) {
|
96 | 129 | if ([current isKindOfClass:RNCSafeAreaProvider.class]) {
|
97 | 130 | return (RNCSafeAreaProvider *)current;
|
|
0 commit comments