import { useState, type ReactNode } from "react";
import { View } from "react-native";
import type { AppSymbolName } from "./AppSymbol";
import { AppText as Text } from "./AppText";
import { cn } from "../lib/cn";
import { MaterialIconButton } from "./MaterialIconButton";
import { AndroidAnchoredMenu } from "./AndroidAnchoredMenu";
import { useScaledTextRole } from "../features/settings/appearance/useScaledTextRole";
import { useMaterialToolbarLayout } from "./useMaterialToolbarLayout";
export interface AndroidHeaderAction {
readonly accessibilityLabel: string;
readonly icon: AppSymbolName;
readonly onPress: () => void;
readonly disabled?: boolean;
readonly selected?: 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 subtitle?: string | null;
readonly actions?: ReadonlyArray;
readonly leading?: ReactNode;
readonly trailing?: ReactNode;
readonly onBack?: () => void;
readonly embedded?: boolean;
readonly hideBottomBorder?: boolean;
}) {
const titleTypography = useScaledTextRole("title");
const subtitleTypography = useScaledTextRole("label");
const { height: materialToolbarHeight, ...headerPadding } = useMaterialToolbarLayout(
props.embedded,
);
const [headerWidth, setHeaderWidth] = useState(0);
const actions = props.actions ?? [];
const directCount = actions.length > 2 ? (headerWidth >= 600 ? 3 : 1) : actions.length;
const visibleActions = actions.slice(0, directCount);
const overflowActions = actions.slice(directCount);
return (
setHeaderWidth(event.nativeEvent.layout.width)}
className="border-b border-header-border bg-header px-2"
style={{
...headerPadding,
borderBottomWidth: props.hideBottomBorder ? 0 : undefined,
}}
>
{props.onBack ? (
) : null}
{props.leading}
{props.title}
{props.subtitle ? (
{props.subtitle}
) : null}
{visibleActions.map((action) => (
))}
{overflowActions.length > 0 ? (
({
id: String(index),
title: action.accessibilityLabel,
attributes: {
disabled: Boolean(action.disabled),
state: action.selected ? "on" : undefined,
},
}))}
onPressAction={({ nativeEvent }) =>
overflowActions[Number(nativeEvent.event)]?.onPress()
}
>
{(open) => (
)}
) : null}
{props.trailing}
);
}
export function AndroidSheetHeader(
props: Omit[0], "embedded">,
) {
return ;
}