|
| 1 | +import React, { PureComponent } from 'react'; |
| 2 | +import { View, TouchableOpacity } from 'react-native'; |
| 3 | +import { Header } from 'react-native-elements'; |
| 4 | +import Icon from 'react-native-vector-icons/FontAwesome'; |
| 5 | + |
| 6 | +import styles from '../Components/Shared.style'; |
| 7 | + |
| 8 | +const containerStyle = { |
| 9 | + alignItems: 'center', |
| 10 | + height: 50, |
| 11 | + justifyContent: 'center', |
| 12 | + paddingHorizontal: 0, |
| 13 | + paddingTop: 0, |
| 14 | + width: '100%' |
| 15 | +}; |
| 16 | + |
| 17 | +const centerContainerStyle = { paddingRight: 20 }; |
| 18 | + |
| 19 | +const buttonStyle = { |
| 20 | + alignItems: 'center', |
| 21 | + height: 48, |
| 22 | + justifyContent: 'center', |
| 23 | + paddingRight: 5, |
| 24 | + width: 40 |
| 25 | +}; |
| 26 | + |
| 27 | +const textStyle = { color: '#fff' }; |
| 28 | + |
| 29 | +const withHeader = ({ title = '' }) => (WrappedComponent) => { |
| 30 | + class HOC extends PureComponent { |
| 31 | + goBack = () => this.props.history.goBack(); |
| 32 | + |
| 33 | + goHome = () => this.props.history.replace('/'); |
| 34 | + |
| 35 | + horizontalComponent = (name, size, onPress) => ( |
| 36 | + <TouchableOpacity onPress={onPress} style={buttonStyle}> |
| 37 | + <Icon name={name} size={size} color='#fff' /> |
| 38 | + </TouchableOpacity> |
| 39 | + ); |
| 40 | + |
| 41 | + centerComponent = (title) => ({ |
| 42 | + text: title.toUpperCase(), |
| 43 | + style: textStyle |
| 44 | + }); |
| 45 | + |
| 46 | + render() { |
| 47 | + return ( |
| 48 | + <View style={styles.container}> |
| 49 | + <Header |
| 50 | + containerStyle={containerStyle} |
| 51 | + centerContainerStyle={centerContainerStyle} |
| 52 | + leftComponent={this.horizontalComponent('chevron-left', 20, this.goBack)} |
| 53 | + centerComponent={this.centerComponent(title)} |
| 54 | + rightComponent={this.horizontalComponent('home', 25, this.goHome)} |
| 55 | + /> |
| 56 | + <WrappedComponent /> |
| 57 | + </View> |
| 58 | + ); |
| 59 | + } |
| 60 | + } |
| 61 | + |
| 62 | + return HOC; |
| 63 | +} |
| 64 | + |
| 65 | +export default withHeader; |
0 commit comments