import { StatusBar } from "expo-status-bar"; import React from "react"; import { useSafeAreaInsets } from "react-native-safe-area-context"; import { styled, YStack } from "tamagui"; import { ScreenHeading } from "@/ui/components/layout/ScreenHeading"; import { ScreenSection } from "@/ui/components/layout/ScreenSection"; type ScreenViewProps = React.ComponentProps & { showStatusBar?: boolean; statusBarStyle?: "auto" | "inverted" | "light" | "dark"; statusBarBackgroundColor?: string; children?: React.ReactNode; }; type ScreenViewComponent = React.FC> & { Heading: typeof ScreenHeading; Section: typeof ScreenSection; }; const ScreenContent = styled(YStack, { alignItems: "center", gap: "$4", paddingHorizontal: "$4", }); const ScreenView: ScreenViewComponent = (props: React.PropsWithChildren) => { const { showStatusBar = true, statusBarStyle = "auto", statusBarBackgroundColor = "transparent", padding, children, ...rest } = props; const insets = useSafeAreaInsets(); let headingElement: React.ReactNode | null = null; const otherChildren: React.ReactNode[] = []; // Iterate through children to find the Heading and separate others React.Children.forEach(children, (child) => { if (React.isValidElement(child)) { if (child.type === ScreenView.Heading) { headingElement = child; } else { otherChildren.push(child); } } else { otherChildren.push(child); } }); return ( <> {showStatusBar ? ( ) : null} {headingElement} {otherChildren} ); }; ScreenView.Heading = ScreenHeading; ScreenView.Section = ScreenSection; export { ScreenView };