Skip to content

Commit 0f9fff8

Browse files
committed
Use SafeAreaContext optional dependency for View useSafeArea (#3937)
* infra: use SafeAreaContext optional dependency for View useSafeArea * refactor: revert rn safeAreaView naming
1 parent b107309 commit 0f9fff8

File tree

1 file changed

+7
-2
lines changed
  • packages/react-native-ui-lib/src/components/view

1 file changed

+7
-2
lines changed

packages/react-native-ui-lib/src/components/view/index.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {View as RNView, SafeAreaView, Animated, ViewProps as RNViewProps, type S
44
import type {AnimateProps as RNReanimatedProps} from 'react-native-reanimated';
55
import {Constants, ContainerModifiers} from '../../commons/new';
66
import type {RecorderProps} from '../../typings/recorderTypes';
7+
import {SafeAreaContextPackage} from '../../optionalDependencies';
78

89
/**
910
* Extra props when using reanimated (only non experimental props)
@@ -106,7 +107,12 @@ function View(props: ViewProps, ref: any) {
106107
}, []);
107108

108109
const ViewContainer = useMemo(() => {
109-
const container = useSafeArea && Constants.isIOS ? SafeAreaView : RNView;
110+
let container: React.ComponentType<any> = RNView;
111+
if (useSafeArea && SafeAreaContextPackage?.SafeAreaView) {
112+
container = SafeAreaContextPackage.SafeAreaView;
113+
} else if (useSafeArea && Constants.isIOS) {
114+
container = SafeAreaView;
115+
}
110116

111117
if (reanimated) {
112118
const {default: Reanimated}: typeof import('react-native-reanimated') = require('react-native-reanimated');
@@ -155,7 +161,6 @@ function View(props: ViewProps, ref: any) {
155161
}
156162

157163
return (
158-
//@ts-expect-error
159164
<ViewContainer
160165
accessibilityElementsHidden={inaccessible}
161166
importantForAccessibility={inaccessible ? 'no-hide-descendants' : undefined}

0 commit comments

Comments
 (0)