import * as React from 'react'; import { View, Text, StatusBar, TouchableOpacity, ViewStyle, Pressable } from 'react-native'; import Node from '../node'; import Icon from '../icon'; import { isIPhoneX } from '../_util'; import { STATUS_BAR_HEIGHT, TOP_SAFE_HEIGHT } from '../_constants'; import styles from './style'; const prefixCls = 'navigation-bar'; export interface LeftButtonProps { color?: string; style?: ViewStyle; children?: string | number; onPress?: (e?: any) => void; } const leftStyle = { flexDirection: 'row', alignItems: 'center', paddingLeft: 15, minWidth: 40, } as ViewStyle; const leftTextStyle = { fontSize: 16, marginLeft: -4, }; export const LeftButton: React.FC = props => { const { color, style, children, onPress } = props; return ( {children} ); }; export interface NavigationBarProps { left?: React.ReactNode; leftText?: string | number; right?: React.ReactNode; fill?: boolean; statusBar?: any; leftColor?: string; titleColor?: string; backgroundColor?: string; opacity?: number; children?: React.ReactNode; previous?: any; navigation?: any; look?: 'light' | 'dark'; showBackButton?: boolean; absolute?: boolean; numberOfLines?: number; onLeftPress?: (e?: any) => void; onRightPress?: (e?: any) => void; } const NavigationBar: React.FC & { config: NavigationBarConfigProps; setDefaultConfig: (config: any) => void; LeftButton: React.FC; } = props => { const { leftText, leftColor, left, right, onLeftPress, onRightPress, statusBar = { barStyle: 'light-content', hidden: false, }, titleColor, backgroundColor, opacity, look, showBackButton, absolute, numberOfLines, children, } = props; let curBackgroundColor = backgroundColor; let curTitleColor = titleColor; let curLeftColor = leftColor; let curOpacity = opacity; if (look === 'light') { curBackgroundColor = '#FFFFFF'; curTitleColor = '#000'; curLeftColor = '#000'; } let leftNode = left; if (!left && showBackButton) { leftNode = ( {leftText} ); } const absoluteTop = isIPhoneX() ? TOP_SAFE_HEIGHT : STATUS_BAR_HEIGHT; const absoluteStyle = absolute ? { position: 'absolute', top: absoluteTop, left: 0, right: 0, zIndex: 1, } : null; const navStyle = { backgroundColor: curBackgroundColor, opacity: curOpacity, ...absoluteStyle, }; return ( {!statusBar.hidden ? ( ) : null} {leftNode} {children} {right} ); }; export interface NavigationBarConfigProps { onLeftPress?: (e?: any) => void; } NavigationBar.config = {}; NavigationBar.setDefaultConfig = ({ onLeftPress }) => { if (onLeftPress) { NavigationBar.config.onLeftPress = onLeftPress; } }; NavigationBar.LeftButton = LeftButton; export default NavigationBar;