import { AppActivityIndicator } from "./AppActivityIndicator";
import { Column, Row, Text as NativeText, RNHostView } from "@expo/ui/jetpack-compose";
import { weight } from "@expo/ui/jetpack-compose/modifiers";
import { use, useState, type ReactNode } from "react";
import { View } from "react-native";
import type { AppSymbolName } from "./AppSymbol";
import { NativeAppBar } from "./NativeAppBar.android";
import { IconButton } from "./IconButton";
import { AndroidAnchoredMenu } from "./AndroidAnchoredMenu";
import { splitAndroidHeaderActions } from "./headerMenu.android";
import { useScaledTextRole } from "../../features/settings/appearance/useScaledTextRole";
import { useToolbarLayout } from "./useToolbarLayout";
import { useControlTheme } from "./useControlTheme";
import { RoutedFormSheetContext } from "./RoutedFormSheetContext";
export interface AndroidHeaderAction {
readonly accessibilityLabel: string;
readonly icon: AppSymbolName;
readonly onPress: () => void;
readonly disabled?: boolean;
readonly loading?: boolean;
readonly selected?: boolean;
readonly subtitle?: string;
readonly destructive?: boolean;
readonly overflowOnly?: boolean;
}
export function AndroidHeaderIconButton(props: {
readonly accessibilityLabel: string;
readonly icon: AppSymbolName;
readonly onPress?: () => void;
readonly disabled?: boolean;
readonly selected?: boolean;
}) {
return ;
}
export function AndroidScreenHeader(props: {
readonly title: string;
readonly titleContent?: ReactNode;
readonly subtitle?: string | null;
readonly actions?: ReadonlyArray;
readonly leading?: ReactNode;
readonly trailing?: ReactNode;
readonly onBack?: () => void;
readonly embedded?: boolean;
readonly hideBottomBorder?: boolean;
/** One row with the subtitle after the title, for screens short on height. */
readonly compact?: boolean;
}) {
const { colors } = useControlTheme();
const titleTypography = useScaledTextRole("title");
const subtitleTypography = useScaledTextRole("label");
const inFormSheet = use(RoutedFormSheetContext);
const { paddingTop, paddingBottom } = useToolbarLayout(props.embedded || inFormSheet);
const [headerWidth, setHeaderWidth] = useState(0);
const { visibleActions, overflowActions } = splitAndroidHeaderActions(
props.actions ?? [],
headerWidth >= 600,
);
return (
setHeaderWidth(event.nativeEvent.layout.width)}
className="border-b border-header-border bg-header"
style={{
paddingTop,
paddingBottom,
borderBottomWidth: props.hideBottomBorder ? 0 : undefined,
}}
>
{inFormSheet ? (
) : null}
{props.onBack ? (
) : null}
{props.leading}
) : undefined
}
title={
props.titleContent ? (
{props.titleContent}
) : !props.subtitle ? (
{props.title}
) : props.compact ? (
{props.title}
{props.subtitle}
) : (
{props.title}
{props.subtitle ? (
{props.subtitle}
) : null}
)
}
actions={
visibleActions.length > 0 || overflowActions.length > 0 || props.trailing ? (
{visibleActions.map((action) =>
action.loading ? (
) : (
),
)}
{overflowActions.length > 0 ? (
({
id: String(index),
title: action.accessibilityLabel,
subtitle: action.subtitle,
state: action.selected ? "on" : undefined,
attributes: {
disabled: Boolean(action.disabled),
destructive: action.destructive,
},
}))}
onPressAction={({ nativeEvent }) =>
overflowActions[Number(nativeEvent.event)]?.onPress()
}
>
{(open) => (
)}
) : null}
{props.trailing}
) : undefined
}
/>
);
}
export function AndroidSheetHeader(
props: Omit[0], "embedded">,
) {
return ;
}