import { useEffect, useState } from "react"; import { View } from "react-native"; import type IMainHeader from "./type"; import stylesheet, { useStyles } from "./stylesheet"; import { NCoreUIKitTheme } from "../../core/hooks"; import { SafeAreaView } from "react-native-safe-area-context"; import { Portal } from "../../helpers/portalize"; import SiteLogo from "../siteLogo"; const MainHeader = ({ isWorkWithSafeAreaView = true, isWorkWithStickySpace = false, isSetAutoHeaderSpace = true, isWorkWithSeperator = false, backgroundColor = "default", portalName = "main-header", isWorkWithPortal = false, isWorkWithSticky = false, renderRight: RenderRight, renderLeft: RenderLeft, customBackgroundColor, onContentHeight, customLocalize, siteLogoProps, customTheme, glassEffect, children, style, ...props }: IMainHeader) => { const { borders, spaces, colors } = NCoreUIKitTheme.useContext(); const { safeAreaView: safeAreaViewDynamicStyle, container: containerDynamicStyle } = useStyles({ isWorkWithSafeAreaView, customBackgroundColor, isWorkWithSeperator, isWorkWithSticky, backgroundColor, glassEffect, borders, spaces, colors }); const [ contentHeight, setContentHeight ] = useState(null); useEffect(() => { if(onContentHeight) onContentHeight(contentHeight); }, [ contentHeight ]); const renderRight = () => { if(RenderRight) { return ; } return ; }; const renderLeft = () => { if(RenderLeft) { return ; } return ; }; const renderContent = () => { return { if(props && props.onLayout) { props.onLayout(event); } if(isWorkWithSticky) { const _contentHeight = event.nativeEvent.layout.height; setContentHeight(_contentHeight); if(isSetAutoHeaderSpace) { NCoreUIKitTheme.updateConfigs({ headerSpace: _contentHeight }); } } }} > {renderLeft()} {renderRight()} ; }; const renderContentContainer = () => { if(isWorkWithPortal) { return {renderContent()} ; } return renderContent(); }; const renderSafeAreaView = () => { return {renderContentContainer()} ; }; const renderWithChildren = () => { return {isWorkWithSafeAreaView ? renderSafeAreaView() : renderContentContainer()} { isWorkWithSticky && isWorkWithStickySpace ? : null } {children} ; }; if(children) { return renderWithChildren(); } return isWorkWithSafeAreaView ? renderSafeAreaView() : renderContentContainer(); }; export default MainHeader;