Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

AndroidHingeObserver.android.tsx

29 lines1.1 KB

1import { requireNativeView } from "expo";
2import type { NativeSyntheticEvent, ViewProps } from "react-native";
3import type { VerticalHinge } from "../lib/layout";
4​
5interface ObserverProps extends ViewProps {
6 readonly onHingeChange: (
7 event: NativeSyntheticEvent<Partial<VerticalHinge & { readonly windowX: number }>>,
8 ) => void;
9}
10​
11const Observer = requireNativeView<ObserverProps>("T3FoldPosture");
12​
13/** Reports a vertical hinge in this view's coordinates while the device is bent like a book. */
14export function AndroidHingeObserver(props: {
15 /** Receives the hinge in this view's coordinates and in window coordinates. */
16 readonly onChange: (hinge: VerticalHinge | null, windowHinge: VerticalHinge | null) => void;
17}) {
18 return (
19 <Observer
20 pointerEvents="none"
21 onHingeChange={({ nativeEvent: { x, width, windowX } }) =>
22 x === undefined || width === undefined || windowX === undefined
23 ? props.onChange(null, null)
24 : props.onChange({ x, width }, { x: windowX, width })
25 }
26 style={{ position: "absolute", top: 0, bottom: 0, left: 0, right: 0 }}
27 />
28 );