import * as React from "react"; import {StyleProp, TextStyle, View, ViewStyle} from "react-native"; import {HeaderIconParams, IProps} from "./header"; import app, {ThemeCss} from "../../app"; import Basic from "../../basicPage"; import {useNav} from "../../nav"; const CompositeHeader: React.FC = (props) => { const css = app.theme.useGet(); const nav = useNav(); // 宽度 const width = props.width ?? css.width; // 一份 const partWidth = width / 8; // 获取底线 const hasBottomLine = typeof props.hasBottomLine === 'boolean' ? props.hasBottomLine : true; // 获取是否透明 const isTransparent = typeof props.isTransparent === 'boolean' ? props.isTransparent : false; // 是否浮动 const isFloat = typeof props.isFloat === 'boolean' ? props.isFloat : false; // 是否中间区域撑到最大 const isCenterMax = typeof props.isCenterMax === 'boolean' ? props.isCenterMax : false; // 默认样式 const defaultStyle: StyleProp = { marginTop: props.t ?? props.mt ?? 0, width: props.width ?? css.width, height: css.header.height, backgroundColor: isTransparent ? 'rgba(0,0,0,0)' : props.bgColor ?? css.header.bg, } // 是否浮动 if (isFloat) { defaultStyle.position = 'absolute'; defaultStyle.top = css.app.barHeight; defaultStyle.left = defaultStyle.right = props.width ? (css.width - props.width) / 2 : 0; defaultStyle.zIndex = 1; } // 是否存在底线 if (hasBottomLine) { defaultStyle.borderBottomWidth = typeof props.bottomLineSize === "number" ? props.bottomLineSize : 0.5; defaultStyle.borderBottomColor = props.bottomLineColor ?? css.header.line; } // 标题样式 const titleStyle: StyleProp = { color: props.titleColor ?? css.header.color ?? '#666', fontSize: props.titleSize ?? css.header.size ?? 16, lineHeight: css.header.height, fontWeight: 'bold', } // left 图标 const leftIcon: HeaderIconParams = { onPress: () => nav.back(), } if (props.leftIcon) leftIcon.icon = props.leftIcon; if (props.leftIconColor) leftIcon.color = props.leftIconColor; if (props.leftIconSize) leftIcon.size = props.leftIconSize; // let leftView: React.ReactNode = headerIcon(leftIcon), rightView: React.ReactNode = , centerView: React.ReactNode = ; if (props.leftView && typeof props.leftView === 'object') leftView = props.leftView; if (props.rightView && typeof props.rightView === 'object') rightView = props.rightView; if (props.centerView && typeof props.centerView === 'object') centerView = props.centerView; const leftWidth = partWidth; const rightWidth = partWidth * 2; // 左右 样式 const leftRightStyle: StyleProp = {height: css.header.height}; // 中间 样式 const centerStyle: StyleProp = { height: css.header.height, flex: 1, paddingHorizontal: leftWidth, }; return {/* left */} {leftView} {/* center */} {centerView} {/* right */} {rightView} } /** * header icon view * @param params */ const headerIcon = (params?: HeaderIconParams): React.ReactNode => { const css = app.theme.useGet(); params = params || {}; const iconName: string = params.icon ?? app.iconfont.getBack(); const size = params.size ? params.size : 18; const color = params.color ? params.color : css.app.leftIconColor; return { if (typeof params.onPress === "function") params.onPress(event); }}> } export default CompositeHeader export { headerIcon, }