MCPcopy Create free account
hub / github.com/callstack/react-native-paper / useLayout

Function useLayout

src/utils/useLayout.tsx:4–29  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

2import type { LayoutChangeEvent } from 'react-native';
3
4export default function useLayout() {
5 const [layout, setLayout] = React.useState<{
6 height: number;
7 width: number;
8 measured: boolean;
9 }>({ height: 0, width: 0, measured: false });
10
11 const onLayout = React.useCallback(
12 (e: LayoutChangeEvent) => {
13 const { height, width } = e.nativeEvent.layout;
14
15 if (height === layout.height && width === layout.width) {
16 return;
17 }
18
19 setLayout({
20 height,
21 width,
22 measured: true,
23 });
24 },
25 [layout.height, layout.width]
26 );
27
28 return [layout, onLayout] as const;
29}

Callers 1

BottomNavigationBarFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…