@amazon-devices/react-native-safe-area-context 2.0.1758683737

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (156) hide show
  1. package/LICENSE +7 -0
  2. package/README.md +315 -0
  3. package/SystemBundles/e3c0cdeab56b8b622d4f0fd5a80812eafe199fa2287d0e3a09c5e573a1035350.bundle +11031 -0
  4. package/SystemBundles/e3c0cdeab56b8b622d4f0fd5a80812eafe199fa2287d0e3a09c5e573a1035350.map +1 -0
  5. package/SystemModules/amzn__react-native-safe-area-context-2.modules.txt +55 -0
  6. package/SystemModules/amzn__react-native-safe-area-context-2.private.modules.txt +91 -0
  7. package/SystemModules/keplerscript-system-bundle-config.json +7 -0
  8. package/THIRD_PARTY_NOTICES.txt +24 -0
  9. package/android/build.gradle +46 -0
  10. package/android/src/main/AndroidManifest.xml +6 -0
  11. package/android/src/main/java/com/th3rdwave/safeareacontext/EdgeInsets.java +22 -0
  12. package/android/src/main/java/com/th3rdwave/safeareacontext/InsetsChangeEvent.java +33 -0
  13. package/android/src/main/java/com/th3rdwave/safeareacontext/Rect.java +22 -0
  14. package/android/src/main/java/com/th3rdwave/safeareacontext/SafeAreaContextPackage.java +31 -0
  15. package/android/src/main/java/com/th3rdwave/safeareacontext/SafeAreaProvider.java +66 -0
  16. package/android/src/main/java/com/th3rdwave/safeareacontext/SafeAreaProviderManager.java +94 -0
  17. package/android/src/main/java/com/th3rdwave/safeareacontext/SafeAreaUtils.java +82 -0
  18. package/android/src/main/java/com/th3rdwave/safeareacontext/SafeAreaView.java +159 -0
  19. package/android/src/main/java/com/th3rdwave/safeareacontext/SafeAreaViewEdges.java +8 -0
  20. package/android/src/main/java/com/th3rdwave/safeareacontext/SafeAreaViewLocalData.java +27 -0
  21. package/android/src/main/java/com/th3rdwave/safeareacontext/SafeAreaViewManager.java +72 -0
  22. package/android/src/main/java/com/th3rdwave/safeareacontext/SafeAreaViewMode.java +6 -0
  23. package/android/src/main/java/com/th3rdwave/safeareacontext/SafeAreaViewShadowNode.java +201 -0
  24. package/android/src/main/java/com/th3rdwave/safeareacontext/SerializationUtils.java +52 -0
  25. package/ios/SafeAreaView/RCTView+SafeAreaCompat.h +16 -0
  26. package/ios/SafeAreaView/RCTView+SafeAreaCompat.m +57 -0
  27. package/ios/SafeAreaView/RNCSafeAreaProvider.h +13 -0
  28. package/ios/SafeAreaView/RNCSafeAreaProvider.m +65 -0
  29. package/ios/SafeAreaView/RNCSafeAreaProviderManager.h +9 -0
  30. package/ios/SafeAreaView/RNCSafeAreaProviderManager.m +61 -0
  31. package/ios/SafeAreaView/RNCSafeAreaShadowView.h +9 -0
  32. package/ios/SafeAreaView/RNCSafeAreaShadowView.m +180 -0
  33. package/ios/SafeAreaView/RNCSafeAreaView.h +21 -0
  34. package/ios/SafeAreaView/RNCSafeAreaView.m +118 -0
  35. package/ios/SafeAreaView/RNCSafeAreaViewEdges.h +9 -0
  36. package/ios/SafeAreaView/RNCSafeAreaViewEdges.m +13 -0
  37. package/ios/SafeAreaView/RNCSafeAreaViewLocalData.h +18 -0
  38. package/ios/SafeAreaView/RNCSafeAreaViewLocalData.m +16 -0
  39. package/ios/SafeAreaView/RNCSafeAreaViewManager.h +9 -0
  40. package/ios/SafeAreaView/RNCSafeAreaViewManager.m +25 -0
  41. package/ios/SafeAreaView/RNCSafeAreaViewMode.h +7 -0
  42. package/ios/SafeAreaView/RNCSafeAreaViewMode.m +11 -0
  43. package/ios/SafeAreaView.xcodeproj/project.pbxproj +338 -0
  44. package/kepler-compatibility.json +8 -0
  45. package/kepler-transformed-package-info.json +3 -0
  46. package/lib/commonjs/CompatNativeSafeAreaProvider.js +44 -0
  47. package/lib/commonjs/CompatNativeSafeAreaProvider.js.map +1 -0
  48. package/lib/commonjs/InitialWindow.js +13 -0
  49. package/lib/commonjs/InitialWindow.js.map +1 -0
  50. package/lib/commonjs/InitialWindow.kepler.js +15 -0
  51. package/lib/commonjs/InitialWindow.kepler.js.map +1 -0
  52. package/lib/commonjs/InitialWindow.native.js +15 -0
  53. package/lib/commonjs/InitialWindow.native.js.map +1 -0
  54. package/lib/commonjs/NativeSafeAreaProvider.js +132 -0
  55. package/lib/commonjs/NativeSafeAreaProvider.js.map +1 -0
  56. package/lib/commonjs/NativeSafeAreaProvider.kepler.js +9 -0
  57. package/lib/commonjs/NativeSafeAreaProvider.kepler.js.map +1 -0
  58. package/lib/commonjs/NativeSafeAreaProvider.macos.js +9 -0
  59. package/lib/commonjs/NativeSafeAreaProvider.macos.js.map +1 -0
  60. package/lib/commonjs/NativeSafeAreaProvider.native.js +9 -0
  61. package/lib/commonjs/NativeSafeAreaProvider.native.js.map +1 -0
  62. package/lib/commonjs/NativeSafeAreaProvider.windows.js +9 -0
  63. package/lib/commonjs/NativeSafeAreaProvider.windows.js.map +1 -0
  64. package/lib/commonjs/SafeArea.types.js +6 -0
  65. package/lib/commonjs/SafeArea.types.js.map +1 -0
  66. package/lib/commonjs/SafeAreaContext.js +113 -0
  67. package/lib/commonjs/SafeAreaContext.js.map +1 -0
  68. package/lib/commonjs/SafeAreaView.js +82 -0
  69. package/lib/commonjs/SafeAreaView.js.map +1 -0
  70. package/lib/commonjs/SafeAreaView.kepler.js +9 -0
  71. package/lib/commonjs/SafeAreaView.kepler.js.map +1 -0
  72. package/lib/commonjs/SafeAreaView.macos.js +9 -0
  73. package/lib/commonjs/SafeAreaView.macos.js.map +1 -0
  74. package/lib/commonjs/SafeAreaView.native.js +9 -0
  75. package/lib/commonjs/SafeAreaView.native.js.map +1 -0
  76. package/lib/commonjs/SafeAreaView.windows.js +9 -0
  77. package/lib/commonjs/SafeAreaView.windows.js.map +1 -0
  78. package/lib/commonjs/index.js +50 -0
  79. package/lib/commonjs/index.js.map +1 -0
  80. package/lib/commonjs/useWindowDimensions.js +32 -0
  81. package/lib/commonjs/useWindowDimensions.js.map +1 -0
  82. package/lib/module/CompatNativeSafeAreaProvider.js +35 -0
  83. package/lib/module/CompatNativeSafeAreaProvider.js.map +1 -0
  84. package/lib/module/InitialWindow.js +7 -0
  85. package/lib/module/InitialWindow.js.map +1 -0
  86. package/lib/module/InitialWindow.kepler.js +9 -0
  87. package/lib/module/InitialWindow.kepler.js.map +1 -0
  88. package/lib/module/InitialWindow.native.js +9 -0
  89. package/lib/module/InitialWindow.native.js.map +1 -0
  90. package/lib/module/NativeSafeAreaProvider.js +124 -0
  91. package/lib/module/NativeSafeAreaProvider.js.map +1 -0
  92. package/lib/module/NativeSafeAreaProvider.kepler.js +3 -0
  93. package/lib/module/NativeSafeAreaProvider.kepler.js.map +1 -0
  94. package/lib/module/NativeSafeAreaProvider.macos.js +3 -0
  95. package/lib/module/NativeSafeAreaProvider.macos.js.map +1 -0
  96. package/lib/module/NativeSafeAreaProvider.native.js +3 -0
  97. package/lib/module/NativeSafeAreaProvider.native.js.map +1 -0
  98. package/lib/module/NativeSafeAreaProvider.windows.js +3 -0
  99. package/lib/module/NativeSafeAreaProvider.windows.js.map +1 -0
  100. package/lib/module/SafeArea.types.js +2 -0
  101. package/lib/module/SafeArea.types.js.map +1 -0
  102. package/lib/module/SafeAreaContext.js +99 -0
  103. package/lib/module/SafeAreaContext.js.map +1 -0
  104. package/lib/module/SafeAreaView.js +74 -0
  105. package/lib/module/SafeAreaView.js.map +1 -0
  106. package/lib/module/SafeAreaView.kepler.js +3 -0
  107. package/lib/module/SafeAreaView.kepler.js.map +1 -0
  108. package/lib/module/SafeAreaView.macos.js +3 -0
  109. package/lib/module/SafeAreaView.macos.js.map +1 -0
  110. package/lib/module/SafeAreaView.native.js +3 -0
  111. package/lib/module/SafeAreaView.native.js.map +1 -0
  112. package/lib/module/SafeAreaView.windows.js +3 -0
  113. package/lib/module/SafeAreaView.windows.js.map +1 -0
  114. package/lib/module/index.js +5 -0
  115. package/lib/module/index.js.map +1 -0
  116. package/lib/module/useWindowDimensions.js +26 -0
  117. package/lib/module/useWindowDimensions.js.map +1 -0
  118. package/lib/typescript/src/CompatNativeSafeAreaProvider.d.ts +2 -0
  119. package/lib/typescript/src/InitialWindow.d.ts +6 -0
  120. package/lib/typescript/src/InitialWindow.kepler.d.ts +6 -0
  121. package/lib/typescript/src/InitialWindow.native.d.ts +6 -0
  122. package/lib/typescript/src/NativeSafeAreaProvider.d.ts +2 -0
  123. package/lib/typescript/src/NativeSafeAreaProvider.kepler.d.ts +2 -0
  124. package/lib/typescript/src/NativeSafeAreaProvider.macos.d.ts +2 -0
  125. package/lib/typescript/src/NativeSafeAreaProvider.native.d.ts +3 -0
  126. package/lib/typescript/src/NativeSafeAreaProvider.windows.d.ts +2 -0
  127. package/lib/typescript/src/SafeArea.types.d.ts +31 -0
  128. package/lib/typescript/src/SafeAreaContext.d.ts +30 -0
  129. package/lib/typescript/src/SafeAreaView.d.ts +2 -0
  130. package/lib/typescript/src/SafeAreaView.kepler.d.ts +2 -0
  131. package/lib/typescript/src/SafeAreaView.macos.d.ts +2 -0
  132. package/lib/typescript/src/SafeAreaView.native.d.ts +2 -0
  133. package/lib/typescript/src/SafeAreaView.windows.d.ts +2 -0
  134. package/lib/typescript/src/index.d.ts +4 -0
  135. package/lib/typescript/src/useWindowDimensions.d.ts +8 -0
  136. package/package.json +1 -0
  137. package/react-native-safe-area-context.podspec +19 -0
  138. package/react-native.config.js +8 -0
  139. package/src/CompatNativeSafeAreaProvider.tsx +29 -0
  140. package/src/InitialWindow.kepler.ts +10 -0
  141. package/src/InitialWindow.native.ts +16 -0
  142. package/src/InitialWindow.ts +8 -0
  143. package/src/NativeSafeAreaProvider.kepler.tsx +3 -0
  144. package/src/NativeSafeAreaProvider.macos.tsx +3 -0
  145. package/src/NativeSafeAreaProvider.native.tsx +6 -0
  146. package/src/NativeSafeAreaProvider.tsx +129 -0
  147. package/src/NativeSafeAreaProvider.windows.tsx +3 -0
  148. package/src/SafeArea.types.ts +43 -0
  149. package/src/SafeAreaContext.tsx +148 -0
  150. package/src/SafeAreaView.kepler.tsx +3 -0
  151. package/src/SafeAreaView.macos.tsx +3 -0
  152. package/src/SafeAreaView.native.tsx +6 -0
  153. package/src/SafeAreaView.tsx +85 -0
  154. package/src/SafeAreaView.windows.tsx +3 -0
  155. package/src/index.tsx +4 -0
  156. package/src/useWindowDimensions.tsx +35 -0
