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

NativeColumnContent.ios.tsx

41 lines1.6 KB

1import { HeaderHeightContext } from "@react-navigation/elements";
2import { useState, type ReactNode } from "react";
3import { View, type ColorValue } from "react-native";
4import { SafeAreaProvider, SafeAreaView } from "react-native-safe-area-context";
5import { NativeColumnLayoutMetricsContext } from "./native-layout-metrics";
6import type { NativeLayoutMetrics } from "../lib/reserved-regions";
7import { NativeLayoutObserver } from "./NativeLayoutObserver";
8​
9export function NativeColumnContent(props: {
10 readonly children: ReactNode;
11 readonly primary?: boolean;
12 readonly insetHorizontally?: boolean;
13 readonly backgroundColor?: ColorValue;
14}) {
15 const [metrics, setMetrics] = useState<NativeLayoutMetrics | null>(null);
16 return (
17 <View
18 className={props.primary ? "flex-1 bg-drawer" : "flex-1 bg-screen"}
19 style={
20 props.backgroundColor === undefined ? undefined : { backgroundColor: props.backgroundColor }
21 }
22 >
23 <SafeAreaProvider style={{ flex: 1 }}>
24 <SafeAreaView
25 edges={props.insetHorizontally === false ? [] : ["left", "right"]}
26 style={{ flex: 1 }}
27 >
28 {/* Observe the inset body. UIKit can reserve other columns in its safe area. */}
29 <View style={{ flex: 1 }}>
30 <NativeLayoutObserver onChange={setMetrics} />
31 <NativeColumnLayoutMetricsContext value={metrics}>
32 <HeaderHeightContext value={metrics?.safeArea.top ?? undefined}>
33 {props.children}
34 </HeaderHeightContext>
35 </NativeColumnLayoutMetricsContext>
36 </View>
37 </SafeAreaView>
38 </SafeAreaProvider>
39 </View>
40 );