import { ArrowLeft } from '@/assets/icons';
import { Text, Touchable } from '@/components/core';
import { APP_BAR_HEIGHT, DEFAULT_HORIZONTAL_EDGE_SPACING } from '@/core/constants';
import { AppBarAction } from '@/core/interfaces';
import { useLayout, useTailwind } from '@/hooks';
import { useNavigation } from '@react-navigation/native';
import { compareMemo } from '@/utils';
import { useMemo } from 'react';
import { View, ViewProps } from 'react-native';
import { useSafeAreaInsets } from 'react-native-safe-area-context';
export interface AppBarProps extends ViewProps {
title: string;
rightActions?: AppBarAction[];
actionSeparatorWidth?: number;
}
function AppBar({ title, rightActions = [], actionSeparatorWidth = 8, ...props }: AppBarProps) {
const tw = useTailwind();
const edgeInsets = useSafeAreaInsets();
const { canGoBack, goBack } = useNavigation();
const { layout: sideLayout, handleLayout: handleSideLayout } = useLayout({
flexibleLayout: false,
});
const iconColor = tw.color(tw.prefixMatch('dark') ? 'white' : 'zinc-700');
const RightActions = useMemo(
() =>
rightActions.map(({ onPress, Icon, size = 24 }: AppBarAction, index) => {
return (
);
}),
[rightActions, actionSeparatorWidth, iconColor],
);
const handleGoBack = canGoBack() ? goBack : undefined;
return (
{handleGoBack && (
)}
{title}
{RightActions}
);
}
export default compareMemo(AppBar);