@@ -0,0 +1,61 @@
1
+ #import "RNCSafeAreaProviderManager.h"
2
+
3
+ #import "RNCSafeAreaProvider.h"
4
+
5
+ @implementation RNCSafeAreaProviderManager
6
+
7
+ RCT_EXPORT_MODULE(RNCSafeAreaProvider)
8
+
9
+ RCT_EXPORT_VIEW_PROPERTY(onInsetsChange, RCTDirectEventBlock)
10
+
11
+ + (BOOL)requiresMainQueueSetup
12
+ {
13
+ return YES;
14
+ }
15
+
16
+ - (UIView *)view
17
+ {
18
+ return [RNCSafeAreaProvider new];
19
+ }
20
+
21
+ - (NSDictionary *)constantsToExport
22
+ {
23
+ UIWindow* window = [[UIApplication sharedApplication] keyWindow];
24
+ if (@available(iOS 11.0, *)) {
25
+ UIEdgeInsets safeAreaInsets = window.safeAreaInsets;
26
+ return @{
27
+ @"initialWindowMetrics": @{
28
+ @"insets": @{
29
+ @"top": @(safeAreaInsets.top),
30
+ @"right": @(safeAreaInsets.right),
31
+ @"bottom": @(safeAreaInsets.bottom),
32
+ @"left": @(safeAreaInsets.left),
33
+ },
34
+ @"frame": @{
35
+ @"x": @(window.frame.origin.x),
36
+ @"y": @(window.frame.origin.y),
37
+ @"width": @(window.frame.size.width),
38
+ @"height": @(window.frame.size.height),
39
+ },
40
+ }
41
+ };
42
+ } else {
43
+ return @{ @"initialWindowMetrics": @{
44
+ @"insets": @{
45
+ @"top": @(20),
46
+ @"right": @(0),
47
+ @"bottom": @(0),
48
+ @"left": @(0),
49
+ },
50
+ @"frame": @{
51
+ @"x": @(window.frame.origin.x),
52
+ @"y": @(window.frame.origin.y),
53
+ @"width": @(window.frame.size.width),
54
+ @"height": @(window.frame.size.height),
55
+ },
56
+ }
57
+ } ;
58
+ }
59
+ }
60
+
61
+ @end
@@ -0,0 +1,9 @@
1
+ #import <React/RCTShadowView.h>
2
+
3
+ NS_ASSUME_NONNULL_BEGIN
4
+
5
+ @interface RNCSafeAreaShadowView : RCTShadowView
6
+
7
+ @end
8
+
9
+ NS_ASSUME_NONNULL_END
@@ -0,0 +1,180 @@
1
+ #import "RNCSafeAreaShadowView.h"
2
+
3
+ #import <React/RCTAssert.h>
4
+ #include <math.h>
5
+
6
+ #import "RNCSafeAreaViewLocalData.h"
7
+ #import "RNCSafeAreaViewMode.h"
8
+ #import "RNCSafeAreaViewEdges.h"
9
+
10
+ // From RCTShadowView.m
11
+ typedef NS_ENUM(unsigned int, meta_prop_t) {
12
+ META_PROP_LEFT,
13
+ META_PROP_TOP,
14
+ META_PROP_RIGHT,
15
+ META_PROP_BOTTOM,
16
+ META_PROP_HORIZONTAL,
17
+ META_PROP_VERTICAL,
18
+ META_PROP_ALL,
19
+ META_PROP_COUNT,
20
+ };
21
+
22
+ @implementation RNCSafeAreaShadowView {
23
+ RNCSafeAreaViewLocalData *_localData;
24
+ bool _needsUpdate;
25
+ YGValue _paddingMetaProps[META_PROP_COUNT];
26
+ YGValue _marginMetaProps[META_PROP_COUNT];
27
+ }
28
+
29
+ - (instancetype)init
30
+ {
31
+ self = [super init];
32
+ if (self) {
33
+ _needsUpdate = false;
34
+ for (unsigned int ii = 0; ii < META_PROP_COUNT; ii++) {
35
+ _paddingMetaProps[ii] = YGValueUndefined;
36
+ _marginMetaProps[ii] = YGValueUndefined;
37
+ }
38
+ }
39
+ return self;
40
+ }
41
+
42
+ - (void)extractEdges:(YGValue[])_metaProps top:(CGFloat *)top right:(CGFloat *)right bottom:(CGFloat *)bottom left:(CGFloat *)left
43
+ {
44
+ if (_metaProps[META_PROP_ALL].unit == YGUnitPoint) {
45
+ *top = _metaProps[META_PROP_ALL].value;
46
+ *right = _metaProps[META_PROP_ALL].value;
47
+ *bottom = _metaProps[META_PROP_ALL].value;
48
+ *left = _metaProps[META_PROP_ALL].value;
49
+ }
50
+
51
+ if (_metaProps[META_PROP_HORIZONTAL].unit == YGUnitPoint) {
52
+ *right = _metaProps[META_PROP_HORIZONTAL].value;
53
+ *left = _metaProps[META_PROP_HORIZONTAL].value;
54
+ }
55
+
56
+ if (_metaProps[META_PROP_VERTICAL].unit == YGUnitPoint) {
57
+ *top = _metaProps[META_PROP_VERTICAL].value;
58
+ *bottom = _metaProps[META_PROP_VERTICAL].value;
59
+ }
60
+
61
+ if (_metaProps[META_PROP_TOP].unit == YGUnitPoint) {
62
+ *top = _metaProps[META_PROP_TOP].value;
63
+ }
64
+
65
+ if (_metaProps[META_PROP_RIGHT].unit == YGUnitPoint) {
66
+ *right = _metaProps[META_PROP_RIGHT].value;
67
+ }
68
+
69
+ if (_metaProps[META_PROP_BOTTOM].unit == YGUnitPoint) {
70
+ *bottom = _metaProps[META_PROP_BOTTOM].value;
71
+ }
72
+
73
+ if (_metaProps[META_PROP_LEFT].unit == YGUnitPoint) {
74
+ *left = _metaProps[META_PROP_LEFT].value;
75
+ }
76
+ }
77
+
78
+ - (void)resetInsetsForMode:(RNCSafeAreaViewMode)mode {
79
+ if (mode == RNCSafeAreaViewModePadding) {
80
+ super.paddingTop = _paddingMetaProps[META_PROP_TOP];
81
+ super.paddingRight = _paddingMetaProps[META_PROP_RIGHT];
82
+ super.paddingBottom = _paddingMetaProps[META_PROP_BOTTOM];
83
+ super.paddingLeft = _paddingMetaProps[META_PROP_LEFT];
84
+ } else if (mode == RNCSafeAreaViewModeMargin) {
85
+ super.marginTop = _marginMetaProps[META_PROP_TOP];
86
+ super.marginRight = _marginMetaProps[META_PROP_RIGHT];
87
+ super.marginBottom = _marginMetaProps[META_PROP_BOTTOM];
88
+ super.marginLeft = _marginMetaProps[META_PROP_LEFT];
89
+ }
90
+ }
91
+
92
+ - (void)updateInsets
93
+ {
94
+ if (_localData == nil) {
95
+ return;
96
+ }
97
+
98
+ UIEdgeInsets insets = _localData.insets;
99
+ RNCSafeAreaViewMode mode = _localData.mode;
100
+ RNCSafeAreaViewEdges edges = _localData.edges;
101
+
102
+ CGFloat top = 0;
103
+ CGFloat right = 0;
104
+ CGFloat bottom = 0;
105
+ CGFloat left = 0;
106
+
107
+ CGFloat insetTop = (edges & RNCSafeAreaViewEdgesTop) ? insets.top : 0;
108
+ CGFloat insetRight = (edges & RNCSafeAreaViewEdgesRight) ? insets.right : 0;
109
+ CGFloat insetBottom = (edges & RNCSafeAreaViewEdgesBottom) ? insets.bottom : 0;
110
+ CGFloat insetLeft = (edges & RNCSafeAreaViewEdgesLeft) ? insets.left : 0;
111
+
112
+ if (mode == RNCSafeAreaViewModePadding) {
113
+ [self extractEdges:_paddingMetaProps top:&top right:&right bottom:&bottom left:&left];
114
+ super.paddingTop = (YGValue){insetTop + top, YGUnitPoint};
115
+ super.paddingRight = (YGValue){insetRight + right, YGUnitPoint};
116
+ super.paddingBottom = (YGValue){insetBottom + bottom, YGUnitPoint};
117
+ super.paddingLeft = (YGValue){insetLeft + left, YGUnitPoint};
118
+ } else if (mode == RNCSafeAreaViewModeMargin) {
119
+ [self extractEdges:_marginMetaProps top:&top right:&right bottom:&bottom left:&left];
120
+ super.marginTop = (YGValue){insetTop + top, YGUnitPoint};
121
+ super.marginRight = (YGValue){insetRight + right, YGUnitPoint};
122
+ super.marginBottom = (YGValue){insetBottom + bottom, YGUnitPoint};
123
+ super.marginLeft = (YGValue){insetLeft + left, YGUnitPoint};
124
+ }
125
+ }
126
+
127
+ - (void)didSetProps:(NSArray<NSString *> *)changedProps
128
+ {
129
+ if (_needsUpdate) {
130
+ _needsUpdate = false;
131
+ [self updateInsets];
132
+ }
133
+ [super didSetProps:changedProps];
134
+ }
135
+
136
+ - (void)setLocalData:(RNCSafeAreaViewLocalData *)localData
137
+ {
138
+ RCTAssert(
139
+ [localData isKindOfClass:[RNCSafeAreaViewLocalData class]],
140
+ @"Local data object for `RCTRNCSafeAreaShadowView` must be `RCTRNCSafeAreaViewLocalData` instance."
141
+ );
142
+
143
+ if (_localData != nil && _localData.mode != localData.mode) {
144
+ [self resetInsetsForMode:_localData.mode];
145
+ }
146
+
147
+ _localData = localData;
148
+ _needsUpdate = false;
149
+ [self updateInsets];
150
+
151
+ if (_localData.mode == RNCSafeAreaViewModePadding) {
152
+ [super didSetProps:@[@"paddingTop", @"paddingRight", @"paddingBottom", @"paddingLeft"]];
153
+ } else {
154
+ [super didSetProps:@[@"marginTop", @"marginRight", @"marginBottom", @"marginLeft"]];
155
+ }
156
+ }
157
+
158
+ #define SHADOW_VIEW_MARGIN_PADDING_PROP(edge, metaProp) \
159
+ - (void)setPadding##edge:(YGValue)value \
160
+ { \
161
+ [super setPadding##edge:value]; \
162
+ _needsUpdate = true; \
163
+ _paddingMetaProps[META_PROP_##metaProp] = value; \
164
+ } \
165
+ - (void)setMargin##edge:(YGValue)value \
166
+ { \
167
+ [super setMargin##edge:value]; \
168
+ _needsUpdate = true; \
169
+ _marginMetaProps[META_PROP_##metaProp] = value; \
170
+ }
171
+
172
+ SHADOW_VIEW_MARGIN_PADDING_PROP(, ALL);
173
+ SHADOW_VIEW_MARGIN_PADDING_PROP(Vertical, VERTICAL);
174
+ SHADOW_VIEW_MARGIN_PADDING_PROP(Horizontal, HORIZONTAL);
175
+ SHADOW_VIEW_MARGIN_PADDING_PROP(Top, TOP);
176
+ SHADOW_VIEW_MARGIN_PADDING_PROP(Right, RIGHT);
177
+ SHADOW_VIEW_MARGIN_PADDING_PROP(Bottom, BOTTOM);
178
+ SHADOW_VIEW_MARGIN_PADDING_PROP(Left, LEFT);
179
+
180
+ @end
@@ -0,0 +1,21 @@
1
+ #import <UIKit/UIKit.h>
2
+ #import <React/RCTView.h>
3
+ #import <React/RCTBridge.h>
4
+
5
+ #import "RNCSafeAreaViewMode.h"
6
+ #import "RNCSafeAreaViewEdges.h"
7
+
8
+ NS_ASSUME_NONNULL_BEGIN
9
+
10
+ @class RNCSafeAreaView;
11
+
12
+ @interface RNCSafeAreaView: RCTView
13
+
14
+ - (instancetype)initWithBridge:(RCTBridge *)bridge;
15
+
16
+ @property (nonatomic, assign) RNCSafeAreaViewMode mode;
17
+ @property (nonatomic, assign) RNCSafeAreaViewEdges edges;
18
+
19
+ @end
20
+
21
+ NS_ASSUME_NONNULL_END
@@ -0,0 +1,118 @@
1
+ #import "RNCSafeAreaView.h"
2
+
3
+ #import <React/RCTBridge.h>
4
+ #import <React/RCTUIManager.h>
5
+
6
+ #import "RNCSafeAreaViewLocalData.h"
7
+ #import "RNCSafeAreaViewMode.h"
8
+ #import "RNCSafeAreaViewEdges.h"
9
+ #import "RCTView+SafeAreaCompat.h"
10
+ #import "RNCSafeAreaProvider.h"
11
+
12
+ @implementation RNCSafeAreaView {
13
+ __weak RCTBridge *_bridge;
14
+ UIEdgeInsets _currentSafeAreaInsets;
15
+ RNCSafeAreaViewMode _mode;
16
+ RNCSafeAreaViewEdges _edges;
17
+ __weak UIView * _Nullable _providerView;
18
+ }
19
+
20
+ - (instancetype)initWithBridge:(RCTBridge *)bridge
21
+ {
22
+ if (self = [super initWithFrame:CGRectZero]) {
23
+ _bridge = bridge;
24
+ // Defaults
25
+ _mode = RNCSafeAreaViewModePadding;
26
+ _edges = RNCSafeAreaViewEdgesAll;
27
+ }
28
+
29
+ return self;
30
+ }
31
+
32
+ RCT_NOT_IMPLEMENTED(-(instancetype)initWithCoder : (NSCoder *)decoder)
33
+ RCT_NOT_IMPLEMENTED(-(instancetype)initWithFrame : (CGRect)frame)
34
+
35
+ - (NSString *)description
36
+ {
37
+ NSString *superDescription = [super description];
38
+
39
+ // Cutting the last `>` character.
40
+ if (superDescription.length > 0 && [superDescription characterAtIndex:superDescription.length - 1] == '>') {
41
+ superDescription = [superDescription substringToIndex:superDescription.length - 1];
42
+ }
43
+
44
+ return [NSString stringWithFormat:@"%@; RNCSafeAreaInsets = %@; appliedRNCSafeAreaInsets = %@>",
45
+ superDescription,
46
+ NSStringFromUIEdgeInsets([_providerView safeAreaInsetsOrEmulate]),
47
+ NSStringFromUIEdgeInsets(_currentSafeAreaInsets)];
48
+ }
49
+
50
+ - (void)safeAreaInsetsDidChange
51
+ {
52
+ [super safeAreaInsetsDidChange];
53
+ [self invalidateSafeAreaInsets];
54
+ }
55
+
56
+ - (void)layoutSubviews
57
+ {
58
+ [super layoutSubviews];
59
+
60
+ if (!self.nativeSafeAreaSupport) {
61
+ [self invalidateSafeAreaInsets];
62
+ }
63
+ }
64
+
65
+ - (void)didMoveToWindow
66
+ {
67
+ _providerView = [self findNearestProvider];
68
+ [self invalidateSafeAreaInsets];
69
+ }
70
+
71
+ - (void)invalidateSafeAreaInsets
72
+ {
73
+ if (_providerView == nil) {
74
+ return;
75
+ }
76
+ UIEdgeInsets safeAreaInsets = [_providerView safeAreaInsetsOrEmulate];
77
+
78
+ if (UIEdgeInsetsEqualToEdgeInsetsWithThreshold(safeAreaInsets, _currentSafeAreaInsets, 1.0 / RCTScreenScale())) {
79
+ return;
80
+ }
81
+
82
+ _currentSafeAreaInsets = safeAreaInsets;
83
+ [self updateLocalData];
84
+ }
85
+
86
+ - (UIView *)findNearestProvider
87
+ {
88
+ UIView *current = self.reactSuperview;
89
+ while (current != nil) {
90
+ if ([current isKindOfClass:RNCSafeAreaProvider.class] ) {
91
+ return current;
92
+ }
93
+ current = current.reactSuperview;
94
+ }
95
+ return self;
96
+ }
97
+
98
+ - (void)updateLocalData
99
+ {
100
+ RNCSafeAreaViewLocalData *localData = [[RNCSafeAreaViewLocalData alloc] initWithInsets:_currentSafeAreaInsets
101
+ mode:_mode
102
+ edges:_edges];
103
+ [_bridge.uiManager setLocalData:localData forView:self];
104
+ }
105
+
106
+ - (void)setMode:(RNCSafeAreaViewMode)mode
107
+ {
108
+ _mode = mode;
109
+ [self updateLocalData];
110
+ }
111
+
112
+ - (void)setEdges:(RNCSafeAreaViewEdges)edges
113
+ {
114
+ _edges = edges;
115
+ [self updateLocalData];
116
+ }
117
+
118
+ @end
@@ -0,0 +1,9 @@
1
+ #import <Foundation/Foundation.h>
2
+
3
+ typedef NS_ENUM(NSInteger, RNCSafeAreaViewEdges) {
4
+ RNCSafeAreaViewEdgesTop = 0b1000,
5
+ RNCSafeAreaViewEdgesRight = 0b0100,
6
+ RNCSafeAreaViewEdgesBottom = 0b0010,
7
+ RNCSafeAreaViewEdgesLeft = 0b0001,
8
+ RNCSafeAreaViewEdgesAll = 0b1111,
9
+ };
@@ -0,0 +1,13 @@
1
+ #import <React/RCTConvert.h>
2
+ #import "RNCSafeAreaViewEdges.h"
3
+
4
+ @implementation RCTConvert (RNCSafeAreaView)
5
+
6
+ RCT_MULTI_ENUM_CONVERTER(RNCSafeAreaViewEdges, (@{
7
+ @"top": @(RNCSafeAreaViewEdgesTop),
8
+ @"right": @(RNCSafeAreaViewEdgesRight),
9
+ @"bottom": @(RNCSafeAreaViewEdgesBottom),
10
+ @"left": @(RNCSafeAreaViewEdgesLeft),
11
+ }), RNCSafeAreaViewEdgesAll, integerValue);
12
+
13
+ @end
@@ -0,0 +1,18 @@
1
+ #import <UIKit/UIKit.h>
2
+
3
+ #import "RNCSafeAreaViewMode.h"
4
+ #import "RNCSafeAreaViewEdges.h"
5
+
6
+ NS_ASSUME_NONNULL_BEGIN
7
+
8
+ @interface RNCSafeAreaViewLocalData : NSObject
9
+
10
+ - (instancetype)initWithInsets:(UIEdgeInsets)insets mode:(RNCSafeAreaViewMode)mode edges:(RNCSafeAreaViewEdges)edges;
11
+
12
+ @property (atomic, readonly) UIEdgeInsets insets;
13
+ @property (atomic, readonly) RNCSafeAreaViewMode mode;
14
+ @property (atomic, readonly) RNCSafeAreaViewEdges edges;
15
+
16
+ @end
17
+
18
+ NS_ASSUME_NONNULL_END
@@ -0,0 +1,16 @@
1
+ #import "RNCSafeAreaViewLocalData.h"
2
+
3
+ @implementation RNCSafeAreaViewLocalData
4
+
5
+ - (instancetype)initWithInsets:(UIEdgeInsets)insets mode:(RNCSafeAreaViewMode)mode edges:(RNCSafeAreaViewEdges)edges
6
+ {
7
+ if (self = [super init]) {
8
+ _insets = insets;
9
+ _mode = mode;
10
+ _edges = edges;
11
+ }
12
+
13
+ return self;
14
+ }
15
+
16
+ @end
@@ -0,0 +1,9 @@
1
+ #import <React/RCTViewManager.h>
2
+
3
+ NS_ASSUME_NONNULL_BEGIN
4
+
5
+ @interface RNCSafeAreaViewManager : RCTViewManager
6
+
7
+ @end
8
+
9
+ NS_ASSUME_NONNULL_END
@@ -0,0 +1,25 @@
1
+ #import "RNCSafeAreaViewManager.h"
2
+
3
+ #import "RNCSafeAreaShadowView.h"
4
+ #import "RNCSafeAreaView.h"
5
+ #import "RNCSafeAreaViewMode.h"
6
+ #import "RNCSafeAreaViewEdges.h"
7
+
8
+ @implementation RNCSafeAreaViewManager
9
+
10
+ RCT_EXPORT_MODULE(RNCSafeAreaView)
11
+
12
+ - (UIView *)view
13
+ {
14
+ return [[RNCSafeAreaView alloc] initWithBridge:self.bridge];
15
+ }
16
+
17
+ - (RNCSafeAreaShadowView *)shadowView
18
+ {
19
+ return [RNCSafeAreaShadowView new];
20
+ }
21
+
22
+ RCT_EXPORT_VIEW_PROPERTY(mode, RNCSafeAreaViewMode)
23
+ RCT_EXPORT_VIEW_PROPERTY(edges, RNCSafeAreaViewEdges)
24
+
25
+ @end
@@ -0,0 +1,7 @@
1
+ #import <Foundation/Foundation.h>
2
+
3
+ typedef NS_ENUM(NSInteger, RNCSafeAreaViewMode) {
4
+ RNCSafeAreaViewModePadding,
5
+ RNCSafeAreaViewModeMargin,
6
+ RNCSafeAreaViewModeBorder,
7
+ };
@@ -0,0 +1,11 @@
1
+ #import <React/RCTConvert.h>
2
+ #import "RNCSafeAreaViewMode.h"
3
+
4
+ @implementation RCTConvert (RNCSafeAreaView)
5
+
6
+ RCT_MULTI_ENUM_CONVERTER(RNCSafeAreaViewMode, (@{
7
+ @"padding": @(RNCSafeAreaViewModePadding),
8
+ @"margin": @(RNCSafeAreaViewModeMargin),
9
+ }), RNCSafeAreaViewModePadding, integerValue);
10
+
11
+ @end