import React, { Component, ReactElement } from 'react' import { Text, View, TouchableOpacity, ViewStyle, TextStyle } from 'react-native' import { Icon } from '../Icon' import navigationBarStyles from './styles' import variables from '../../common/styles/variables' export interface NavigationBarProps { testID?: string style?: ViewStyle proportion?: number[] titleContainer?: ReactElement title?: string titleStyle?: TextStyle backLabel?: ReactElement backLabelIcon?: ReactElement backLabelText?: string backLabelTextStyle?: TextStyle onPressBack?: Function forwardLabel?: ReactElement forwardLabelText?: string forwardLabelTextStyle?: TextStyle onPressForward?: Function renderItem?: Function } export class NavigationBar extends Component { static defaultProps = { style: {}, proportion: [1, 2, 1], title: '标题', titleStyle: {}, backLabelText: '返回', onPressBack: null, forwardLabelText: null, onPressForward: null, renderItem: null } constructor (props: NavigationBarProps) { super(props) } renderItem(index) { const { backLabel, backLabelIcon, backLabelText, backLabelTextStyle, onPressBack, titleContainer, title, titleStyle, forwardLabel, forwardLabelText, forwardLabelTextStyle, onPressForward } = this.props const fontSize = variables.mtdFontSizeL const fontColor = variables.mtdGrayBase if (index === 0) { return ( { onPressBack && onPressBack() }}> { React.isValidElement(backLabel) ? backLabel : { React.isValidElement(backLabelIcon) ? backLabelIcon : } {backLabelText} } ) } if (index === 1) { return ( { React.isValidElement(titleContainer) ? titleContainer : {title}} ) } if (index === 2) { return ( { onPressForward && onPressForward() }}> { React.isValidElement(forwardLabel) ? forwardLabel : {forwardLabelText} } ) } } render() { const { testID, style, proportion, renderItem } = this.props return ( { proportion.map((item, index) => { return ( {renderItem ? renderItem(index) : this.renderItem(index)} ) }) } ) } }