@amazon-devices/react-native-safe-area-context 8.0.9000000000 → 8.0.9000000002
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/SystemModules/amzn__react-native-safe-area-context-8.private.modules.txt +35 -29
- package/kepler-compatibility.json +4 -2
- package/lib/commonjs/index.js +0 -50
- package/oss-attribution/attribution.txt +0 -0
- package/oss-attribution/licenseInfos.json +1 -0
- package/package.json +1 -1
- package/src/index.tsx +0 -5
- package/SystemBundles/3e1c492419a85957481898df760cf9cf3bd38d3e26ef2e78822fb256fdee0153.bundle +0 -7373
- package/SystemBundles/3e1c492419a85957481898df760cf9cf3bd38d3e26ef2e78822fb256fdee0153.map +0 -2780
- package/jest/mock.tsx +0 -59
- package/lib/commonjs/CompatNativeSafeAreaProvider.js +0 -43
- package/lib/commonjs/InitialWindow.js +0 -13
- package/lib/commonjs/InitialWindow.kepler.js +0 -15
- package/lib/commonjs/InitialWindow.native.js +0 -15
- package/lib/commonjs/NativeSafeAreaProvider.js +0 -14
- package/lib/commonjs/NativeSafeAreaProvider.kepler.js +0 -13
- package/lib/commonjs/NativeSafeAreaProvider.web.js +0 -135
- package/lib/commonjs/NativeSafeAreaProvider.windows.js +0 -13
- package/lib/commonjs/SafeArea.types.js +0 -6
- package/lib/commonjs/SafeAreaContext.js +0 -133
- package/lib/commonjs/SafeAreaView.js +0 -49
- package/lib/commonjs/SafeAreaView.kepler.js +0 -9
- package/lib/commonjs/SafeAreaView.web.js +0 -91
- package/lib/commonjs/SafeAreaView.windows.js +0 -9
- package/lib/commonjs/specs/NativeSafeAreaContext.js +0 -9
- package/lib/commonjs/specs/NativeSafeAreaProvider.js +0 -10
- package/lib/commonjs/specs/NativeSafeAreaView.js +0 -12
- package/lib/module/CompatNativeSafeAreaProvider.js +0 -38
- package/lib/module/InitialWindow.js +0 -9
- package/lib/module/InitialWindow.kepler.js +0 -11
- package/lib/module/InitialWindow.native.js +0 -10
- package/lib/module/NativeSafeAreaProvider.js +0 -5
- package/lib/module/NativeSafeAreaProvider.kepler.js +0 -4
- package/lib/module/NativeSafeAreaProvider.web.js +0 -130
- package/lib/module/NativeSafeAreaProvider.windows.js +0 -4
- package/lib/module/SafeArea.types.js +0 -4
- package/lib/module/SafeAreaContext.js +0 -123
- package/lib/module/SafeAreaView.js +0 -43
- package/lib/module/SafeAreaView.kepler.js +0 -5
- package/lib/module/SafeAreaView.web.js +0 -86
- package/lib/module/SafeAreaView.windows.js +0 -5
- package/lib/module/index.js +0 -8
- package/lib/module/specs/NativeSafeAreaContext.js +0 -5
- package/lib/module/specs/NativeSafeAreaProvider.js +0 -5
- package/lib/module/specs/NativeSafeAreaView.js +0 -7
- package/src/CompatNativeSafeAreaProvider.tsx +0 -28
- package/src/InitialWindow.kepler.ts +0 -10
- package/src/InitialWindow.native.ts +0 -10
- package/src/InitialWindow.ts +0 -8
- package/src/NativeSafeAreaProvider.kepler.tsx +0 -1
- package/src/NativeSafeAreaProvider.tsx +0 -3
- package/src/NativeSafeAreaProvider.web.tsx +0 -127
- package/src/NativeSafeAreaProvider.windows.tsx +0 -1
- package/src/SafeArea.types.ts +0 -47
- package/src/SafeAreaContext.tsx +0 -171
- package/src/SafeAreaView.kepler.tsx +0 -3
- package/src/SafeAreaView.tsx +0 -50
- package/src/SafeAreaView.web.tsx +0 -123
- package/src/SafeAreaView.windows.tsx +0 -4
- package/src/specs/NativeSafeAreaContext.ts +0 -23
- package/src/specs/NativeSafeAreaProvider.ts +0 -29
- package/src/specs/NativeSafeAreaView.ts +0 -17
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
/* eslint-env browser */
|
|
2
|
-
|
|
3
|
-
import * as React from 'react';
|
|
4
|
-
import { View } from 'react-native';
|
|
5
|
-
import type { NativeSafeAreaProviderProps } from './SafeArea.types';
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* TODO:
|
|
9
|
-
* Currently insets and frame are based on the window and are not
|
|
10
|
-
* relative to the provider view. This is inconsistent with iOS and Android.
|
|
11
|
-
* However in most cases if the provider view covers the screen this is not
|
|
12
|
-
* an issue.
|
|
13
|
-
*/
|
|
14
|
-
|
|
15
|
-
const CSSTransitions: Record<string, string> = {
|
|
16
|
-
WebkitTransition: 'webkitTransitionEnd',
|
|
17
|
-
Transition: 'transitionEnd',
|
|
18
|
-
MozTransition: 'transitionend',
|
|
19
|
-
MSTransition: 'msTransitionEnd',
|
|
20
|
-
OTransition: 'oTransitionEnd',
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
export function NativeSafeAreaProvider({
|
|
24
|
-
children,
|
|
25
|
-
style,
|
|
26
|
-
onInsetsChange,
|
|
27
|
-
}: NativeSafeAreaProviderProps) {
|
|
28
|
-
React.useEffect(() => {
|
|
29
|
-
// Skip for SSR.
|
|
30
|
-
if (typeof document === 'undefined') {
|
|
31
|
-
return;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
const element = createContextElement();
|
|
35
|
-
document.body.appendChild(element);
|
|
36
|
-
const onEnd = () => {
|
|
37
|
-
const { paddingTop, paddingBottom, paddingLeft, paddingRight } =
|
|
38
|
-
window.getComputedStyle(element);
|
|
39
|
-
|
|
40
|
-
const insets = {
|
|
41
|
-
top: paddingTop ? parseInt(paddingTop, 10) : 0,
|
|
42
|
-
bottom: paddingBottom ? parseInt(paddingBottom, 10) : 0,
|
|
43
|
-
left: paddingLeft ? parseInt(paddingLeft, 10) : 0,
|
|
44
|
-
right: paddingRight ? parseInt(paddingRight, 10) : 0,
|
|
45
|
-
};
|
|
46
|
-
const frame = {
|
|
47
|
-
x: 0,
|
|
48
|
-
y: 0,
|
|
49
|
-
width: document.documentElement.offsetWidth,
|
|
50
|
-
height: document.documentElement.offsetHeight,
|
|
51
|
-
};
|
|
52
|
-
// @ts-ignore: missing properties
|
|
53
|
-
onInsetsChange({ nativeEvent: { insets, frame } });
|
|
54
|
-
};
|
|
55
|
-
element.addEventListener(getSupportedTransitionEvent(), onEnd);
|
|
56
|
-
onEnd();
|
|
57
|
-
return () => {
|
|
58
|
-
document.body.removeChild(element);
|
|
59
|
-
element.removeEventListener(getSupportedTransitionEvent(), onEnd);
|
|
60
|
-
};
|
|
61
|
-
}, [onInsetsChange]);
|
|
62
|
-
|
|
63
|
-
return <View style={style}>{children}</View>;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
let _supportedTransitionEvent: string | null | undefined = null;
|
|
67
|
-
function getSupportedTransitionEvent(): string {
|
|
68
|
-
if (_supportedTransitionEvent != null) {
|
|
69
|
-
return _supportedTransitionEvent;
|
|
70
|
-
}
|
|
71
|
-
const element = document.createElement('invalidtype');
|
|
72
|
-
|
|
73
|
-
_supportedTransitionEvent = CSSTransitions.Transition;
|
|
74
|
-
for (const key in CSSTransitions) {
|
|
75
|
-
if (element.style[key as keyof CSSStyleDeclaration] !== undefined) {
|
|
76
|
-
_supportedTransitionEvent = CSSTransitions[key];
|
|
77
|
-
break;
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
return _supportedTransitionEvent as string;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
type CssEnv = 'constant' | 'env';
|
|
84
|
-
|
|
85
|
-
let _supportedEnv: CssEnv | null = null;
|
|
86
|
-
function getSupportedEnv(): CssEnv {
|
|
87
|
-
if (_supportedEnv !== null) {
|
|
88
|
-
return _supportedEnv;
|
|
89
|
-
}
|
|
90
|
-
const { CSS } = window;
|
|
91
|
-
if (
|
|
92
|
-
CSS &&
|
|
93
|
-
CSS.supports &&
|
|
94
|
-
CSS.supports('top: constant(safe-area-inset-top)')
|
|
95
|
-
) {
|
|
96
|
-
_supportedEnv = 'constant';
|
|
97
|
-
} else {
|
|
98
|
-
_supportedEnv = 'env';
|
|
99
|
-
}
|
|
100
|
-
return _supportedEnv;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
function getInset(side: string): string {
|
|
104
|
-
return `${getSupportedEnv()}(safe-area-inset-${side})`;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
function createContextElement(): HTMLElement {
|
|
108
|
-
const element = document.createElement('div');
|
|
109
|
-
const { style } = element;
|
|
110
|
-
style.position = 'fixed';
|
|
111
|
-
style.left = '0';
|
|
112
|
-
style.top = '0';
|
|
113
|
-
style.width = '0';
|
|
114
|
-
style.height = '0';
|
|
115
|
-
style.zIndex = '-1';
|
|
116
|
-
style.overflow = 'hidden';
|
|
117
|
-
style.visibility = 'hidden';
|
|
118
|
-
// Bacon: Anything faster than this and the callback will be invoked too early with the wrong insets
|
|
119
|
-
style.transitionDuration = '0.05s';
|
|
120
|
-
style.transitionProperty = 'padding';
|
|
121
|
-
style.transitionDelay = '0s';
|
|
122
|
-
style.paddingTop = getInset('top');
|
|
123
|
-
style.paddingBottom = getInset('bottom');
|
|
124
|
-
style.paddingLeft = getInset('left');
|
|
125
|
-
style.paddingRight = getInset('right');
|
|
126
|
-
return element;
|
|
127
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { CompatNativeSafeAreaProvider as NativeSafeAreaProvider } from './CompatNativeSafeAreaProvider';
|
package/src/SafeArea.types.ts
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import type * as React from 'react';
|
|
2
|
-
import type { NativeSyntheticEvent, ViewProps } from 'react-native';
|
|
3
|
-
import NativeSafeAreaView from './specs/NativeSafeAreaView';
|
|
4
|
-
|
|
5
|
-
export type Edge = 'top' | 'right' | 'bottom' | 'left';
|
|
6
|
-
export type EdgeMode = 'off' | 'additive' | 'maximum';
|
|
7
|
-
|
|
8
|
-
export type EdgeRecord = Partial<Record<Edge, EdgeMode>>;
|
|
9
|
-
export type Edges = readonly Edge[] | Readonly<EdgeRecord>;
|
|
10
|
-
|
|
11
|
-
export interface EdgeInsets {
|
|
12
|
-
top: number;
|
|
13
|
-
right: number;
|
|
14
|
-
bottom: number;
|
|
15
|
-
left: number;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export interface Rect {
|
|
19
|
-
x: number;
|
|
20
|
-
y: number;
|
|
21
|
-
width: number;
|
|
22
|
-
height: number;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export interface Metrics {
|
|
26
|
-
insets: EdgeInsets;
|
|
27
|
-
frame: Rect;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export type InsetChangedEvent = NativeSyntheticEvent<Metrics>;
|
|
31
|
-
|
|
32
|
-
export type InsetChangeNativeCallback = (event: InsetChangedEvent) => void;
|
|
33
|
-
|
|
34
|
-
export interface NativeSafeAreaProviderProps extends ViewProps {
|
|
35
|
-
children?: React.ReactNode;
|
|
36
|
-
onInsetsChange: InsetChangeNativeCallback;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
export interface NativeSafeAreaViewProps extends ViewProps {
|
|
40
|
-
children?: React.ReactNode;
|
|
41
|
-
mode?: 'padding' | 'margin';
|
|
42
|
-
edges?: Edges;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
export type NativeSafeAreaViewInstance = InstanceType<
|
|
46
|
-
typeof NativeSafeAreaView
|
|
47
|
-
>;
|
package/src/SafeAreaContext.tsx
DELETED
|
@@ -1,171 +0,0 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
2
|
-
import { Dimensions, StyleSheet, type ViewProps } from 'react-native';
|
|
3
|
-
import { NativeSafeAreaProvider } from './NativeSafeAreaProvider';
|
|
4
|
-
import type {
|
|
5
|
-
EdgeInsets,
|
|
6
|
-
InsetChangedEvent,
|
|
7
|
-
Metrics,
|
|
8
|
-
Rect,
|
|
9
|
-
} from './SafeArea.types';
|
|
10
|
-
|
|
11
|
-
const isDev = process.env.NODE_ENV !== 'production';
|
|
12
|
-
|
|
13
|
-
export const SafeAreaInsetsContext = React.createContext<EdgeInsets | null>(
|
|
14
|
-
null,
|
|
15
|
-
);
|
|
16
|
-
if (isDev) {
|
|
17
|
-
SafeAreaInsetsContext.displayName = 'SafeAreaInsetsContext';
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export const SafeAreaFrameContext = React.createContext<Rect | null>(null);
|
|
21
|
-
if (isDev) {
|
|
22
|
-
SafeAreaFrameContext.displayName = 'SafeAreaFrameContext';
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export interface SafeAreaProviderProps extends ViewProps {
|
|
26
|
-
children?: React.ReactNode;
|
|
27
|
-
initialMetrics?: Metrics | null;
|
|
28
|
-
/**
|
|
29
|
-
* @deprecated
|
|
30
|
-
*/
|
|
31
|
-
initialSafeAreaInsets?: EdgeInsets | null;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export function SafeAreaProvider({
|
|
35
|
-
children,
|
|
36
|
-
initialMetrics,
|
|
37
|
-
initialSafeAreaInsets,
|
|
38
|
-
style,
|
|
39
|
-
...others
|
|
40
|
-
}: SafeAreaProviderProps) {
|
|
41
|
-
const parentInsets = useParentSafeAreaInsets();
|
|
42
|
-
const parentFrame = useParentSafeAreaFrame();
|
|
43
|
-
const [insets, setInsets] = React.useState<EdgeInsets | null>(
|
|
44
|
-
initialMetrics?.insets ?? initialSafeAreaInsets ?? parentInsets ?? null,
|
|
45
|
-
);
|
|
46
|
-
const [frame, setFrame] = React.useState<Rect>(
|
|
47
|
-
initialMetrics?.frame ??
|
|
48
|
-
parentFrame ?? {
|
|
49
|
-
// Backwards compat so we render anyway if we don't have frame.
|
|
50
|
-
x: 0,
|
|
51
|
-
y: 0,
|
|
52
|
-
width: Dimensions.get('window').width,
|
|
53
|
-
height: Dimensions.get('window').height,
|
|
54
|
-
},
|
|
55
|
-
);
|
|
56
|
-
const onInsetsChange = React.useCallback((event: InsetChangedEvent) => {
|
|
57
|
-
const {
|
|
58
|
-
nativeEvent: { frame: nextFrame, insets: nextInsets },
|
|
59
|
-
} = event;
|
|
60
|
-
|
|
61
|
-
setFrame((curFrame) => {
|
|
62
|
-
if (
|
|
63
|
-
// Backwards compat with old native code that won't send frame.
|
|
64
|
-
nextFrame &&
|
|
65
|
-
(nextFrame.height !== curFrame.height ||
|
|
66
|
-
nextFrame.width !== curFrame.width ||
|
|
67
|
-
nextFrame.x !== curFrame.x ||
|
|
68
|
-
nextFrame.y !== curFrame.y)
|
|
69
|
-
) {
|
|
70
|
-
return nextFrame;
|
|
71
|
-
} else {
|
|
72
|
-
return curFrame;
|
|
73
|
-
}
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
setInsets((curInsets) => {
|
|
77
|
-
if (
|
|
78
|
-
!curInsets ||
|
|
79
|
-
nextInsets.bottom !== curInsets.bottom ||
|
|
80
|
-
nextInsets.left !== curInsets.left ||
|
|
81
|
-
nextInsets.right !== curInsets.right ||
|
|
82
|
-
nextInsets.top !== curInsets.top
|
|
83
|
-
) {
|
|
84
|
-
return nextInsets;
|
|
85
|
-
} else {
|
|
86
|
-
return curInsets;
|
|
87
|
-
}
|
|
88
|
-
});
|
|
89
|
-
}, []);
|
|
90
|
-
|
|
91
|
-
return (
|
|
92
|
-
<NativeSafeAreaProvider
|
|
93
|
-
style={[styles.fill, style]}
|
|
94
|
-
onInsetsChange={onInsetsChange}
|
|
95
|
-
{...others}
|
|
96
|
-
>
|
|
97
|
-
{insets != null ? (
|
|
98
|
-
<SafeAreaFrameContext.Provider value={frame}>
|
|
99
|
-
<SafeAreaInsetsContext.Provider value={insets}>
|
|
100
|
-
{children}
|
|
101
|
-
</SafeAreaInsetsContext.Provider>
|
|
102
|
-
</SafeAreaFrameContext.Provider>
|
|
103
|
-
) : null}
|
|
104
|
-
</NativeSafeAreaProvider>
|
|
105
|
-
);
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
const styles = StyleSheet.create({
|
|
109
|
-
fill: { flex: 1 },
|
|
110
|
-
});
|
|
111
|
-
|
|
112
|
-
function useParentSafeAreaInsets(): EdgeInsets | null {
|
|
113
|
-
return React.useContext(SafeAreaInsetsContext);
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
function useParentSafeAreaFrame(): Rect | null {
|
|
117
|
-
return React.useContext(SafeAreaFrameContext);
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
const NO_INSETS_ERROR =
|
|
121
|
-
'No safe area value available. Make sure you are rendering `<SafeAreaProvider>` at the top of your app.';
|
|
122
|
-
|
|
123
|
-
export function useSafeAreaInsets(): EdgeInsets {
|
|
124
|
-
const insets = React.useContext(SafeAreaInsetsContext);
|
|
125
|
-
if (insets == null) {
|
|
126
|
-
throw new Error(NO_INSETS_ERROR);
|
|
127
|
-
}
|
|
128
|
-
return insets;
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
export function useSafeAreaFrame(): Rect {
|
|
132
|
-
const frame = React.useContext(SafeAreaFrameContext);
|
|
133
|
-
if (frame == null) {
|
|
134
|
-
throw new Error(NO_INSETS_ERROR);
|
|
135
|
-
}
|
|
136
|
-
return frame;
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
export type WithSafeAreaInsetsProps = {
|
|
140
|
-
insets: EdgeInsets;
|
|
141
|
-
};
|
|
142
|
-
|
|
143
|
-
export function withSafeAreaInsets<T>(
|
|
144
|
-
WrappedComponent: React.ComponentType<
|
|
145
|
-
(React.PropsWithoutRef<T> | T) & WithSafeAreaInsetsProps
|
|
146
|
-
>,
|
|
147
|
-
): React.ForwardRefExoticComponent<
|
|
148
|
-
React.PropsWithoutRef<T> & React.RefAttributes<unknown>
|
|
149
|
-
> {
|
|
150
|
-
return React.forwardRef<unknown, T>((props, ref) => {
|
|
151
|
-
const insets = useSafeAreaInsets();
|
|
152
|
-
return <WrappedComponent {...props} insets={insets} ref={ref} />;
|
|
153
|
-
});
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
/**
|
|
157
|
-
* @deprecated
|
|
158
|
-
*/
|
|
159
|
-
export function useSafeArea(): EdgeInsets {
|
|
160
|
-
return useSafeAreaInsets();
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
/**
|
|
164
|
-
* @deprecated
|
|
165
|
-
*/
|
|
166
|
-
export const SafeAreaConsumer = SafeAreaInsetsContext.Consumer;
|
|
167
|
-
|
|
168
|
-
/**
|
|
169
|
-
* @deprecated
|
|
170
|
-
*/
|
|
171
|
-
export const SafeAreaContext = SafeAreaInsetsContext;
|
package/src/SafeAreaView.tsx
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
2
|
-
import type {
|
|
3
|
-
Edge,
|
|
4
|
-
EdgeMode,
|
|
5
|
-
EdgeRecord,
|
|
6
|
-
NativeSafeAreaViewInstance,
|
|
7
|
-
NativeSafeAreaViewProps,
|
|
8
|
-
} from './SafeArea.types';
|
|
9
|
-
import NativeSafeAreaView from './specs/NativeSafeAreaView';
|
|
10
|
-
import { useMemo } from 'react';
|
|
11
|
-
|
|
12
|
-
const defaultEdges: Record<Edge, EdgeMode> = {
|
|
13
|
-
top: 'additive',
|
|
14
|
-
left: 'additive',
|
|
15
|
-
bottom: 'additive',
|
|
16
|
-
right: 'additive',
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
export type SafeAreaViewProps = NativeSafeAreaViewProps;
|
|
20
|
-
|
|
21
|
-
export const SafeAreaView = React.forwardRef<
|
|
22
|
-
NativeSafeAreaViewInstance,
|
|
23
|
-
SafeAreaViewProps
|
|
24
|
-
>(({ edges, ...props }, ref) => {
|
|
25
|
-
const nativeEdges = useMemo(() => {
|
|
26
|
-
if (edges == null) {
|
|
27
|
-
return defaultEdges;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
const edgesObj = Array.isArray(edges)
|
|
31
|
-
? edges.reduce<EdgeRecord>((acc, edge: Edge) => {
|
|
32
|
-
acc[edge] = 'additive';
|
|
33
|
-
return acc;
|
|
34
|
-
}, {})
|
|
35
|
-
: // ts has trouble with refining readonly arrays.
|
|
36
|
-
(edges as EdgeRecord);
|
|
37
|
-
|
|
38
|
-
// make sure that we always pass all edges, required for fabric
|
|
39
|
-
const requiredEdges: Record<Edge, EdgeMode> = {
|
|
40
|
-
top: edgesObj.top ?? 'off',
|
|
41
|
-
right: edgesObj.right ?? 'off',
|
|
42
|
-
bottom: edgesObj.bottom ?? 'off',
|
|
43
|
-
left: edgesObj.left ?? 'off',
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
return requiredEdges;
|
|
47
|
-
}, [edges]);
|
|
48
|
-
|
|
49
|
-
return <NativeSafeAreaView {...props} edges={nativeEdges} ref={ref} />;
|
|
50
|
-
});
|
package/src/SafeAreaView.web.tsx
DELETED
|
@@ -1,123 +0,0 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
2
|
-
import { StyleSheet, View } from 'react-native';
|
|
3
|
-
import {
|
|
4
|
-
Edge,
|
|
5
|
-
EdgeMode,
|
|
6
|
-
EdgeRecord,
|
|
7
|
-
NativeSafeAreaViewInstance,
|
|
8
|
-
NativeSafeAreaViewProps,
|
|
9
|
-
} from './SafeArea.types';
|
|
10
|
-
import { useSafeAreaInsets } from './SafeAreaContext';
|
|
11
|
-
|
|
12
|
-
const defaultEdges: Record<Edge, EdgeMode> = {
|
|
13
|
-
top: 'additive',
|
|
14
|
-
left: 'additive',
|
|
15
|
-
bottom: 'additive',
|
|
16
|
-
right: 'additive',
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
function getEdgeValue(
|
|
20
|
-
inset: number,
|
|
21
|
-
current: number,
|
|
22
|
-
mode: EdgeMode | undefined,
|
|
23
|
-
) {
|
|
24
|
-
switch (mode) {
|
|
25
|
-
case 'off':
|
|
26
|
-
return current;
|
|
27
|
-
case 'maximum':
|
|
28
|
-
return Math.max(current, inset);
|
|
29
|
-
case 'additive':
|
|
30
|
-
default:
|
|
31
|
-
return current + inset;
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
export const SafeAreaView = React.forwardRef<
|
|
36
|
-
NativeSafeAreaViewInstance,
|
|
37
|
-
NativeSafeAreaViewProps
|
|
38
|
-
>(({ style = {}, mode, edges, ...rest }, ref) => {
|
|
39
|
-
const insets = useSafeAreaInsets();
|
|
40
|
-
|
|
41
|
-
const edgesRecord = React.useMemo(() => {
|
|
42
|
-
if (edges == null) {
|
|
43
|
-
return defaultEdges;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
return Array.isArray(edges)
|
|
47
|
-
? edges.reduce<EdgeRecord>((acc, edge: Edge) => {
|
|
48
|
-
acc[edge] = 'additive';
|
|
49
|
-
return acc;
|
|
50
|
-
}, {})
|
|
51
|
-
: // ts has trouble with refining readonly arrays.
|
|
52
|
-
(edges as EdgeRecord);
|
|
53
|
-
}, [edges]);
|
|
54
|
-
|
|
55
|
-
const appliedStyle = React.useMemo(() => {
|
|
56
|
-
const flatStyle = StyleSheet.flatten(style) as Record<string, number>;
|
|
57
|
-
|
|
58
|
-
if (mode === 'margin') {
|
|
59
|
-
const {
|
|
60
|
-
margin = 0,
|
|
61
|
-
marginVertical = margin,
|
|
62
|
-
marginHorizontal = margin,
|
|
63
|
-
marginTop = marginVertical,
|
|
64
|
-
marginRight = marginHorizontal,
|
|
65
|
-
marginBottom = marginVertical,
|
|
66
|
-
marginLeft = marginHorizontal,
|
|
67
|
-
} = flatStyle;
|
|
68
|
-
|
|
69
|
-
const marginStyle = {
|
|
70
|
-
marginTop: getEdgeValue(insets.top, marginTop, edgesRecord.top),
|
|
71
|
-
marginRight: getEdgeValue(insets.right, marginRight, edgesRecord.right),
|
|
72
|
-
marginBottom: getEdgeValue(
|
|
73
|
-
insets.bottom,
|
|
74
|
-
marginBottom,
|
|
75
|
-
edgesRecord.bottom,
|
|
76
|
-
),
|
|
77
|
-
marginLeft: getEdgeValue(insets.left, marginLeft, edgesRecord.left),
|
|
78
|
-
};
|
|
79
|
-
|
|
80
|
-
return [style, marginStyle];
|
|
81
|
-
} else {
|
|
82
|
-
const {
|
|
83
|
-
padding = 0,
|
|
84
|
-
paddingVertical = padding,
|
|
85
|
-
paddingHorizontal = padding,
|
|
86
|
-
paddingTop = paddingVertical,
|
|
87
|
-
paddingRight = paddingHorizontal,
|
|
88
|
-
paddingBottom = paddingVertical,
|
|
89
|
-
paddingLeft = paddingHorizontal,
|
|
90
|
-
} = flatStyle;
|
|
91
|
-
|
|
92
|
-
const paddingStyle = {
|
|
93
|
-
paddingTop: getEdgeValue(insets.top, paddingTop, edgesRecord.top),
|
|
94
|
-
paddingRight: getEdgeValue(
|
|
95
|
-
insets.right,
|
|
96
|
-
paddingRight,
|
|
97
|
-
edgesRecord.right,
|
|
98
|
-
),
|
|
99
|
-
paddingBottom: getEdgeValue(
|
|
100
|
-
insets.bottom,
|
|
101
|
-
paddingBottom,
|
|
102
|
-
edgesRecord.bottom,
|
|
103
|
-
),
|
|
104
|
-
paddingLeft: getEdgeValue(insets.left, paddingLeft, edgesRecord.left),
|
|
105
|
-
};
|
|
106
|
-
|
|
107
|
-
return [style, paddingStyle];
|
|
108
|
-
}
|
|
109
|
-
}, [
|
|
110
|
-
edgesRecord.bottom,
|
|
111
|
-
edgesRecord.left,
|
|
112
|
-
edgesRecord.right,
|
|
113
|
-
edgesRecord.top,
|
|
114
|
-
insets.bottom,
|
|
115
|
-
insets.left,
|
|
116
|
-
insets.right,
|
|
117
|
-
insets.top,
|
|
118
|
-
mode,
|
|
119
|
-
style,
|
|
120
|
-
]);
|
|
121
|
-
|
|
122
|
-
return <View style={appliedStyle} {...rest} ref={ref} />;
|
|
123
|
-
});
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { TurboModule, TurboModuleRegistry } from 'react-native';
|
|
2
|
-
import type { Double } from 'react-native/Libraries/Types/CodegenTypes';
|
|
3
|
-
|
|
4
|
-
export interface Spec extends TurboModule {
|
|
5
|
-
getConstants: () => {
|
|
6
|
-
initialWindowMetrics?: {
|
|
7
|
-
insets: {
|
|
8
|
-
top: Double;
|
|
9
|
-
right: Double;
|
|
10
|
-
bottom: Double;
|
|
11
|
-
left: Double;
|
|
12
|
-
};
|
|
13
|
-
frame: {
|
|
14
|
-
x: Double;
|
|
15
|
-
y: Double;
|
|
16
|
-
width: Double;
|
|
17
|
-
height: Double;
|
|
18
|
-
};
|
|
19
|
-
};
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export default TurboModuleRegistry.get<Spec>('RNCSafeAreaContext');
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
DirectEventHandler,
|
|
3
|
-
Double,
|
|
4
|
-
} from 'react-native/Libraries/Types/CodegenTypes';
|
|
5
|
-
import codegenNativeComponent from 'react-native/Libraries/Utilities/codegenNativeComponent';
|
|
6
|
-
import type { ViewProps, HostComponent } from 'react-native';
|
|
7
|
-
|
|
8
|
-
export type Event = Readonly<{
|
|
9
|
-
insets: Readonly<{
|
|
10
|
-
top: Double;
|
|
11
|
-
right: Double;
|
|
12
|
-
bottom: Double;
|
|
13
|
-
left: Double;
|
|
14
|
-
}>;
|
|
15
|
-
frame: Readonly<{
|
|
16
|
-
x: Double;
|
|
17
|
-
y: Double;
|
|
18
|
-
width: Double;
|
|
19
|
-
height: Double;
|
|
20
|
-
}>;
|
|
21
|
-
}>;
|
|
22
|
-
|
|
23
|
-
export interface NativeProps extends ViewProps {
|
|
24
|
-
onInsetsChange?: DirectEventHandler<Event>;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export default codegenNativeComponent<NativeProps>(
|
|
28
|
-
'RNCSafeAreaProvider',
|
|
29
|
-
) as HostComponent<NativeProps>;
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import codegenNativeComponent from 'react-native/Libraries/Utilities/codegenNativeComponent';
|
|
2
|
-
import type { WithDefault } from 'react-native/Libraries/Types/CodegenTypes';
|
|
3
|
-
import type { ViewProps, HostComponent } from 'react-native';
|
|
4
|
-
|
|
5
|
-
export interface NativeProps extends ViewProps {
|
|
6
|
-
mode?: WithDefault<'padding' | 'margin', 'padding'>;
|
|
7
|
-
edges?: Readonly<{
|
|
8
|
-
top: string;
|
|
9
|
-
right: string;
|
|
10
|
-
bottom: string;
|
|
11
|
-
left: string;
|
|
12
|
-
}>;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export default codegenNativeComponent<NativeProps>('RNCSafeAreaView', {
|
|
16
|
-
interfaceOnly: true,
|
|
17
|
-
}) as HostComponent<NativeProps>;
|