@amazon-devices/react-native-safe-area-context 2.0.9000000000 → 2.0.9000000001

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 (132) hide show
  1. package/SystemBundles/{85c8d24b7f717b77a2deb00e32cc2aaa293a5a16c46eecebca21e95bda425730.bundle → 51fc85bf8d38b1dffede0d601b4549191dcfd495b78de3007c0b6f0f183163ac.bundle} +805 -2723
  2. package/SystemBundles/51fc85bf8d38b1dffede0d601b4549191dcfd495b78de3007c0b6f0f183163ac.map +3579 -0
  3. package/SystemModules/amzn__react-native-safe-area-context-2.modules.txt +1 -37
  4. package/SystemModules/amzn__react-native-safe-area-context-2.private.modules.txt +29 -36
  5. package/kepler-compatibility.json +3 -2
  6. package/lib/commonjs/CompatNativeSafeAreaProvider.js.map +1 -1
  7. package/lib/commonjs/InitialWindow.js.map +1 -1
  8. package/lib/commonjs/InitialWindow.kepler.js.map +1 -1
  9. package/lib/commonjs/InitialWindow.native.js.map +1 -1
  10. package/lib/commonjs/NativeSafeAreaProvider.js +3 -0
  11. package/lib/commonjs/NativeSafeAreaProvider.js.map +1 -1
  12. package/lib/commonjs/NativeSafeAreaProvider.kepler.js.map +1 -1
  13. package/lib/commonjs/NativeSafeAreaProvider.macos.js.map +1 -1
  14. package/lib/commonjs/NativeSafeAreaProvider.native.js.map +1 -1
  15. package/lib/commonjs/NativeSafeAreaProvider.windows.js.map +1 -1
  16. package/lib/commonjs/SafeArea.types.js.map +1 -1
  17. package/lib/commonjs/SafeAreaContext.js +2 -3
  18. package/lib/commonjs/SafeAreaContext.js.map +1 -1
  19. package/lib/commonjs/SafeAreaView.js.map +1 -1
  20. package/lib/commonjs/SafeAreaView.kepler.js.map +1 -1
  21. package/lib/commonjs/SafeAreaView.macos.js.map +1 -1
  22. package/lib/commonjs/SafeAreaView.native.js.map +1 -1
  23. package/lib/commonjs/SafeAreaView.windows.js.map +1 -1
  24. package/lib/commonjs/index.js.map +1 -1
  25. package/lib/commonjs/useWindowDimensions.js.map +1 -1
  26. package/lib/module/CompatNativeSafeAreaProvider.js.map +1 -1
  27. package/lib/module/InitialWindow.js.map +1 -1
  28. package/lib/module/InitialWindow.kepler.js.map +1 -1
  29. package/lib/module/InitialWindow.native.js.map +1 -1
  30. package/lib/module/NativeSafeAreaProvider.js +2 -0
  31. package/lib/module/NativeSafeAreaProvider.js.map +1 -1
  32. package/lib/module/NativeSafeAreaProvider.kepler.js.map +1 -1
  33. package/lib/module/NativeSafeAreaProvider.macos.js.map +1 -1
  34. package/lib/module/NativeSafeAreaProvider.native.js.map +1 -1
  35. package/lib/module/NativeSafeAreaProvider.windows.js.map +1 -1
  36. package/lib/module/SafeArea.types.js.map +1 -1
  37. package/lib/module/SafeAreaContext.js +2 -3
  38. package/lib/module/SafeAreaContext.js.map +1 -1
  39. package/lib/module/SafeAreaView.js.map +1 -1
  40. package/lib/module/SafeAreaView.kepler.js.map +1 -1
  41. package/lib/module/SafeAreaView.macos.js.map +1 -1
  42. package/lib/module/SafeAreaView.native.js.map +1 -1
  43. package/lib/module/SafeAreaView.windows.js.map +1 -1
  44. package/lib/module/index.js.map +1 -1
  45. package/lib/module/useWindowDimensions.js.map +1 -1
  46. package/lib/typescript/CompatNativeSafeAreaProvider.d.ts +4 -0
  47. package/lib/typescript/CompatNativeSafeAreaProvider.d.ts.map +1 -0
  48. package/lib/typescript/{src/InitialWindow.d.ts → InitialWindow.d.ts} +2 -1
  49. package/lib/typescript/InitialWindow.d.ts.map +1 -0
  50. package/lib/typescript/{src/InitialWindow.kepler.d.ts → InitialWindow.kepler.d.ts} +1 -0
  51. package/lib/typescript/InitialWindow.kepler.d.ts.map +1 -0
  52. package/lib/typescript/{src/InitialWindow.native.d.ts → InitialWindow.native.d.ts} +1 -0
  53. package/lib/typescript/InitialWindow.native.d.ts.map +1 -0
  54. package/lib/typescript/NativeSafeAreaProvider.d.ts +4 -0
  55. package/lib/typescript/NativeSafeAreaProvider.d.ts.map +1 -0
  56. package/lib/typescript/{src/NativeSafeAreaProvider.kepler.d.ts → NativeSafeAreaProvider.kepler.d.ts} +1 -0
  57. package/lib/typescript/NativeSafeAreaProvider.kepler.d.ts.map +1 -0
  58. package/lib/typescript/{src/NativeSafeAreaProvider.macos.d.ts → NativeSafeAreaProvider.macos.d.ts} +1 -0
  59. package/lib/typescript/NativeSafeAreaProvider.macos.d.ts.map +1 -0
  60. package/lib/typescript/{src/NativeSafeAreaProvider.native.d.ts → NativeSafeAreaProvider.native.d.ts} +1 -0
  61. package/lib/typescript/NativeSafeAreaProvider.native.d.ts.map +1 -0
  62. package/lib/typescript/{src/NativeSafeAreaProvider.windows.d.ts → NativeSafeAreaProvider.windows.d.ts} +1 -0
  63. package/lib/typescript/NativeSafeAreaProvider.windows.d.ts.map +1 -0
  64. package/lib/typescript/{src/SafeArea.types.d.ts → SafeArea.types.d.ts} +2 -1
  65. package/lib/typescript/SafeArea.types.d.ts.map +1 -0
  66. package/lib/typescript/{src/SafeAreaContext.d.ts → SafeAreaContext.d.ts} +4 -3
  67. package/lib/typescript/SafeAreaContext.d.ts.map +1 -0
  68. package/lib/typescript/SafeAreaView.d.ts +4 -0
  69. package/lib/typescript/SafeAreaView.d.ts.map +1 -0
  70. package/lib/typescript/{src/SafeAreaView.kepler.d.ts → SafeAreaView.kepler.d.ts} +1 -0
  71. package/lib/typescript/SafeAreaView.kepler.d.ts.map +1 -0
  72. package/lib/typescript/{src/SafeAreaView.macos.d.ts → SafeAreaView.macos.d.ts} +1 -0
  73. package/lib/typescript/SafeAreaView.macos.d.ts.map +1 -0
  74. package/lib/typescript/{src/SafeAreaView.native.d.ts → SafeAreaView.native.d.ts} +1 -0
  75. package/lib/typescript/SafeAreaView.native.d.ts.map +1 -0
  76. package/lib/typescript/{src/SafeAreaView.windows.d.ts → SafeAreaView.windows.d.ts} +1 -0
  77. package/lib/typescript/SafeAreaView.windows.d.ts.map +1 -0
  78. package/lib/typescript/{src/index.d.ts → index.d.ts} +1 -0
  79. package/lib/typescript/index.d.ts.map +1 -0
  80. package/lib/typescript/{src/useWindowDimensions.d.ts → useWindowDimensions.d.ts} +1 -0
  81. package/lib/typescript/useWindowDimensions.d.ts.map +1 -0
  82. package/package.json +1 -1
  83. package/src/InitialWindow.ts +1 -1
  84. package/src/NativeSafeAreaProvider.tsx +3 -1
  85. package/src/SafeArea.types.ts +1 -1
  86. package/src/SafeAreaContext.tsx +2 -2
  87. package/src/SafeAreaView.tsx +1 -1
  88. package/src/__tests__/InitialWindow-test.tsx +47 -0
  89. package/src/__tests__/SafeAreaContext-test.tsx +121 -0
  90. package/src/__tests__/SafeAreaView-test.tsx +35 -0
  91. package/src/__tests__/__snapshots__/SafeAreaContext-test.tsx.snap +183 -0
  92. package/src/__tests__/__snapshots__/SafeAreaView-test.tsx.snap +43 -0
  93. package/SystemBundles/85c8d24b7f717b77a2deb00e32cc2aaa293a5a16c46eecebca21e95bda425730.map +0 -4335
  94. package/android/build.gradle +0 -46
  95. package/android/src/main/AndroidManifest.xml +0 -6
  96. package/android/src/main/java/com/th3rdwave/safeareacontext/EdgeInsets.java +0 -22
  97. package/android/src/main/java/com/th3rdwave/safeareacontext/InsetsChangeEvent.java +0 -33
  98. package/android/src/main/java/com/th3rdwave/safeareacontext/Rect.java +0 -22
  99. package/android/src/main/java/com/th3rdwave/safeareacontext/SafeAreaContextPackage.java +0 -31
  100. package/android/src/main/java/com/th3rdwave/safeareacontext/SafeAreaProvider.java +0 -66
  101. package/android/src/main/java/com/th3rdwave/safeareacontext/SafeAreaProviderManager.java +0 -94
  102. package/android/src/main/java/com/th3rdwave/safeareacontext/SafeAreaUtils.java +0 -82
  103. package/android/src/main/java/com/th3rdwave/safeareacontext/SafeAreaView.java +0 -159
  104. package/android/src/main/java/com/th3rdwave/safeareacontext/SafeAreaViewEdges.java +0 -8
  105. package/android/src/main/java/com/th3rdwave/safeareacontext/SafeAreaViewLocalData.java +0 -27
  106. package/android/src/main/java/com/th3rdwave/safeareacontext/SafeAreaViewManager.java +0 -72
  107. package/android/src/main/java/com/th3rdwave/safeareacontext/SafeAreaViewMode.java +0 -6
  108. package/android/src/main/java/com/th3rdwave/safeareacontext/SafeAreaViewShadowNode.java +0 -201
  109. package/android/src/main/java/com/th3rdwave/safeareacontext/SerializationUtils.java +0 -52
  110. package/ios/SafeAreaView/RCTView+SafeAreaCompat.h +0 -16
  111. package/ios/SafeAreaView/RCTView+SafeAreaCompat.m +0 -57
  112. package/ios/SafeAreaView/RNCSafeAreaProvider.h +0 -13
  113. package/ios/SafeAreaView/RNCSafeAreaProvider.m +0 -65
  114. package/ios/SafeAreaView/RNCSafeAreaProviderManager.h +0 -9
  115. package/ios/SafeAreaView/RNCSafeAreaProviderManager.m +0 -61
  116. package/ios/SafeAreaView/RNCSafeAreaShadowView.h +0 -9
  117. package/ios/SafeAreaView/RNCSafeAreaShadowView.m +0 -180
  118. package/ios/SafeAreaView/RNCSafeAreaView.h +0 -21
  119. package/ios/SafeAreaView/RNCSafeAreaView.m +0 -118
  120. package/ios/SafeAreaView/RNCSafeAreaViewEdges.h +0 -9
  121. package/ios/SafeAreaView/RNCSafeAreaViewEdges.m +0 -13
  122. package/ios/SafeAreaView/RNCSafeAreaViewLocalData.h +0 -18
  123. package/ios/SafeAreaView/RNCSafeAreaViewLocalData.m +0 -16
  124. package/ios/SafeAreaView/RNCSafeAreaViewManager.h +0 -9
  125. package/ios/SafeAreaView/RNCSafeAreaViewManager.m +0 -25
  126. package/ios/SafeAreaView/RNCSafeAreaViewMode.h +0 -7
  127. package/ios/SafeAreaView/RNCSafeAreaViewMode.m +0 -11
  128. package/ios/SafeAreaView.xcodeproj/project.pbxproj +0 -338
  129. package/lib/typescript/src/CompatNativeSafeAreaProvider.d.ts +0 -2
  130. package/lib/typescript/src/NativeSafeAreaProvider.d.ts +0 -2
  131. package/lib/typescript/src/SafeAreaView.d.ts +0 -2
  132. package/react-native-safe-area-context.podspec +0 -19
