|
| 1 | +/* @flow */ |
| 2 | +'use strict'; |
| 3 | + |
| 4 | +import React from 'react'; |
| 5 | +import NativeBaseComponent from '../Base/NativeBaseComponent'; |
| 6 | +import computeProps from '../../Utils/computeProps'; |
| 7 | +import Button from './Button'; |
| 8 | +import { Platform } from 'react-native'; |
| 9 | +import View from './View'; |
| 10 | +import Icon from './Icon'; |
| 11 | +import IconNB from './Icon'; |
| 12 | +import Text from './Text'; |
| 13 | + |
| 14 | +export default class Footer extends NativeBaseComponent { |
| 15 | + |
| 16 | + propTypes: { |
| 17 | + style : React.PropTypes.object |
| 18 | + } |
| 19 | + |
| 20 | + getInitialStyle() { |
| 21 | + return { |
| 22 | + footerTab: { |
| 23 | + flexDirection: 'row', |
| 24 | + justifyContent: 'space-between', |
| 25 | + flex: 1, |
| 26 | + alignSelf: 'stretch', |
| 27 | + paddingHorizontal: 15 |
| 28 | + }, |
| 29 | + btnTextStyle: { |
| 30 | + color: this.getTheme().tabBarTextColor, |
| 31 | + fontSize: 14 |
| 32 | + }, |
| 33 | + btnActiveTextStyle: { |
| 34 | + color: this.getTheme().tabBarActiveTextColor, |
| 35 | + fontSize: 14 |
| 36 | + }, |
| 37 | + btnStyle: { |
| 38 | + alignSelf: 'center' |
| 39 | + } |
| 40 | + } |
| 41 | + } |
| 42 | + |
| 43 | + prepareRootProps() { |
| 44 | + |
| 45 | + var defaultProps = { |
| 46 | + style: this.getInitialStyle().footerTab |
| 47 | + }; |
| 48 | + |
| 49 | + return computeProps(this.props, defaultProps); |
| 50 | + |
| 51 | + } |
| 52 | + |
| 53 | + renderFooter() { |
| 54 | + var childrenArray = React.Children.toArray(this.props.children); |
| 55 | + var newChildren = []; |
| 56 | + |
| 57 | + {childrenArray.map((child, i) => { |
| 58 | + if (typeof child.props.children==='string') { |
| 59 | + newChildren.push(React.cloneElement(child, { |
| 60 | + style: this.getInitialStyle().btnStyle, |
| 61 | + vertical: true, |
| 62 | + transparent:true, |
| 63 | + textStyle: (child.props.active) ? this.getInitialStyle().btnActiveTextStyle : this.getInitialStyle().btnTextStyle, |
| 64 | + key: i})); |
| 65 | + } |
| 66 | + else { |
| 67 | + let iconElement = []; |
| 68 | + iconElement = _.remove(child.props.children, function(item) { |
| 69 | + if(item.type == IconNB) { |
| 70 | + return true; |
| 71 | + } |
| 72 | + }); |
| 73 | + if (iconElement.length>0) { |
| 74 | + newChildren.push( |
| 75 | + <Button transparent vertical |
| 76 | + style={this.getInitialStyle().btnStyle} |
| 77 | + textStyle={(child.props.active) ? this.getInitialStyle().btnActiveTextStyle : this.getInitialStyle().btnTextStyle} |
| 78 | + key={i}> |
| 79 | + {child.props.children} |
| 80 | + <Icon |
| 81 | + style={{color: (child.props.active) ? this.getTheme().tabBarActiveTextColor : this.getTheme().tabBarTextColor}} |
| 82 | + name={iconElement[0].props.name} /> |
| 83 | + </Button> |
| 84 | + ); |
| 85 | + } |
| 86 | + else { |
| 87 | + newChildren.push( |
| 88 | + <Button transparent vertical |
| 89 | + style={this.getInitialStyle().btnStyle} |
| 90 | + textStyle={(child.props.active) ? this.getInitialStyle().btnActiveTextStyle : this.getInitialStyle().btnTextStyle} |
| 91 | + key={i}> |
| 92 | + <Icon |
| 93 | + style={{color: (child.props.active) ? this.getTheme().tabBarActiveTextColor : this.getTheme().tabBarTextColor}} |
| 94 | + name={child.props.children.props.name} /> |
| 95 | + </Button> |
| 96 | + ); |
| 97 | + } |
| 98 | + }; |
| 99 | + })} |
| 100 | + return newChildren; |
| 101 | + } |
| 102 | + |
| 103 | + render() { |
| 104 | + |
| 105 | + return( |
| 106 | + <View {...this.prepareRootProps()} > |
| 107 | + {this.renderFooter()} |
| 108 | + </View> |
| 109 | + ); |
| 110 | + } |
| 111 | +} |
0 commit comments