forked from callstackincubator/react-native-grab
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgrab-screen.tsx
More file actions
32 lines (26 loc) · 729 Bytes
/
grab-screen.tsx
File metadata and controls
32 lines (26 loc) · 729 Bytes
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
import { useCallback, useRef } from "react";
import { View, type ViewProps } from "react-native";
import { setFocusedScreenRef } from "./containers";
import { getFocusEffect } from "./focus-effect";
const useFocusEffect = getFocusEffect();
export type ReactNativeGrabScreenProps = ViewProps;
export const ReactNativeGrabScreen = ({
children,
style,
...props
}: ReactNativeGrabScreenProps) => {
const screenRef = useRef<View | null>(null);
useFocusEffect(
useCallback(() => {
if (!screenRef.current) {
return;
}
setFocusedScreenRef(screenRef.current);
}, []),
);
return (
<View {...props} ref={screenRef} style={[{ flex: 1 }, style]}>
{children}
</View>
);
};