import React from 'react' import { Image, type ImageSourcePropType, type LayoutChangeEvent, StatusBar, StyleSheet, TouchableOpacity, View, type StyleProp, type ViewStyle } from 'react-native' import { Text } from '../Text' import { SafeAreaView } from 'react-native-safe-area-context' import { iconAssets } from '../../static/iconBase64' export interface CustomNavbarProps { title?: string showBack?: boolean onBack?: () => void rightIcon?: ImageSourcePropType rightText?: string onRightPress?: () => void rightElement?: React.ReactNode leftElement?: React.ReactNode centerElement?: React.ReactNode showShadow?: boolean backgroundColor?: string titleColor?: string statusBarStyle?: 'dark-content' | 'light-content' statusBarBackgroundColor?: string manageStatusBar?: boolean style?: StyleProp onLayout?: (event: LayoutChangeEvent) => void onRightIconLayout?: (event: LayoutChangeEvent) => void } export const CustomNavbar: React.FC = ({ title = '', showBack = true, onBack, rightIcon, rightText, onRightPress, rightElement, leftElement, centerElement, showShadow = true, backgroundColor = '#FFFFFF', titleColor = '#000000', statusBarStyle = 'dark-content', statusBarBackgroundColor = '#FFFFFF', manageStatusBar = true, style, onLayout, onRightIconLayout, }) => { const hasRightContent: boolean = rightElement != null || rightIcon != null || (rightText != null && rightText.length > 0) const renderRight = (): React.ReactNode => { if (rightElement != null) return rightElement if (rightIcon != null) { return ( ) } if (rightText != null && rightText.length > 0) { return ( {rightText} ) } if (showBack) { return } return null } const renderLeft = (): React.ReactNode => { if (leftElement != null) return leftElement if (!showBack) return null return ( ) } const renderCenter = (): React.ReactNode => { if (centerElement != null) return centerElement if (title.length === 0) { return hasRightContent || showBack ? : null } return ( {title} ) } return ( {manageStatusBar ? ( ) : null} {renderLeft()} {renderCenter()} {renderRight()} ) } const styles = StyleSheet.create({ container: { flexDirection: 'column', }, shadow: { borderBottomWidth: StyleSheet.hairlineWidth, borderBottomColor: '#E5E7EB', }, row: { flexDirection: 'row', alignItems: 'center', height: 44, paddingHorizontal: 4, }, backBtn: { width: 40, height: 40, alignItems: 'center', justifyContent: 'center', }, backIcon: { width: 22, height: 22, }, title: { flex: 1, fontSize: 17, fontWeight: '600', textAlign: 'center', }, flexFill: { flex: 1, }, menuBtn: { width: 40, height: 40, alignItems: 'center', justifyContent: 'center', }, menuIcon: { width: 22, height: 22, }, menuTextIcon: { fontSize: 22, color: '#000000', fontWeight: '600', }, placeholder: { width: 40, height: 40, }, })