I'm getting a stragne error in TypeScript SafeAreaView component. I crated other refs for WebView and it doesn't fail, only seems to fail when assigned to the SafeAreaView component.
import { useRef, MutableRefObject } from 'react';
import { SafeAreaView } from 'react-native-safe-area-context';
...
...
const topSafeAreaViewRef = useRef(null);
...
...
<SafeAreaView ref={topSafeAreaViewRef} style={styles.container} edges={['top', 'right', 'left']} >
TS2322: Type '{ children: Element; ref: MutableRefObject; style: { flex: number; backgroundColor: any; }; edges: ("top" | "right" | "left")[]; }' is not assignable to type 'IntrinsicAttributes & ViewProps & { children?: ReactNode; mode?: "padding" | "margin" | undefined; edges?: readonly Edge[] | undefined; }'. Property 'ref' does not exist on type 'IntrinsicAttributes & ViewProps & { children?: ReactNode; mode?: "padding" | "margin" | undefined; edges?: readonly Edge[] | undefined; }'.
I need ref because I need to set setNativeProps on an external function
const handleOnLoadEnd = (
syntheticEvent: WebViewNavigationEvent | WebViewErrorEvent,
topSafeAreaViewRef: MutableRefObject<any>,
) => {
topSafeAreaViewRef.current.setNativeProps({
style:{
backgroundColor: Constants?.manifest?.extra?.webViewBackground,
}
});
};
SafeAreaView is the preferred way to consume insets. This is a regular
Viewwith insets applied as extra padding or margin. It offers better performance by applying insets natively and avoids flickers that can happen with the other JS based consumers.SafeAreaView is a regular View component with the safe area insets applied as padding or margin.
Padding or margin styles are added to the insets, for example
style={{paddingTop: 10}}on a SafeAreaView that has insets of 20 will result in a top padding of 30.Example:
Edges:
Optional, array of top, right, bottom, and left. Defaults to all.
Sets the edges to apply the safe area insets to.
For example if you don't want insets to apply to the top edge because the view does not touch the top of the screen you can use:
For further Details or Documentation you can check Here
You should remove
useRef()because useRef is not Sported in SafeAreaView.