import React, { useState } from 'react' import { View, Text, StyleSheet, TouchableOpacity, Image, StatusBar, ViewStyle } from 'react-native'; import { back } from '../../NavigationService'; import { px2dp, onePx, size, statusBarHeight, isIos, colors } from './../../utils'; interface Props { rightComponent?: any; title?: string; subTitle?: string blod?: boolean; noBoder?: boolean; style?: ViewStyle; hideMessage?: boolean; mode?: 'dark' | 'light'; useCancelText?: boolean; handleBack?: Function, backgroundColor?: string customBackIcon?: any hideBack?: boolean sideWidth?: number }; const NormalHeader = (props: Props) => { const { rightComponent, title, blod = false, noBoder, style, hideMessage, mode = "light", useCancelText, backgroundColor, customBackIcon = "", hideBack = false, sideWidth = px2dp(100), subTitle = "" } = props; React.useEffect(() => { // if (mode === 'light') { // StatusBar.setBarStyle('light-content'); // } else { // StatusBar.setBarStyle('dark-content'); // } }, []) const goBack = () => { const { handleBack } = props; if (handleBack) { handleBack && handleBack(); } else { back(); } }; const confirmBack = () => { let confirmData = { title: '确认取消编辑?系统将不会保留您的更改', confirmText: '确认', confirmFun: goBack }; // myConfirm(confirmData) }; return ( { hideBack ? null : <> { useCancelText ? confirmBack()} style={styles.backPress}> 取消 : <> { customBackIcon ? goBack()} style={styles.backPress}> : goBack()} style={styles.backPress}> { isIos() ? : } } } } {title ? title : ""} { subTitle ? {subTitle} : null } {rightComponent} ) }; const styles = StyleSheet.create({ headerContainer: { width: '100%', height: size.head_height + statusBarHeight, paddingTop: statusBarHeight, flexDirection: 'row', justifyContent: 'space-between', alignItems: 'center', backgroundColor: colors.themeColor, zIndex: 99, }, sideContainer: { width: px2dp(100), flexDirection: 'row', height: size.head_height, alignItems: 'center', justifyContent: 'flex-start', // backgroundColor: 'red' }, backPress: { height: size.head_height, paddingHorizontal: px2dp(12), justifyContent: 'center', alignItems: 'center' }, headerTitle: { fontSize: 18, color: '#fff', fontWeight: '500', maxWidth: px2dp(240), textAlign: 'center' }, headerIcon: { width: px2dp(20), height: px2dp(20), tintColor: '#fff' }, headerIconMini: { width: px2dp(18), height: px2dp(18), tintColor: '#fff' }, messageBox: { paddingHorizontal: px2dp(12), position: 'relative', marginTop: px2dp(-3) }, messageIcon: { width: px2dp(24), height: px2dp(24), }, messageNumBox: { position: 'absolute', top: px2dp(-2), right: px2dp(10), width: px2dp(18), height: px2dp(14), backgroundColor: colors.redColor, zIndex: 999, borderRadius: px2dp(8), justifyContent: 'center', alignItems: 'center' }, messageNum: { fontSize: 8, color: '#fff', opacity: 0.9 }, }) export default NormalHeader;