forked from Expensify/App
-
Notifications
You must be signed in to change notification settings - Fork 0
/
react-native-safe-area-context.js
52 lines (44 loc) · 1.37 KB
/
react-native-safe-area-context.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import React, {forwardRef} from 'react';
import {View} from 'react-native';
const insets = {
top: 0,
right: 0,
bottom: 0,
left: 0,
};
function withSafeAreaInsets(WrappedComponent) {
function WithSafeAreaInsets(props) {
return (
<WrappedComponent
// eslint-disable-next-line react/jsx-props-no-spreading
{...props}
// eslint-disable-next-line react/prop-types
ref={props.forwardedRef}
insets={insets}
/>
);
}
const WithSafeAreaInsetsWithRef = forwardRef((props, ref) => (
<WithSafeAreaInsets
// eslint-disable-next-line react/jsx-props-no-spreading
{...props}
forwardedRef={ref}
/>
));
WithSafeAreaInsetsWithRef.displayName = 'WithSafeAreaInsetsWithRef';
return WithSafeAreaInsetsWithRef;
}
const SafeAreaView = View;
const SafeAreaProvider = (props) => props.children;
const SafeAreaConsumer = (props) => props.children(insets);
const SafeAreaInsetsContext = {
Consumer: SafeAreaConsumer,
};
const useSafeAreaFrame = jest.fn(() => ({
x: 0,
y: 0,
width: 390,
height: 844,
}));
const useSafeAreaInsets = jest.fn(() => insets);
export {SafeAreaProvider, SafeAreaConsumer, SafeAreaInsetsContext, withSafeAreaInsets, SafeAreaView, useSafeAreaFrame, useSafeAreaInsets};