@@ -1,201 +0,0 @@
1
- package com.th3rdwave.safeareacontext;
2
-
3
- import com.facebook.react.bridge.Dynamic;
4
- import com.facebook.react.bridge.ReadableType;
5
- import com.facebook.react.uimanager.LayoutShadowNode;
6
- import com.facebook.react.uimanager.NativeViewHierarchyOptimizer;
7
- import com.facebook.react.uimanager.PixelUtil;
8
- import com.facebook.react.uimanager.Spacing;
9
- import com.facebook.react.uimanager.ViewProps;
10
- import com.facebook.react.uimanager.annotations.ReactPropGroup;
11
-
12
- import java.util.EnumSet;
13
-
14
- import androidx.annotation.Nullable;
15
-
16
- public class SafeAreaViewShadowNode extends LayoutShadowNode {
17
- private @Nullable SafeAreaViewLocalData mLocalData;
18
-
19
- private float[] mPaddings;
20
- private float[] mMargins;
21
- private boolean mNeedsUpdate = false;
22
-
23
- public SafeAreaViewShadowNode() {
24
- super();
25
-
26
- mPaddings = new float[ViewProps.PADDING_MARGIN_SPACING_TYPES.length];
27
- mMargins = new float[ViewProps.PADDING_MARGIN_SPACING_TYPES.length];
28
-
29
- for (int i = 0; i < ViewProps.PADDING_MARGIN_SPACING_TYPES.length; i += 1) {
30
- mPaddings[i] = Float.NaN;
31
- mMargins[i] = Float.NaN;
32
- }
33
- }
34
-
35
- private void updateInsets() {
36
- if (mLocalData == null) {
37
- return;
38
- }
39
-
40
- float top = 0;
41
- float right = 0;
42
- float bottom = 0;
43
- float left = 0;
44
-
45
- float[] meta = mLocalData.getMode() == SafeAreaViewMode.PADDING ? mPaddings : mMargins;
46
-
47
- float allEdges = meta[Spacing.ALL];
48
- if (!Float.isNaN(allEdges)) {
49
- top = allEdges;
50
- right = allEdges;
51
- bottom = allEdges;
52
- left = allEdges;
53
- }
54
-
55
- float verticalEdges = meta[Spacing.VERTICAL];
56
- if (!Float.isNaN(verticalEdges)) {
57
- top = verticalEdges;
58
- bottom = verticalEdges;
59
- }
60
-
61
- float horizontalEdges = meta[Spacing.HORIZONTAL];
62
- if (!Float.isNaN(horizontalEdges)) {
63
- right = horizontalEdges;
64
- left = horizontalEdges;
65
- }
66
-
67
- float topEdge = meta[Spacing.TOP];
68
- if (!Float.isNaN(topEdge)) {
69
- top = topEdge;
70
- }
71
-
72
- float rightEdge = meta[Spacing.RIGHT];
73
- if (!Float.isNaN(rightEdge)) {
74
- right = rightEdge;
75
- }
76
-
77
- float bottomEdge = meta[Spacing.BOTTOM];
78
- if (!Float.isNaN(bottomEdge)) {
79
- bottom = bottomEdge;
80
- }
81
-
82
- float leftEdge = meta[Spacing.LEFT];
83
- if (!Float.isNaN(leftEdge)) {
84
- left = leftEdge;
85
- }
86
-
87
- top = PixelUtil.toPixelFromDIP(top);
88
- right = PixelUtil.toPixelFromDIP(right);
89
- bottom = PixelUtil.toPixelFromDIP(bottom);
90
- left = PixelUtil.toPixelFromDIP(left);
91
-
92
- EnumSet<SafeAreaViewEdges> edges = mLocalData.getEdges();
93
- EdgeInsets insets = mLocalData.getInsets();
94
- float insetTop = edges.contains(SafeAreaViewEdges.TOP) ? insets.top : 0;
95
- float insetRight = edges.contains(SafeAreaViewEdges.RIGHT) ? insets.right : 0;
96
- float insetBottom = edges.contains(SafeAreaViewEdges.BOTTOM) ? insets.bottom : 0;
97
- float insetLeft = edges.contains(SafeAreaViewEdges.LEFT) ? insets.left : 0;
98
-
99
- if (mLocalData.getMode() == SafeAreaViewMode.PADDING) {
100
- super.setPadding(Spacing.TOP, insetTop + top);
101
- super.setPadding(Spacing.RIGHT, insetRight + right);
102
- super.setPadding(Spacing.BOTTOM, insetBottom + bottom);
103
- super.setPadding(Spacing.LEFT, insetLeft + left);
104
- } else {
105
- super.setMargin(Spacing.TOP, insetTop + top);
106
- super.setMargin(Spacing.RIGHT, insetRight + right);
107
- super.setMargin(Spacing.BOTTOM, insetBottom + bottom);
108
- super.setMargin(Spacing.LEFT, insetLeft + left);
109
- }
110
- }
111
-
112
- private void resetInsets(SafeAreaViewMode mode) {
113
- if (mode == SafeAreaViewMode.PADDING) {
114
- super.setPadding(Spacing.TOP, mPaddings[Spacing.TOP]);
115
- super.setPadding(Spacing.RIGHT, mPaddings[Spacing.TOP]);
116
- super.setPadding(Spacing.BOTTOM, mPaddings[Spacing.BOTTOM]);
117
- super.setPadding(Spacing.LEFT, mPaddings[Spacing.LEFT]);
118
- } else {
119
- super.setMargin(Spacing.TOP, mMargins[Spacing.TOP]);
120
- super.setMargin(Spacing.RIGHT, mMargins[Spacing.TOP]);
121
- super.setMargin(Spacing.BOTTOM, mMargins[Spacing.BOTTOM]);
122
- super.setMargin(Spacing.LEFT, mMargins[Spacing.LEFT]);
123
- }
124
- }
125
-
126
- // The signature for onBeforeLayout is different in RN 0.59.
127
- // Remove when we drop support for this version and add back @Override and super call to
128
- // onBeforeLayout(NativeViewHierarchyOptimizer).
129
- public void onBeforeLayout() {
130
- if (mNeedsUpdate) {
131
- mNeedsUpdate = false;
132
- updateInsets();
133
- }
134
- }
135
-
136
- public void onBeforeLayout(NativeViewHierarchyOptimizer nativeViewHierarchyOptimizer) {
137
- if (mNeedsUpdate) {
138
- mNeedsUpdate = false;
139
- updateInsets();
140
- }
141
- }
142
-
143
- @Override
144
- public void setLocalData(Object data) {
145
- if (!(data instanceof SafeAreaViewLocalData)) {
146
- return;
147
- }
148
-
149
- SafeAreaViewLocalData localData = (SafeAreaViewLocalData) data;
150
-
151
- if (mLocalData != null && mLocalData.getMode() != localData.getMode()) {
152
- resetInsets(mLocalData.getMode());
153
- }
154
-
155
- mLocalData = localData;
156
-
157
- mNeedsUpdate = false;
158
- updateInsets();
159
- }
160
-
161
- // Names needs to reflect exact order in LayoutShadowNode.java
162
- @Override
163
- @ReactPropGroup(
164
- names = {
165
- ViewProps.PADDING,
166
- ViewProps.PADDING_VERTICAL,
167
- ViewProps.PADDING_HORIZONTAL,
168
- ViewProps.PADDING_START,
169
- ViewProps.PADDING_END,
170
- ViewProps.PADDING_TOP,
171
- ViewProps.PADDING_BOTTOM,
172
- ViewProps.PADDING_LEFT,
173
- ViewProps.PADDING_RIGHT,
174
- })
175
- public void setPaddings(int index, Dynamic padding) {
176
- int spacingType = ViewProps.PADDING_MARGIN_SPACING_TYPES[index];
177
- mPaddings[spacingType] = padding.getType() == ReadableType.Number ? (float) padding.asDouble() : Float.NaN;
178
- super.setPaddings(index, padding);
179
- mNeedsUpdate = true;
180
- }
181
-
182
- @Override
183
- @ReactPropGroup(
184
- names = {
185
- ViewProps.MARGIN,
186
- ViewProps.MARGIN_VERTICAL,
187
- ViewProps.MARGIN_HORIZONTAL,
188
- ViewProps.MARGIN_START,
189
- ViewProps.MARGIN_END,
190
- ViewProps.MARGIN_TOP,
191
- ViewProps.MARGIN_BOTTOM,
192
- ViewProps.MARGIN_LEFT,
193
- ViewProps.MARGIN_RIGHT,
194
- })
195
- public void setMargins(int index, Dynamic margin) {
196
- int spacingType = ViewProps.PADDING_MARGIN_SPACING_TYPES[index];
197
- mMargins[spacingType] = margin.getType() == ReadableType.Number ? (float) margin.asDouble() : Float.NaN;
198
- super.setMargins(index, margin);
199
- mNeedsUpdate = true;
200
- }
201
- }
@@ -1,52 +0,0 @@
1
- package com.th3rdwave.safeareacontext;
2
-
3
- import com.facebook.react.bridge.Arguments;
4
- import com.facebook.react.bridge.WritableMap;
5
- import com.facebook.react.common.MapBuilder;
6
- import com.facebook.react.uimanager.PixelUtil;
7
-
8
- import java.util.Map;
9
-
10
- /* package */ class SerializationUtils {
11
- static WritableMap edgeInsetsToJsMap(EdgeInsets insets) {
12
- WritableMap insetsMap = Arguments.createMap();
13
- insetsMap.putDouble("top", PixelUtil.toDIPFromPixel(insets.top));
14
- insetsMap.putDouble("right", PixelUtil.toDIPFromPixel(insets.right));
15
- insetsMap.putDouble("bottom", PixelUtil.toDIPFromPixel(insets.bottom));
16
- insetsMap.putDouble("left", PixelUtil.toDIPFromPixel(insets.left));
17
- return insetsMap;
18
- }
19
-
20
- static Map<String, Float> edgeInsetsToJavaMap(EdgeInsets insets) {
21
- return MapBuilder.of(
22
- "top",
23
- PixelUtil.toDIPFromPixel(insets.top),
24
- "right",
25
- PixelUtil.toDIPFromPixel(insets.right),
26
- "bottom",
27
- PixelUtil.toDIPFromPixel(insets.bottom),
28
- "left",
29
- PixelUtil.toDIPFromPixel(insets.left));
30
- }
31
-
32
- static WritableMap rectToJsMap(Rect rect) {
33
- WritableMap rectMap = Arguments.createMap();
34
- rectMap.putDouble("x", PixelUtil.toDIPFromPixel(rect.x));
35
- rectMap.putDouble("y", PixelUtil.toDIPFromPixel(rect.y));
36
- rectMap.putDouble("width", PixelUtil.toDIPFromPixel(rect.width));
37
- rectMap.putDouble("height", PixelUtil.toDIPFromPixel(rect.height));
38
- return rectMap;
39
- }
40
-
41
- static Map<String, Float> rectToJavaMap(Rect rect) {
42
- return MapBuilder.of(
43
- "x",
44
- PixelUtil.toDIPFromPixel(rect.x),
45
- "y",
46
- PixelUtil.toDIPFromPixel(rect.y),
47
- "width",
48
- PixelUtil.toDIPFromPixel(rect.width),
49
- "height",
50
- PixelUtil.toDIPFromPixel(rect.height));
51
- }
52
- }
@@ -1,16 +0,0 @@
1
- #import <UIKit/UIKit.h>
2
- #import <React/RCTDefines.h>
3
- #import <React/RCTView.h>
4
-
5
- RCT_EXTERN BOOL UIEdgeInsetsEqualToEdgeInsetsWithThreshold(UIEdgeInsets insets1, UIEdgeInsets insets2, CGFloat threshold);
6
-
7
- NS_ASSUME_NONNULL_BEGIN
8
-
9
- @interface UIView(SafeAreaCompat)
10
-
11
- - (BOOL)nativeSafeAreaSupport;
12
- - (UIEdgeInsets)safeAreaInsetsOrEmulate;
13
-
14
- @end
15
-
16
- NS_ASSUME_NONNULL_END
@@ -1,57 +0,0 @@
1
- #import "RCTView+SafeAreaCompat.h"
2
-
3
- #import <React/RCTUIManager.h>
4
-
5
- BOOL UIEdgeInsetsEqualToEdgeInsetsWithThreshold(UIEdgeInsets insets1, UIEdgeInsets insets2, CGFloat threshold)
6
- {
7
- return ABS(insets1.left - insets2.left) <= threshold &&
8
- ABS(insets1.right - insets2.right) <= threshold &&
9
- ABS(insets1.top - insets2.top) <= threshold &&
10
- ABS(insets1.bottom - insets2.bottom) <= threshold;
11
- }
12
-
13
- @implementation UIView(SafeAreaCompat)
14
-
15
- - (BOOL)nativeSafeAreaSupport
16
- {
17
- return [self respondsToSelector:@selector(safeAreaInsets)];
18
- }
19
-
20
- - (UIEdgeInsets)safeAreaInsetsOrEmulate
21
- {
22
- #if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 110000 /* __IPHONE_11_0 */
23
- if (self.nativeSafeAreaSupport) {
24
- if (@available(iOS 11.0, *)) {
25
- return self.safeAreaInsets;
26
- }
27
- }
28
- #endif
29
- return self.emulatedSafeAreaInsets;
30
- }
31
-
32
- - (UIEdgeInsets)emulatedSafeAreaInsets
33
- {
34
- UIViewController* vc = self.reactViewController;
35
-
36
- if (!vc) {
37
- return UIEdgeInsetsZero;
38
- }
39
-
40
- CGFloat topLayoutOffset = vc.topLayoutGuide.length;
41
- CGFloat bottomLayoutOffset = vc.bottomLayoutGuide.length;
42
- CGRect safeArea = vc.view.bounds;
43
- safeArea.origin.y += topLayoutOffset;
44
- safeArea.size.height -= topLayoutOffset + bottomLayoutOffset;
45
- CGRect localSafeArea = [vc.view convertRect:safeArea toView:self];
46
- UIEdgeInsets safeAreaInsets = UIEdgeInsetsMake(0, 0, 0, 0);
47
- if (CGRectGetMinY(localSafeArea) > CGRectGetMinY(self.bounds)) {
48
- safeAreaInsets.top = CGRectGetMinY(localSafeArea) - CGRectGetMinY(self.bounds);
49
- }
50
- if (CGRectGetMaxY(localSafeArea) < CGRectGetMaxY(self.bounds)) {
51
- safeAreaInsets.bottom = CGRectGetMaxY(self.bounds) - CGRectGetMaxY(localSafeArea);
52
- }
53
-
54
- return safeAreaInsets;
55
- }
56
-
57
- @end
@@ -1,13 +0,0 @@
1
- #import <UIKit/UIKit.h>
2
-
3
- #import <React/RCTView.h>
4
-
5
- NS_ASSUME_NONNULL_BEGIN
6
-
7
- @interface RNCSafeAreaProvider : RCTView
8
-
9
- @property (nonatomic, copy) RCTBubblingEventBlock onInsetsChange;
10
-
11
- @end
12
-
13
- NS_ASSUME_NONNULL_END
@@ -1,65 +0,0 @@
1
- #import "RNCSafeAreaProvider.h"
2
-
3
- #import <React/RCTBridge.h>
4
- #import <React/RCTUIManager.h>
5
- #import "RCTView+SafeAreaCompat.h"
6
-
7
- @implementation RNCSafeAreaProvider
8
- {
9
- UIEdgeInsets _currentSafeAreaInsets;
10
- CGRect _currentFrame;
11
- BOOL _initialInsetsSent;
12
- }
13
-
14
- - (void)safeAreaInsetsDidChange
15
- {
16
- [self invalidateSafeAreaInsets];
17
- }
18
-
19
- - (void)invalidateSafeAreaInsets
20
- {
21
- // This gets called before the view size is set by react-native so
22
- // make sure to wait so we don't set wrong insets to JS.
23
- if (CGSizeEqualToSize(self.frame.size, CGSizeZero)) {
24
- return;
25
- }
26
-
27
- UIEdgeInsets safeAreaInsets = [self safeAreaInsetsOrEmulate];
28
- CGRect frame = [self convertRect:self.bounds toView:nil];
29
-
30
- if (
31
- _initialInsetsSent &&
32
- UIEdgeInsetsEqualToEdgeInsetsWithThreshold(safeAreaInsets, _currentSafeAreaInsets, 1.0 / RCTScreenScale()) &&
33
- CGRectEqualToRect(frame, _currentFrame)
34
- ) {
35
- return;
36
- }
37
-
38
- _initialInsetsSent = YES;
39
- _currentSafeAreaInsets = safeAreaInsets;
40
- _currentFrame = frame;
41
-
42
- self.onInsetsChange(@{
43
- @"insets": @{
44
- @"top": @(safeAreaInsets.top),
45
- @"right": @(safeAreaInsets.right),
46
- @"bottom": @(safeAreaInsets.bottom),
47
- @"left": @(safeAreaInsets.left),
48
- },
49
- @"frame": @{
50
- @"x": @(frame.origin.x),
51
- @"y": @(frame.origin.y),
52
- @"width": @(frame.size.width),
53
- @"height": @(frame.size.height),
54
- },
55
- });
56
- }
57
-
58
- - (void)layoutSubviews
59
- {
60
- [super layoutSubviews];
61
-
62
- [self invalidateSafeAreaInsets];
63
- }
64
-
65
- @end
@@ -1,9 +0,0 @@
1
- #import <React/RCTViewManager.h>
2
-
3
- NS_ASSUME_NONNULL_BEGIN
4
-
5
- @interface RNCSafeAreaProviderManager : RCTViewManager
6
-
7
- @end
8
-
9
- NS_ASSUME_NONNULL_END
@@ -1,61 +0,0 @@
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
@@ -1,9 +0,0 @@
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
@@ -1,180 +0,0 @@
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
@@ -1,21 +0,0 @@
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