| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185 |
- 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 | number>(null);
- useEffect(() => {
- if(onContentHeight) onContentHeight(contentHeight);
- }, [
- contentHeight
- ]);
- const renderRight = () => {
- if(RenderRight) {
- return <RenderRight/>;
- }
- return <View/>;
- };
- const renderLeft = () => {
- if(RenderLeft) {
- return <RenderLeft/>;
- }
- return <SiteLogo
- isWorkWithFlex1={false}
- customLocalize={customLocalize}
- customTheme={customTheme}
- size="medium"
- {...siteLogoProps}
- />;
- };
- const renderContent = () => {
- return <View
- {...props}
- style={[
- style,
- stylesheet.container,
- containerDynamicStyle
- ]}
- onLayout={(event) => {
- 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()}
- </View>;
- };
- const renderContentContainer = () => {
- if(isWorkWithPortal) {
- return <Portal
- name={portalName}
- >
- {renderContent()}
- </Portal>;
- }
- return renderContent();
- };
- const renderSafeAreaView = () => {
- return <SafeAreaView
- edges={[
- "top"
- ]}
- style={[
- safeAreaViewDynamicStyle
- ]}
- >
- {renderContentContainer()}
- </SafeAreaView>;
- };
- const renderWithChildren = () => {
- return <View
- style={[
- stylesheet.baseContainer
- ]}
- >
- {isWorkWithSafeAreaView ? renderSafeAreaView() : renderContentContainer()}
- {
- isWorkWithSticky && isWorkWithStickySpace ?
- <View
- style={[
- stylesheet.stickySpacer,
- {
- backgroundColor: customBackgroundColor ? colors.project[customBackgroundColor] : colors.content.container[backgroundColor],
- height: contentHeight
- }
- ]}
- />
- :
- null
- }
- {children}
- </View>;
- };
- if(children) {
- return renderWithChildren();
- }
- return isWorkWithSafeAreaView ? renderSafeAreaView() : renderContentContainer();
- };
- export default MainHeader;
|