@amazon-devices/react-native-safe-area-context 2.0.1758683737 → 8.0.9000000000
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.
- package/README.md +6 -302
- package/SystemBundles/3e1c492419a85957481898df760cf9cf3bd38d3e26ef2e78822fb256fdee0153.bundle +7373 -0
- package/SystemBundles/3e1c492419a85957481898df760cf9cf3bd38d3e26ef2e78822fb256fdee0153.map +2780 -0
- package/SystemModules/amzn__react-native-safe-area-context-8.modules.txt +7 -0
- package/SystemModules/amzn__react-native-safe-area-context-8.private.modules.txt +61 -0
- package/SystemModules/keplerscript-system-bundle-config.json +3 -3
- package/android/build.gradle +103 -25
- package/android/gradle.properties +1 -0
- package/android/spotless.gradle +24 -0
- package/android/src/fabric/java/com/th3rdwave/safeareacontext/InsetsChangeEvent.kt +25 -0
- package/android/src/fabric/java/com/th3rdwave/safeareacontext/UIManagerHelperCompat.kt +14 -0
- package/android/src/main/AndroidManifest.xml +1 -2
- package/android/src/main/java/com/th3rdwave/safeareacontext/EdgeInsets.kt +3 -0
- package/android/src/main/java/com/th3rdwave/safeareacontext/Rect.kt +3 -0
- package/android/src/main/java/com/th3rdwave/safeareacontext/SafeAreaContextModule.kt +32 -0
- package/android/src/main/java/com/th3rdwave/safeareacontext/SafeAreaContextPackage.kt +41 -0
- package/android/src/main/java/com/th3rdwave/safeareacontext/SafeAreaProvider.kt +47 -0
- package/android/src/main/java/com/th3rdwave/safeareacontext/SafeAreaProviderManager.kt +41 -0
- package/android/src/main/java/com/th3rdwave/safeareacontext/SafeAreaUtils.kt +102 -0
- package/android/src/main/java/com/th3rdwave/safeareacontext/SafeAreaView.kt +155 -0
- package/android/src/main/java/com/th3rdwave/safeareacontext/SafeAreaViewEdges.kt +16 -0
- package/android/src/main/java/com/th3rdwave/safeareacontext/SafeAreaViewLocalData.kt +7 -0
- package/android/src/main/java/com/th3rdwave/safeareacontext/SafeAreaViewManager.kt +73 -0
- package/android/src/main/java/com/th3rdwave/safeareacontext/SafeAreaViewMode.kt +6 -0
- package/android/src/main/java/com/th3rdwave/safeareacontext/SafeAreaViewShadowNode.kt +170 -0
- package/android/src/main/java/com/th3rdwave/safeareacontext/SerializationUtils.kt +39 -0
- package/android/src/main/jni/CMakeLists.txt +87 -0
- package/android/src/main/jni/safeareacontext.h +17 -0
- package/android/src/paper/java/com/facebook/react/viewmanagers/RNCSafeAreaProviderManagerDelegate.java +31 -0
- package/android/src/paper/java/com/facebook/react/viewmanagers/RNCSafeAreaProviderManagerInterface.java +16 -0
- package/android/src/paper/java/com/facebook/react/viewmanagers/RNCSafeAreaViewManagerDelegate.java +41 -0
- package/android/src/paper/java/com/facebook/react/viewmanagers/RNCSafeAreaViewManagerInterface.java +20 -0
- package/android/src/paper/java/com/th3rdwave/safeareacontext/InsetsChangeEvent.kt +29 -0
- package/android/src/paper/java/com/th3rdwave/safeareacontext/NativeSafeAreaContextSpec.java +56 -0
- package/android/src/paper/java/com/th3rdwave/safeareacontext/UIManagerHelperCompat.kt +20 -0
- package/common/cpp/react/renderer/components/safeareacontext/RNCSafeAreaViewComponentDescriptor.h +25 -0
- package/common/cpp/react/renderer/components/safeareacontext/RNCSafeAreaViewShadowNode.cpp +131 -0
- package/common/cpp/react/renderer/components/safeareacontext/RNCSafeAreaViewShadowNode.h +36 -0
- package/common/cpp/react/renderer/components/safeareacontext/RNCSafeAreaViewState.cpp +23 -0
- package/common/cpp/react/renderer/components/safeareacontext/RNCSafeAreaViewState.h +56 -0
- package/ios/Fabric/RNCSafeAreaProviderComponentView.h +13 -0
- package/ios/Fabric/RNCSafeAreaProviderComponentView.mm +129 -0
- package/ios/Fabric/RNCSafeAreaViewComponentView.h +11 -0
- package/ios/Fabric/RNCSafeAreaViewComponentView.mm +153 -0
- package/ios/RNCSafeAreaContext.h +9 -0
- package/ios/RNCSafeAreaContext.mm +85 -0
- package/ios/{SafeAreaView/RNCSafeAreaProvider.h → RNCSafeAreaProvider.h} +4 -0
- package/ios/RNCSafeAreaProvider.m +102 -0
- package/ios/RNCSafeAreaProviderManager.m +20 -0
- package/ios/{SafeAreaView/RNCSafeAreaShadowView.m → RNCSafeAreaShadowView.m} +50 -36
- package/ios/RNCSafeAreaUtils.h +22 -0
- package/ios/RNCSafeAreaUtils.m +41 -0
- package/ios/{SafeAreaView/RNCSafeAreaView.h → RNCSafeAreaView.h} +8 -4
- package/ios/RNCSafeAreaView.m +168 -0
- package/ios/RNCSafeAreaViewEdgeMode.h +12 -0
- package/ios/RNCSafeAreaViewEdgeMode.m +16 -0
- package/ios/RNCSafeAreaViewEdges.h +15 -0
- package/ios/RNCSafeAreaViewEdges.m +36 -0
- package/ios/{SafeAreaView/RNCSafeAreaViewLocalData.h → RNCSafeAreaViewLocalData.h} +12 -1
- package/ios/{SafeAreaView/RNCSafeAreaViewLocalData.m → RNCSafeAreaViewLocalData.m} +4 -0
- package/ios/{SafeAreaView/RNCSafeAreaViewManager.m → RNCSafeAreaViewManager.m} +5 -1
- package/ios/RNCSafeAreaViewMode.m +15 -0
- package/ios/{SafeAreaView.xcodeproj → RNSafeAreaContext.xcodeproj}/project.pbxproj +70 -56
- package/jest/mock.tsx +59 -0
- package/kepler-compatibility.json +2 -4
- package/lib/commonjs/CompatNativeSafeAreaProvider.js +7 -8
- package/lib/commonjs/CompatNativeSafeAreaProvider.js.map +1 -1
- package/lib/commonjs/InitialWindow.js.map +1 -1
- package/lib/commonjs/InitialWindow.kepler.js +1 -1
- package/lib/commonjs/InitialWindow.kepler.js.map +1 -1
- package/lib/commonjs/InitialWindow.native.js +4 -4
- package/lib/commonjs/InitialWindow.native.js.map +1 -1
- package/lib/commonjs/NativeSafeAreaProvider.js +7 -125
- package/lib/commonjs/NativeSafeAreaProvider.js.map +1 -1
- package/lib/commonjs/NativeSafeAreaProvider.kepler.js +6 -2
- package/lib/commonjs/NativeSafeAreaProvider.kepler.js.map +1 -1
- package/lib/commonjs/NativeSafeAreaProvider.web.js +135 -0
- package/lib/commonjs/NativeSafeAreaProvider.web.js.map +1 -0
- package/lib/commonjs/NativeSafeAreaProvider.windows.js +6 -2
- package/lib/commonjs/NativeSafeAreaProvider.windows.js.map +1 -1
- package/lib/commonjs/SafeArea.types.js.map +1 -1
- package/lib/commonjs/SafeAreaContext.js +56 -36
- package/lib/commonjs/SafeAreaContext.js.map +1 -1
- package/lib/commonjs/SafeAreaView.js +40 -73
- package/lib/commonjs/SafeAreaView.js.map +1 -1
- package/lib/commonjs/SafeAreaView.kepler.js.map +1 -1
- package/lib/commonjs/SafeAreaView.web.js +91 -0
- package/lib/commonjs/SafeAreaView.web.js.map +1 -0
- package/lib/commonjs/SafeAreaView.windows.js.map +1 -1
- package/lib/commonjs/index.js +1 -0
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/package.json +1 -0
- package/lib/commonjs/specs/NativeSafeAreaContext.js +9 -0
- package/lib/commonjs/specs/NativeSafeAreaContext.js.map +1 -0
- package/lib/commonjs/specs/NativeSafeAreaProvider.js +10 -0
- package/lib/commonjs/specs/NativeSafeAreaProvider.js.map +1 -0
- package/lib/commonjs/specs/NativeSafeAreaView.js +12 -0
- package/lib/commonjs/specs/NativeSafeAreaView.js.map +1 -0
- package/lib/module/CompatNativeSafeAreaProvider.js +8 -5
- package/lib/module/CompatNativeSafeAreaProvider.js.map +1 -1
- package/lib/module/InitialWindow.js +2 -0
- package/lib/module/InitialWindow.js.map +1 -1
- package/lib/module/InitialWindow.kepler.js +3 -1
- package/lib/module/InitialWindow.kepler.js.map +1 -1
- package/lib/module/InitialWindow.native.js +5 -4
- package/lib/module/InitialWindow.native.js.map +1 -1
- package/lib/module/NativeSafeAreaProvider.js +3 -122
- package/lib/module/NativeSafeAreaProvider.js.map +1 -1
- package/lib/module/NativeSafeAreaProvider.kepler.js +3 -2
- package/lib/module/NativeSafeAreaProvider.kepler.js.map +1 -1
- package/lib/module/NativeSafeAreaProvider.web.js +130 -0
- package/lib/module/NativeSafeAreaProvider.web.js.map +1 -0
- package/lib/module/NativeSafeAreaProvider.windows.js +3 -2
- package/lib/module/NativeSafeAreaProvider.windows.js.map +1 -1
- package/lib/module/SafeArea.types.js +2 -0
- package/lib/module/SafeArea.types.js.map +1 -1
- package/lib/module/SafeAreaContext.js +57 -33
- package/lib/module/SafeAreaContext.js.map +1 -1
- package/lib/module/SafeAreaView.js +38 -69
- package/lib/module/SafeAreaView.js.map +1 -1
- package/lib/module/SafeAreaView.kepler.js +2 -0
- package/lib/module/SafeAreaView.kepler.js.map +1 -1
- package/lib/module/SafeAreaView.web.js +86 -0
- package/lib/module/SafeAreaView.web.js.map +1 -0
- package/lib/module/SafeAreaView.windows.js +2 -0
- package/lib/module/SafeAreaView.windows.js.map +1 -1
- package/lib/module/index.js +3 -0
- package/lib/module/index.js.map +1 -1
- package/lib/module/specs/NativeSafeAreaContext.js +5 -0
- package/lib/module/specs/NativeSafeAreaContext.js.map +1 -0
- package/lib/module/specs/NativeSafeAreaProvider.js +5 -0
- package/lib/module/specs/NativeSafeAreaProvider.js.map +1 -0
- package/lib/module/specs/NativeSafeAreaView.js +7 -0
- package/lib/module/specs/NativeSafeAreaView.js.map +1 -0
- package/lib/typescript/CompatNativeSafeAreaProvider.d.ts +4 -0
- package/lib/typescript/CompatNativeSafeAreaProvider.d.ts.map +1 -0
- package/lib/typescript/{src/InitialWindow.d.ts → InitialWindow.d.ts} +2 -1
- package/lib/typescript/InitialWindow.d.ts.map +1 -0
- package/lib/typescript/{src/InitialWindow.kepler.d.ts → InitialWindow.kepler.d.ts} +1 -0
- package/lib/typescript/InitialWindow.kepler.d.ts.map +1 -0
- package/lib/typescript/{src/InitialWindow.native.d.ts → InitialWindow.native.d.ts} +2 -1
- package/lib/typescript/InitialWindow.native.d.ts.map +1 -0
- package/lib/typescript/NativeSafeAreaProvider.d.ts +3 -0
- package/lib/typescript/NativeSafeAreaProvider.d.ts.map +1 -0
- package/lib/typescript/NativeSafeAreaProvider.kepler.d.ts +2 -0
- package/lib/typescript/NativeSafeAreaProvider.kepler.d.ts.map +1 -0
- package/lib/typescript/NativeSafeAreaProvider.web.d.ts +4 -0
- package/lib/typescript/NativeSafeAreaProvider.web.d.ts.map +1 -0
- package/lib/typescript/NativeSafeAreaProvider.windows.d.ts +2 -0
- package/lib/typescript/NativeSafeAreaProvider.windows.d.ts.map +1 -0
- package/lib/typescript/SafeArea.types.d.ts +36 -0
- package/lib/typescript/SafeArea.types.d.ts.map +1 -0
- package/lib/typescript/{src/SafeAreaContext.d.ts → SafeAreaContext.d.ts} +9 -6
- package/lib/typescript/SafeAreaContext.d.ts.map +1 -0
- package/lib/typescript/SafeAreaView.d.ts +5 -0
- package/lib/typescript/SafeAreaView.d.ts.map +1 -0
- package/lib/typescript/{src/SafeAreaView.kepler.d.ts → SafeAreaView.kepler.d.ts} +1 -0
- package/lib/typescript/SafeAreaView.kepler.d.ts.map +1 -0
- package/lib/typescript/SafeAreaView.web.d.ts +4 -0
- package/lib/typescript/SafeAreaView.web.d.ts.map +1 -0
- package/lib/typescript/SafeAreaView.windows.d.ts +3 -0
- package/lib/typescript/SafeAreaView.windows.d.ts.map +1 -0
- package/lib/typescript/{src/index.d.ts → index.d.ts} +1 -0
- package/lib/typescript/index.d.ts.map +1 -0
- package/lib/typescript/specs/NativeSafeAreaContext.d.ts +23 -0
- package/lib/typescript/specs/NativeSafeAreaContext.d.ts.map +1 -0
- package/lib/typescript/specs/NativeSafeAreaProvider.d.ts +22 -0
- package/lib/typescript/specs/NativeSafeAreaProvider.d.ts.map +1 -0
- package/lib/typescript/specs/NativeSafeAreaView.d.ts +14 -0
- package/lib/typescript/specs/NativeSafeAreaView.d.ts.map +1 -0
- package/package.json +1 -1
- package/react-native-safe-area-context.podspec +26 -4
- package/react-native.config.js +8 -0
- package/src/CompatNativeSafeAreaProvider.tsx +2 -3
- package/src/InitialWindow.kepler.ts +1 -1
- package/src/InitialWindow.native.ts +5 -11
- package/src/InitialWindow.ts +1 -1
- package/src/NativeSafeAreaProvider.kepler.tsx +1 -3
- package/src/NativeSafeAreaProvider.tsx +2 -128
- package/src/NativeSafeAreaProvider.web.tsx +127 -0
- package/src/NativeSafeAreaProvider.windows.tsx +1 -3
- package/src/SafeArea.types.ts +15 -11
- package/src/SafeAreaContext.tsx +66 -43
- package/src/SafeAreaView.tsx +47 -82
- package/src/SafeAreaView.web.tsx +123 -0
- package/src/SafeAreaView.windows.tsx +2 -1
- package/src/index.tsx +2 -0
- package/src/specs/NativeSafeAreaContext.ts +23 -0
- package/src/specs/NativeSafeAreaProvider.ts +29 -0
- package/src/specs/NativeSafeAreaView.ts +17 -0
- package/SystemBundles/e3c0cdeab56b8b622d4f0fd5a80812eafe199fa2287d0e3a09c5e573a1035350.bundle +0 -11031
- package/SystemBundles/e3c0cdeab56b8b622d4f0fd5a80812eafe199fa2287d0e3a09c5e573a1035350.map +0 -1
- package/SystemModules/amzn__react-native-safe-area-context-2.modules.txt +0 -55
- package/SystemModules/amzn__react-native-safe-area-context-2.private.modules.txt +0 -91
- package/THIRD_PARTY_NOTICES.txt +0 -24
- package/android/src/main/java/com/th3rdwave/safeareacontext/EdgeInsets.java +0 -22
- package/android/src/main/java/com/th3rdwave/safeareacontext/InsetsChangeEvent.java +0 -33
- package/android/src/main/java/com/th3rdwave/safeareacontext/Rect.java +0 -22
- package/android/src/main/java/com/th3rdwave/safeareacontext/SafeAreaContextPackage.java +0 -31
- package/android/src/main/java/com/th3rdwave/safeareacontext/SafeAreaProvider.java +0 -66
- package/android/src/main/java/com/th3rdwave/safeareacontext/SafeAreaProviderManager.java +0 -94
- package/android/src/main/java/com/th3rdwave/safeareacontext/SafeAreaUtils.java +0 -82
- package/android/src/main/java/com/th3rdwave/safeareacontext/SafeAreaView.java +0 -159
- package/android/src/main/java/com/th3rdwave/safeareacontext/SafeAreaViewEdges.java +0 -8
- package/android/src/main/java/com/th3rdwave/safeareacontext/SafeAreaViewLocalData.java +0 -27
- package/android/src/main/java/com/th3rdwave/safeareacontext/SafeAreaViewManager.java +0 -72
- package/android/src/main/java/com/th3rdwave/safeareacontext/SafeAreaViewMode.java +0 -6
- package/android/src/main/java/com/th3rdwave/safeareacontext/SafeAreaViewShadowNode.java +0 -201
- package/android/src/main/java/com/th3rdwave/safeareacontext/SerializationUtils.java +0 -52
- package/ios/SafeAreaView/RCTView+SafeAreaCompat.h +0 -16
- package/ios/SafeAreaView/RCTView+SafeAreaCompat.m +0 -57
- package/ios/SafeAreaView/RNCSafeAreaProvider.m +0 -65
- package/ios/SafeAreaView/RNCSafeAreaProviderManager.m +0 -61
- package/ios/SafeAreaView/RNCSafeAreaView.m +0 -118
- package/ios/SafeAreaView/RNCSafeAreaViewEdges.h +0 -9
- package/ios/SafeAreaView/RNCSafeAreaViewEdges.m +0 -13
- package/ios/SafeAreaView/RNCSafeAreaViewMode.m +0 -11
- package/lib/commonjs/NativeSafeAreaProvider.macos.js +0 -9
- package/lib/commonjs/NativeSafeAreaProvider.macos.js.map +0 -1
- package/lib/commonjs/NativeSafeAreaProvider.native.js +0 -9
- package/lib/commonjs/NativeSafeAreaProvider.native.js.map +0 -1
- package/lib/commonjs/SafeAreaView.macos.js +0 -9
- package/lib/commonjs/SafeAreaView.macos.js.map +0 -1
- package/lib/commonjs/SafeAreaView.native.js +0 -9
- package/lib/commonjs/SafeAreaView.native.js.map +0 -1
- package/lib/commonjs/useWindowDimensions.js +0 -32
- package/lib/commonjs/useWindowDimensions.js.map +0 -1
- package/lib/module/NativeSafeAreaProvider.macos.js +0 -3
- package/lib/module/NativeSafeAreaProvider.macos.js.map +0 -1
- package/lib/module/NativeSafeAreaProvider.native.js +0 -3
- package/lib/module/NativeSafeAreaProvider.native.js.map +0 -1
- package/lib/module/SafeAreaView.macos.js +0 -3
- package/lib/module/SafeAreaView.macos.js.map +0 -1
- package/lib/module/SafeAreaView.native.js +0 -3
- package/lib/module/SafeAreaView.native.js.map +0 -1
- package/lib/module/useWindowDimensions.js +0 -26
- package/lib/module/useWindowDimensions.js.map +0 -1
- package/lib/typescript/src/CompatNativeSafeAreaProvider.d.ts +0 -2
- package/lib/typescript/src/NativeSafeAreaProvider.d.ts +0 -2
- package/lib/typescript/src/NativeSafeAreaProvider.kepler.d.ts +0 -2
- package/lib/typescript/src/NativeSafeAreaProvider.macos.d.ts +0 -2
- package/lib/typescript/src/NativeSafeAreaProvider.native.d.ts +0 -3
- package/lib/typescript/src/NativeSafeAreaProvider.windows.d.ts +0 -2
- package/lib/typescript/src/SafeArea.types.d.ts +0 -31
- package/lib/typescript/src/SafeAreaView.d.ts +0 -2
- package/lib/typescript/src/SafeAreaView.macos.d.ts +0 -2
- package/lib/typescript/src/SafeAreaView.native.d.ts +0 -2
- package/lib/typescript/src/SafeAreaView.windows.d.ts +0 -2
- package/lib/typescript/src/useWindowDimensions.d.ts +0 -8
- package/src/NativeSafeAreaProvider.macos.tsx +0 -3
- package/src/NativeSafeAreaProvider.native.tsx +0 -6
- package/src/SafeAreaView.macos.tsx +0 -3
- package/src/SafeAreaView.native.tsx +0 -6
- package/src/useWindowDimensions.tsx +0 -35
- /package/ios/{SafeAreaView/RNCSafeAreaProviderManager.h → RNCSafeAreaProviderManager.h} +0 -0
- /package/ios/{SafeAreaView/RNCSafeAreaShadowView.h → RNCSafeAreaShadowView.h} +0 -0
- /package/ios/{SafeAreaView/RNCSafeAreaViewManager.h → RNCSafeAreaViewManager.h} +0 -0
- /package/ios/{SafeAreaView/RNCSafeAreaViewMode.h → RNCSafeAreaViewMode.h} +0 -0
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
@file:Suppress("DEPRECATION")
|
|
2
|
+
|
|
3
|
+
package com.th3rdwave.safeareacontext
|
|
4
|
+
|
|
5
|
+
import com.facebook.react.bridge.Arguments
|
|
6
|
+
import com.facebook.react.uimanager.events.Event
|
|
7
|
+
import com.facebook.react.uimanager.events.RCTEventEmitter
|
|
8
|
+
|
|
9
|
+
internal class InsetsChangeEvent(
|
|
10
|
+
@Suppress("UNUSED_PARAMETER") surfaceId: Int,
|
|
11
|
+
viewTag: Int,
|
|
12
|
+
private val mInsets: EdgeInsets,
|
|
13
|
+
private val mFrame: Rect
|
|
14
|
+
// New ctor is only available in RN 0.65.
|
|
15
|
+
) : Event<InsetsChangeEvent>(viewTag) {
|
|
16
|
+
override fun getEventName() = EVENT_NAME
|
|
17
|
+
|
|
18
|
+
// TODO: Migrate to getEventData when dropping support for RN 0.64.
|
|
19
|
+
override fun dispatch(rctEventEmitter: RCTEventEmitter) {
|
|
20
|
+
val event = Arguments.createMap()
|
|
21
|
+
event.putMap("insets", edgeInsetsToJsMap(mInsets))
|
|
22
|
+
event.putMap("frame", rectToJsMap(mFrame))
|
|
23
|
+
rctEventEmitter.receiveEvent(viewTag, eventName, event)
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
companion object {
|
|
27
|
+
const val EVENT_NAME = "topInsetsChange"
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This code was generated by
|
|
3
|
+
* [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
|
|
4
|
+
*
|
|
5
|
+
* <p>Do not edit this file as changes may cause incorrect behavior and will be lost once the code
|
|
6
|
+
* is regenerated.
|
|
7
|
+
*
|
|
8
|
+
* @generated by codegen project: GenerateModuleJavaSpec.js
|
|
9
|
+
* @nolint
|
|
10
|
+
*/
|
|
11
|
+
package com.th3rdwave.safeareacontext;
|
|
12
|
+
|
|
13
|
+
import com.facebook.proguard.annotations.DoNotStrip;
|
|
14
|
+
import com.facebook.react.bridge.ReactApplicationContext;
|
|
15
|
+
import com.facebook.react.bridge.ReactContextBaseJavaModule;
|
|
16
|
+
import com.facebook.react.bridge.ReactModuleWithSpec;
|
|
17
|
+
import com.facebook.react.common.build.ReactBuildConfig;
|
|
18
|
+
import com.facebook.react.turbomodule.core.interfaces.TurboModule;
|
|
19
|
+
import java.util.Arrays;
|
|
20
|
+
import java.util.HashSet;
|
|
21
|
+
import java.util.Map;
|
|
22
|
+
import java.util.Set;
|
|
23
|
+
import javax.annotation.Nullable;
|
|
24
|
+
|
|
25
|
+
public abstract class NativeSafeAreaContextSpec extends ReactContextBaseJavaModule
|
|
26
|
+
implements ReactModuleWithSpec, TurboModule {
|
|
27
|
+
public NativeSafeAreaContextSpec(ReactApplicationContext reactContext) {
|
|
28
|
+
super(reactContext);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
protected abstract Map<String, Object> getTypedExportedConstants();
|
|
32
|
+
|
|
33
|
+
@Override
|
|
34
|
+
@DoNotStrip
|
|
35
|
+
public final @Nullable Map<String, Object> getConstants() {
|
|
36
|
+
Map<String, Object> constants = getTypedExportedConstants();
|
|
37
|
+
if (ReactBuildConfig.DEBUG || ReactBuildConfig.IS_INTERNAL_BUILD) {
|
|
38
|
+
Set<String> obligatoryFlowConstants = new HashSet<>();
|
|
39
|
+
Set<String> optionalFlowConstants = new HashSet<>(Arrays.asList("initialWindowMetrics"));
|
|
40
|
+
Set<String> undeclaredConstants = new HashSet<>(constants.keySet());
|
|
41
|
+
undeclaredConstants.removeAll(obligatoryFlowConstants);
|
|
42
|
+
undeclaredConstants.removeAll(optionalFlowConstants);
|
|
43
|
+
if (!undeclaredConstants.isEmpty()) {
|
|
44
|
+
throw new IllegalStateException(
|
|
45
|
+
String.format("Native Module Flow doesn't declare constants: %s", undeclaredConstants));
|
|
46
|
+
}
|
|
47
|
+
undeclaredConstants = obligatoryFlowConstants;
|
|
48
|
+
undeclaredConstants.removeAll(constants.keySet());
|
|
49
|
+
if (!undeclaredConstants.isEmpty()) {
|
|
50
|
+
throw new IllegalStateException(
|
|
51
|
+
String.format("Native Module doesn't fill in constants: %s", undeclaredConstants));
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return constants;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
package com.th3rdwave.safeareacontext
|
|
2
|
+
|
|
3
|
+
import android.content.Context
|
|
4
|
+
import android.content.ContextWrapper
|
|
5
|
+
import android.view.View
|
|
6
|
+
import com.facebook.react.bridge.ReactContext
|
|
7
|
+
|
|
8
|
+
/** UIManagerHelper.getReactContext only exists in RN 0.63+ so vendor it here for a while. */
|
|
9
|
+
fun getReactContext(view: View): ReactContext {
|
|
10
|
+
var context = view.context
|
|
11
|
+
if (context !is ReactContext && context is ContextWrapper) {
|
|
12
|
+
context = context.baseContext
|
|
13
|
+
}
|
|
14
|
+
return context as ReactContext
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/** UIManagerHelper.getSurfaceId only exists in RN 0.65+, surface id is only needed for new arch. */
|
|
18
|
+
fun getSurfaceId(@Suppress("UNUSED_PARAMETER") context: Context): Int {
|
|
19
|
+
return -1
|
|
20
|
+
}
|
package/common/cpp/react/renderer/components/safeareacontext/RNCSafeAreaViewComponentDescriptor.h
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include <react/renderer/components/safeareacontext/RNCSafeAreaViewShadowNode.h>
|
|
4
|
+
#include <react/renderer/core/ConcreteComponentDescriptor.h>
|
|
5
|
+
|
|
6
|
+
namespace facebook {
|
|
7
|
+
namespace react {
|
|
8
|
+
|
|
9
|
+
/*
|
|
10
|
+
* Descriptor for <RNCSafeAreaView> component.
|
|
11
|
+
*/
|
|
12
|
+
class RNCSafeAreaViewComponentDescriptor final
|
|
13
|
+
: public ConcreteComponentDescriptor<RNCSafeAreaViewShadowNode> {
|
|
14
|
+
using ConcreteComponentDescriptor::ConcreteComponentDescriptor;
|
|
15
|
+
void adopt(ShadowNode &shadowNode) const override {
|
|
16
|
+
auto &concreteShadowNode =
|
|
17
|
+
static_cast<RNCSafeAreaViewShadowNode &>(shadowNode);
|
|
18
|
+
concreteShadowNode.adjustLayoutWithState();
|
|
19
|
+
|
|
20
|
+
ConcreteComponentDescriptor::adopt(shadowNode);
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
} // namespace react
|
|
25
|
+
} // namespace facebook
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
#include "RNCSafeAreaViewShadowNode.h"
|
|
2
|
+
|
|
3
|
+
#include <react/renderer/components/view/conversions.h>
|
|
4
|
+
#include <react/renderer/core/LayoutContext.h>
|
|
5
|
+
#include <yoga/Yoga.h>
|
|
6
|
+
#include <algorithm>
|
|
7
|
+
|
|
8
|
+
namespace facebook {
|
|
9
|
+
namespace react {
|
|
10
|
+
|
|
11
|
+
using namespace yoga;
|
|
12
|
+
|
|
13
|
+
extern const char RNCSafeAreaViewComponentName[] = "RNCSafeAreaView";
|
|
14
|
+
|
|
15
|
+
inline Style::Length valueFromEdges(
|
|
16
|
+
Style::Length edge,
|
|
17
|
+
Style::Length axis,
|
|
18
|
+
Style::Length defaultValue) {
|
|
19
|
+
if (edge.isDefined()) {
|
|
20
|
+
return edge;
|
|
21
|
+
}
|
|
22
|
+
if (axis.isDefined()) {
|
|
23
|
+
return axis;
|
|
24
|
+
}
|
|
25
|
+
return defaultValue;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
inline float
|
|
29
|
+
getEdgeValue(std::string edgeMode, float insetValue, float edgeValue) {
|
|
30
|
+
if (edgeMode == "off") {
|
|
31
|
+
return edgeValue;
|
|
32
|
+
} else if (edgeMode == "maximum") {
|
|
33
|
+
return fmax(insetValue, edgeValue);
|
|
34
|
+
} else {
|
|
35
|
+
return insetValue + edgeValue;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
void RNCSafeAreaViewShadowNode::adjustLayoutWithState() {
|
|
40
|
+
ensureUnsealed();
|
|
41
|
+
|
|
42
|
+
auto &props = getConcreteProps();
|
|
43
|
+
auto state =
|
|
44
|
+
std::static_pointer_cast<const RNCSafeAreaViewShadowNode::ConcreteState>(
|
|
45
|
+
getState());
|
|
46
|
+
auto stateData = state->getData();
|
|
47
|
+
auto edges = props.edges;
|
|
48
|
+
|
|
49
|
+
// Get the current values for padding / margin. The only caveat here is that
|
|
50
|
+
// percent values are not supported. Also might need to add support for start
|
|
51
|
+
// / end.
|
|
52
|
+
Style::Length top, left, right, bottom;
|
|
53
|
+
if (props.mode == RNCSafeAreaViewMode::Padding) {
|
|
54
|
+
auto defaultPadding = props.yogaStyle.padding(Edge::All);
|
|
55
|
+
top = valueFromEdges(
|
|
56
|
+
props.yogaStyle.padding(Edge::Top),
|
|
57
|
+
props.yogaStyle.padding(Edge::Vertical),
|
|
58
|
+
defaultPadding);
|
|
59
|
+
left = valueFromEdges(
|
|
60
|
+
props.yogaStyle.padding(Edge::Left),
|
|
61
|
+
props.yogaStyle.padding(Edge::Horizontal),
|
|
62
|
+
defaultPadding);
|
|
63
|
+
bottom = valueFromEdges(
|
|
64
|
+
props.yogaStyle.padding(Edge::Bottom),
|
|
65
|
+
props.yogaStyle.padding(Edge::Vertical),
|
|
66
|
+
defaultPadding);
|
|
67
|
+
right = valueFromEdges(
|
|
68
|
+
props.yogaStyle.padding(Edge::Right),
|
|
69
|
+
props.yogaStyle.padding(Edge::Horizontal),
|
|
70
|
+
defaultPadding);
|
|
71
|
+
} else {
|
|
72
|
+
auto defaultMargin = props.yogaStyle.margin(Edge::All);
|
|
73
|
+
top = valueFromEdges(
|
|
74
|
+
props.yogaStyle.margin(Edge::Top),
|
|
75
|
+
props.yogaStyle.margin(Edge::Vertical),
|
|
76
|
+
defaultMargin);
|
|
77
|
+
left = valueFromEdges(
|
|
78
|
+
props.yogaStyle.margin(Edge::Left),
|
|
79
|
+
props.yogaStyle.margin(Edge::Horizontal),
|
|
80
|
+
defaultMargin);
|
|
81
|
+
bottom = valueFromEdges(
|
|
82
|
+
props.yogaStyle.margin(Edge::Bottom),
|
|
83
|
+
props.yogaStyle.margin(Edge::Vertical),
|
|
84
|
+
defaultMargin);
|
|
85
|
+
right = valueFromEdges(
|
|
86
|
+
props.yogaStyle.margin(Edge::Right),
|
|
87
|
+
props.yogaStyle.margin(Edge::Horizontal),
|
|
88
|
+
defaultMargin);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
top = Style::Length::points(getEdgeValue(
|
|
92
|
+
edges.top, stateData.insets.top, top.value().unwrapOrDefault(0)));
|
|
93
|
+
left = Style::Length::points(getEdgeValue(
|
|
94
|
+
edges.left, stateData.insets.left, left.value().unwrapOrDefault(0)));
|
|
95
|
+
right = Style::Length::points(getEdgeValue(
|
|
96
|
+
edges.right, stateData.insets.right, right.value().unwrapOrDefault(0)));
|
|
97
|
+
bottom = Style::Length::points(getEdgeValue(
|
|
98
|
+
edges.bottom,
|
|
99
|
+
stateData.insets.bottom,
|
|
100
|
+
bottom.value().unwrapOrDefault(0)));
|
|
101
|
+
|
|
102
|
+
yoga::Style adjustedStyle = getConcreteProps().yogaStyle;
|
|
103
|
+
if (props.mode == RNCSafeAreaViewMode::Padding) {
|
|
104
|
+
adjustedStyle.setPadding(Edge::Top, top);
|
|
105
|
+
adjustedStyle.setPadding(Edge::Left, left);
|
|
106
|
+
adjustedStyle.setPadding(Edge::Right, right);
|
|
107
|
+
adjustedStyle.setPadding(Edge::Bottom, bottom);
|
|
108
|
+
} else {
|
|
109
|
+
adjustedStyle.setMargin(Edge::Top, top);
|
|
110
|
+
adjustedStyle.setMargin(Edge::Left, left);
|
|
111
|
+
adjustedStyle.setMargin(Edge::Right, right);
|
|
112
|
+
adjustedStyle.setMargin(Edge::Bottom, bottom);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
auto currentStyle = yogaNode_.style();
|
|
116
|
+
if (adjustedStyle.padding(Edge::Top) != currentStyle.padding(Edge::Top) ||
|
|
117
|
+
adjustedStyle.padding(Edge::Left) != currentStyle.padding(Edge::Left) ||
|
|
118
|
+
adjustedStyle.padding(Edge::Right) != currentStyle.padding(Edge::Right) ||
|
|
119
|
+
adjustedStyle.padding(Edge::Bottom) !=
|
|
120
|
+
currentStyle.padding(Edge::Bottom) ||
|
|
121
|
+
adjustedStyle.margin(Edge::Top) != currentStyle.margin(Edge::Top) ||
|
|
122
|
+
adjustedStyle.margin(Edge::Left) != currentStyle.margin(Edge::Left) ||
|
|
123
|
+
adjustedStyle.margin(Edge::Right) != currentStyle.margin(Edge::Right) ||
|
|
124
|
+
adjustedStyle.margin(Edge::Bottom) != currentStyle.margin(Edge::Bottom)) {
|
|
125
|
+
yogaNode_.setStyle(adjustedStyle);
|
|
126
|
+
yogaNode_.setDirty(true);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
} // namespace react
|
|
131
|
+
} // namespace facebook
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include <jsi/jsi.h>
|
|
4
|
+
#include <react/renderer/components/safeareacontext/EventEmitters.h>
|
|
5
|
+
#include <react/renderer/components/safeareacontext/Props.h>
|
|
6
|
+
#include <react/renderer/components/safeareacontext/RNCSafeAreaViewState.h>
|
|
7
|
+
#include <react/renderer/components/view/ConcreteViewShadowNode.h>
|
|
8
|
+
|
|
9
|
+
namespace facebook {
|
|
10
|
+
namespace react {
|
|
11
|
+
|
|
12
|
+
JSI_EXPORT extern const char RNCSafeAreaViewComponentName[];
|
|
13
|
+
|
|
14
|
+
/*
|
|
15
|
+
* `ShadowNode` for <RNCSafeAreaView> component.
|
|
16
|
+
*/
|
|
17
|
+
class JSI_EXPORT RNCSafeAreaViewShadowNode final
|
|
18
|
+
: public ConcreteViewShadowNode<
|
|
19
|
+
RNCSafeAreaViewComponentName,
|
|
20
|
+
RNCSafeAreaViewProps,
|
|
21
|
+
ViewEventEmitter,
|
|
22
|
+
RNCSafeAreaViewState> {
|
|
23
|
+
using ConcreteViewShadowNode::ConcreteViewShadowNode;
|
|
24
|
+
|
|
25
|
+
public:
|
|
26
|
+
static ShadowNodeTraits BaseTraits() {
|
|
27
|
+
auto traits = ConcreteViewShadowNode::BaseTraits();
|
|
28
|
+
traits.set(ShadowNodeTraits::Trait::DirtyYogaNode);
|
|
29
|
+
return traits;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
void adjustLayoutWithState();
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
} // namespace react
|
|
36
|
+
} // namespace facebook
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
#include "RNCSafeAreaViewState.h"
|
|
2
|
+
|
|
3
|
+
namespace facebook {
|
|
4
|
+
namespace react {
|
|
5
|
+
|
|
6
|
+
#ifdef ANDROID
|
|
7
|
+
|
|
8
|
+
folly::dynamic RNCSafeAreaViewState::getDynamic() const {
|
|
9
|
+
folly::dynamic insetsValue = folly::dynamic::object();
|
|
10
|
+
insetsValue["top"] = insets.top;
|
|
11
|
+
insetsValue["left"] = insets.left;
|
|
12
|
+
insetsValue["bottom"] = insets.bottom;
|
|
13
|
+
insetsValue["right"] = insets.right;
|
|
14
|
+
|
|
15
|
+
folly::dynamic data = folly::dynamic::object();
|
|
16
|
+
data["insets"] = insetsValue;
|
|
17
|
+
|
|
18
|
+
return data;
|
|
19
|
+
}
|
|
20
|
+
#endif
|
|
21
|
+
|
|
22
|
+
} // namespace react
|
|
23
|
+
} // namespace facebook
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include <react/renderer/components/safeareacontext/Props.h>
|
|
4
|
+
#include <react/renderer/graphics/RectangleEdges.h>
|
|
5
|
+
#include <vector>
|
|
6
|
+
|
|
7
|
+
#ifdef ANDROID
|
|
8
|
+
#include <folly/dynamic.h>
|
|
9
|
+
#include <react/renderer/mapbuffer/MapBuffer.h>
|
|
10
|
+
#include <react/renderer/mapbuffer/MapBufferBuilder.h>
|
|
11
|
+
#endif
|
|
12
|
+
|
|
13
|
+
namespace facebook {
|
|
14
|
+
namespace react {
|
|
15
|
+
|
|
16
|
+
#ifdef ANDROID
|
|
17
|
+
inline EdgeInsets edgeInsetsFromDynamic(const folly::dynamic &value) {
|
|
18
|
+
return EdgeInsets{
|
|
19
|
+
.left = (float)value["left"].getDouble(),
|
|
20
|
+
.top = (float)value["top"].getDouble(),
|
|
21
|
+
.right = (float)value["right"].getDouble(),
|
|
22
|
+
.bottom = (float)value["bottom"].getDouble(),
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
#endif
|
|
27
|
+
|
|
28
|
+
/*
|
|
29
|
+
* State for <RNCSafeAreaView> component.
|
|
30
|
+
*/
|
|
31
|
+
class JSI_EXPORT RNCSafeAreaViewState final {
|
|
32
|
+
public:
|
|
33
|
+
using Shared = std::shared_ptr<const RNCSafeAreaViewState>;
|
|
34
|
+
|
|
35
|
+
RNCSafeAreaViewState(){};
|
|
36
|
+
|
|
37
|
+
#ifdef ANDROID
|
|
38
|
+
RNCSafeAreaViewState(
|
|
39
|
+
RNCSafeAreaViewState const &previousState,
|
|
40
|
+
folly::dynamic data)
|
|
41
|
+
: insets(edgeInsetsFromDynamic(data["insets"])){};
|
|
42
|
+
#endif
|
|
43
|
+
|
|
44
|
+
EdgeInsets insets{};
|
|
45
|
+
|
|
46
|
+
#ifdef ANDROID
|
|
47
|
+
folly::dynamic getDynamic() const;
|
|
48
|
+
MapBuffer getMapBuffer() const {
|
|
49
|
+
return MapBufferBuilder::EMPTY();
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
#endif
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
} // namespace react
|
|
56
|
+
} // namespace facebook
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
#import "RNCSafeAreaProviderComponentView.h"
|
|
2
|
+
|
|
3
|
+
#import <react/renderer/components/safeareacontext/ComponentDescriptors.h>
|
|
4
|
+
#import <react/renderer/components/safeareacontext/EventEmitters.h>
|
|
5
|
+
#import <react/renderer/components/safeareacontext/Props.h>
|
|
6
|
+
#import <react/renderer/components/safeareacontext/RCTComponentViewHelpers.h>
|
|
7
|
+
|
|
8
|
+
#import <React/RCTFabricComponentsPlugins.h>
|
|
9
|
+
#import "RNCSafeAreaUtils.h"
|
|
10
|
+
|
|
11
|
+
using namespace facebook::react;
|
|
12
|
+
|
|
13
|
+
@interface RNCSafeAreaProviderComponentView () <RCTRNCSafeAreaProviderViewProtocol>
|
|
14
|
+
@end
|
|
15
|
+
|
|
16
|
+
@implementation RNCSafeAreaProviderComponentView {
|
|
17
|
+
UIEdgeInsets _currentSafeAreaInsets;
|
|
18
|
+
CGRect _currentFrame;
|
|
19
|
+
BOOL _initialInsetsSent;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// Needed because of this: https://github.com/facebook/react-native/pull/37274
|
|
23
|
+
+ (void)load
|
|
24
|
+
{
|
|
25
|
+
[super load];
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
- (instancetype)initWithFrame:(CGRect)frame
|
|
29
|
+
{
|
|
30
|
+
if (self = [super initWithFrame:frame]) {
|
|
31
|
+
static const auto defaultProps = std::make_shared<const RNCSafeAreaProviderProps>();
|
|
32
|
+
_props = defaultProps;
|
|
33
|
+
|
|
34
|
+
#if !TARGET_OS_TV
|
|
35
|
+
[NSNotificationCenter.defaultCenter addObserver:self
|
|
36
|
+
selector:@selector(invalidateSafeAreaInsets)
|
|
37
|
+
name:UIKeyboardDidShowNotification
|
|
38
|
+
object:nil];
|
|
39
|
+
[NSNotificationCenter.defaultCenter addObserver:self
|
|
40
|
+
selector:@selector(invalidateSafeAreaInsets)
|
|
41
|
+
name:UIKeyboardDidHideNotification
|
|
42
|
+
object:nil];
|
|
43
|
+
[NSNotificationCenter.defaultCenter addObserver:self
|
|
44
|
+
selector:@selector(invalidateSafeAreaInsets)
|
|
45
|
+
name:UIKeyboardDidChangeFrameNotification
|
|
46
|
+
object:nil];
|
|
47
|
+
#endif
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return self;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
- (void)safeAreaInsetsDidChange
|
|
54
|
+
{
|
|
55
|
+
[self invalidateSafeAreaInsets];
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
- (void)invalidateSafeAreaInsets
|
|
59
|
+
{
|
|
60
|
+
// This gets called before the view size is set by react-native so
|
|
61
|
+
// make sure to wait so we don't set wrong insets to JS.
|
|
62
|
+
if (CGSizeEqualToSize(self.frame.size, CGSizeZero)) {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
UIEdgeInsets safeAreaInsets = self.safeAreaInsets;
|
|
67
|
+
CGRect frame = [self convertRect:self.bounds toView:RNCParentViewController(self).view];
|
|
68
|
+
|
|
69
|
+
if (_initialInsetsSent &&
|
|
70
|
+
UIEdgeInsetsEqualToEdgeInsetsWithThreshold(safeAreaInsets, _currentSafeAreaInsets, 1.0 / RCTScreenScale()) &&
|
|
71
|
+
CGRectEqualToRect(frame, _currentFrame)) {
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
_initialInsetsSent = YES;
|
|
76
|
+
_currentSafeAreaInsets = safeAreaInsets;
|
|
77
|
+
_currentFrame = frame;
|
|
78
|
+
|
|
79
|
+
[NSNotificationCenter.defaultCenter postNotificationName:RNCSafeAreaDidChange object:self userInfo:nil];
|
|
80
|
+
|
|
81
|
+
if (_eventEmitter) {
|
|
82
|
+
RNCSafeAreaProviderEventEmitter::OnInsetsChange event = {
|
|
83
|
+
.insets =
|
|
84
|
+
{
|
|
85
|
+
.top = safeAreaInsets.top,
|
|
86
|
+
.left = safeAreaInsets.left,
|
|
87
|
+
.bottom = safeAreaInsets.bottom,
|
|
88
|
+
.right = safeAreaInsets.right,
|
|
89
|
+
},
|
|
90
|
+
.frame =
|
|
91
|
+
{
|
|
92
|
+
.x = frame.origin.x,
|
|
93
|
+
.y = frame.origin.y,
|
|
94
|
+
.width = frame.size.width,
|
|
95
|
+
.height = frame.size.height,
|
|
96
|
+
},
|
|
97
|
+
};
|
|
98
|
+
std::static_pointer_cast<RNCSafeAreaProviderEventEmitter const>(_eventEmitter)->onInsetsChange(event);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
- (void)layoutSubviews
|
|
103
|
+
{
|
|
104
|
+
[super layoutSubviews];
|
|
105
|
+
|
|
106
|
+
[self invalidateSafeAreaInsets];
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
#pragma mark - RCTComponentViewProtocol
|
|
110
|
+
|
|
111
|
+
+ (ComponentDescriptorProvider)componentDescriptorProvider
|
|
112
|
+
{
|
|
113
|
+
return concreteComponentDescriptorProvider<RNCSafeAreaProviderComponentDescriptor>();
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
- (void)prepareForRecycle
|
|
117
|
+
{
|
|
118
|
+
[super prepareForRecycle];
|
|
119
|
+
_currentSafeAreaInsets = UIEdgeInsetsZero;
|
|
120
|
+
_currentFrame = CGRectZero;
|
|
121
|
+
_initialInsetsSent = NO;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
@end
|
|
125
|
+
|
|
126
|
+
Class<RCTComponentViewProtocol> RNCSafeAreaProviderCls(void)
|
|
127
|
+
{
|
|
128
|
+
return RNCSafeAreaProviderComponentView.class;
|
|
129
|
+
}
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
#import "RNCSafeAreaViewComponentView.h"
|
|
2
|
+
|
|
3
|
+
#import <react/renderer/components/safeareacontext/EventEmitters.h>
|
|
4
|
+
#import <react/renderer/components/safeareacontext/Props.h>
|
|
5
|
+
#import <react/renderer/components/safeareacontext/RCTComponentViewHelpers.h>
|
|
6
|
+
#import <react/renderer/components/safeareacontext/RNCSafeAreaViewComponentDescriptor.h>
|
|
7
|
+
#import <react/renderer/components/safeareacontext/RNCSafeAreaViewShadowNode.h>
|
|
8
|
+
|
|
9
|
+
#import <React/RCTConversions.h>
|
|
10
|
+
#import <React/RCTFabricComponentsPlugins.h>
|
|
11
|
+
|
|
12
|
+
#import "RNCSafeAreaProviderComponentView.h"
|
|
13
|
+
#import "RNCSafeAreaUtils.h"
|
|
14
|
+
|
|
15
|
+
using namespace facebook::react;
|
|
16
|
+
|
|
17
|
+
@interface RNCSafeAreaViewComponentView () <RCTRNCSafeAreaViewViewProtocol>
|
|
18
|
+
@end
|
|
19
|
+
|
|
20
|
+
@implementation RNCSafeAreaViewComponentView {
|
|
21
|
+
RNCSafeAreaViewShadowNode::ConcreteState::Shared _state;
|
|
22
|
+
UIEdgeInsets _currentSafeAreaInsets;
|
|
23
|
+
__weak UIView *_Nullable _providerView;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// Needed because of this: https://github.com/facebook/react-native/pull/37274
|
|
27
|
+
+ (void)load
|
|
28
|
+
{
|
|
29
|
+
[super load];
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
- (instancetype)initWithFrame:(CGRect)frame
|
|
33
|
+
{
|
|
34
|
+
if (self = [super initWithFrame:frame]) {
|
|
35
|
+
static const auto defaultProps = std::make_shared<const RNCSafeAreaViewProps>();
|
|
36
|
+
_props = defaultProps;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return self;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
- (NSString *)description
|
|
43
|
+
{
|
|
44
|
+
NSString *superDescription = [super description];
|
|
45
|
+
|
|
46
|
+
// Cutting the last `>` character.
|
|
47
|
+
if (superDescription.length > 0 && [superDescription characterAtIndex:superDescription.length - 1] == '>') {
|
|
48
|
+
superDescription = [superDescription substringToIndex:superDescription.length - 1];
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return [NSString stringWithFormat:@"%@; RNCSafeAreaInsets = %@; appliedRNCSafeAreaInsets = %@>",
|
|
52
|
+
superDescription,
|
|
53
|
+
NSStringFromUIEdgeInsets(_providerView.safeAreaInsets),
|
|
54
|
+
NSStringFromUIEdgeInsets(_currentSafeAreaInsets)];
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
- (void)didMoveToWindow
|
|
58
|
+
{
|
|
59
|
+
UIView *previousProviderView = _providerView;
|
|
60
|
+
_providerView = [self findNearestProvider];
|
|
61
|
+
|
|
62
|
+
[self updateStateIfNecessary];
|
|
63
|
+
|
|
64
|
+
if (previousProviderView != _providerView) {
|
|
65
|
+
[NSNotificationCenter.defaultCenter removeObserver:self name:RNCSafeAreaDidChange object:previousProviderView];
|
|
66
|
+
[NSNotificationCenter.defaultCenter addObserver:self
|
|
67
|
+
selector:@selector(safeAreaProviderInsetsDidChange:)
|
|
68
|
+
name:RNCSafeAreaDidChange
|
|
69
|
+
object:_providerView];
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
- (void)safeAreaProviderInsetsDidChange:(NSNotification *)notification
|
|
74
|
+
{
|
|
75
|
+
[self updateStateIfNecessary];
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
- (void)updateStateIfNecessary
|
|
79
|
+
{
|
|
80
|
+
if (_providerView == nil) {
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
UIEdgeInsets safeAreaInsets = _providerView.safeAreaInsets;
|
|
84
|
+
|
|
85
|
+
if (UIEdgeInsetsEqualToEdgeInsetsWithThreshold(safeAreaInsets, _currentSafeAreaInsets, 1.0 / RCTScreenScale())) {
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
_currentSafeAreaInsets = safeAreaInsets;
|
|
90
|
+
[self updateState];
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
- (UIView *)findNearestProvider
|
|
94
|
+
{
|
|
95
|
+
UIView *current = self.superview;
|
|
96
|
+
while (current != nil) {
|
|
97
|
+
if ([current isKindOfClass:RNCSafeAreaProviderComponentView.class]) {
|
|
98
|
+
return current;
|
|
99
|
+
}
|
|
100
|
+
current = current.superview;
|
|
101
|
+
}
|
|
102
|
+
return self;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
- (void)updateState
|
|
106
|
+
{
|
|
107
|
+
if (!_state) {
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
_state->updateState(
|
|
112
|
+
[=](RNCSafeAreaViewShadowNode::ConcreteState::Data const &oldData)
|
|
113
|
+
-> RNCSafeAreaViewShadowNode::ConcreteState::SharedData {
|
|
114
|
+
auto newData = oldData;
|
|
115
|
+
newData.insets = RCTEdgeInsetsFromUIEdgeInsets(_currentSafeAreaInsets);
|
|
116
|
+
return std::make_shared<RNCSafeAreaViewShadowNode::ConcreteState::Data const>(newData);
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
#pragma mark - RCTComponentViewProtocol
|
|
121
|
+
|
|
122
|
+
+ (ComponentDescriptorProvider)componentDescriptorProvider
|
|
123
|
+
{
|
|
124
|
+
return concreteComponentDescriptorProvider<RNCSafeAreaViewComponentDescriptor>();
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
- (void)updateState:(State::Shared const &)state oldState:(State::Shared const &)oldState
|
|
128
|
+
{
|
|
129
|
+
_state = std::static_pointer_cast<RNCSafeAreaViewShadowNode::ConcreteState const>(state);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
- (void)finalizeUpdates:(RNComponentViewUpdateMask)updateMask
|
|
133
|
+
{
|
|
134
|
+
[super finalizeUpdates:updateMask];
|
|
135
|
+
[self updateStateIfNecessary];
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
- (void)prepareForRecycle
|
|
139
|
+
{
|
|
140
|
+
[super prepareForRecycle];
|
|
141
|
+
|
|
142
|
+
[NSNotificationCenter.defaultCenter removeObserver:self];
|
|
143
|
+
_state.reset();
|
|
144
|
+
_providerView = nil;
|
|
145
|
+
_currentSafeAreaInsets = UIEdgeInsetsZero;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
@end
|
|
149
|
+
|
|
150
|
+
Class<RCTComponentViewProtocol> RNCSafeAreaViewCls(void)
|
|
151
|
+
{
|
|
152
|
+
return RNCSafeAreaViewComponentView.class;
|
|
153
|
+
}
|