Skip to content

Commit

Permalink
top tabBAr added
Browse files Browse the repository at this point in the history
  • Loading branch information
Sankhadeep committed Oct 25, 2016
1 parent 58ec7f6 commit 0cd2553
Show file tree
Hide file tree
Showing 4 changed files with 178 additions and 38 deletions.
7 changes: 7 additions & 0 deletions Components/Themes/light.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,13 @@ export default {
tabBarActiveTextColor: (Platform.OS === 'ios' ) ? '#007aff' : '#fff',
tabActiveBgColor: (Platform.OS=='ios') ? '#cde1f9' : undefined,

//Tab
tabDefaultBg: (Platform.OS === 'ios' ) ? '#F8F8F8' : '#4179F7',
topTabBarTextColor: (Platform.OS === 'ios' ) ? '#6b6b6b' : '#b3c7f9',
topTabBarActiveTextColor: (Platform.OS === 'ios' ) ? '#007aff' : '#fff',
topTabActiveBgColor: (Platform.OS=='ios') ? '#cde1f9' : undefined,
topTabBarBorderColor: (Platform.OS === 'ios' ) ? '#007aff' : '#fff',


// Header
iosToolbarBtnColor: '#007aff',
Expand Down
8 changes: 5 additions & 3 deletions Components/Widgets/Button.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ export default class Button extends NativeBaseComponent {
rounded : React.PropTypes.bool,
large : React.PropTypes.bool,
small : React.PropTypes.bool,
inputButton : React.PropTypes.bool
inputButton : React.PropTypes.bool,
tabButton : React.PropTypes.bool
}

getInitialStyle() {
Expand Down Expand Up @@ -125,9 +126,11 @@ export default class Button extends NativeBaseComponent {
(this.props.bordered) ? this.getTheme().btnPrimaryBg :
(this.props.color) ? this.props.color :
(this.props.header) ? this.getTheme().toolbarTextColor :
(this.props.activeTabButton) ? this.getTheme().topTabBarActiveTextColor :
(this.props.tabButton) ? this.getTheme().topTabBarTextColor :
(this.props.transparent) ? this.getContextForegroundColor() :
this.getTheme().inverseTextColor,

marginBottom: ((this.props.vertical) && (Platform.OS == 'android')) ? 2 : undefined,
fontSize: (this.props.large) ? this.getTheme().iconSizeLarge :
(this.props.small) ? this.getTheme().iconSizeSmall :
(this.props.inputButton) ? this.getTheme().toolbarIconSize :
Expand All @@ -150,7 +153,6 @@ export default class Button extends NativeBaseComponent {
return iconComponentPresent;
}
renderChildren() {

if(typeof this.props.children == 'string') {
return <Text style={this.getTextStyle()}>{(Platform.OS==='ios' || !this.props.capitalize) ? this.props.children : this.props.children.toUpperCase()}</Text>
}
Expand Down
129 changes: 129 additions & 0 deletions Components/Widgets/Tab.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
/* @flow */
'use strict';

import React from 'react';
import NativeBaseComponent from '../Base/NativeBaseComponent';
import computeProps from '../../Utils/computeProps';
import Button from './Button';
import { Platform, Animated, Dimensions } from 'react-native';
import View from './View';
import Icon from './Icon';
import Badge from './Badge';
import IconNB from './Icon';
import Text from './Text';
import _ from 'lodash';

const { height, width } = Dimensions.get('window');

export default class Footer extends NativeBaseComponent {

propTypes: {
style : React.PropTypes.object
}

state = {
length: undefined,
activeIndex: undefined
}

getInitialStyle() {
return {
tab: {
flexDirection: 'row',
elevation: 2,
shadowColor: '#000',
shadowOffset: {width: 0, height: 2},
shadowOpacity: 0.1,
backgroundColor: this.getTheme().tabDefaultBg,
shadowRadius: 1.5,
position: 'relative'
},
button: {
flex: 1,
borderRadius: 0,
height: this.checkIconPresent() ? 63 : 45,
justifyContent: 'center',
shadowColor: 'transparent',
shadowOffset: undefined,
shadowOpacity: 0,
shadowRadius: 0,
borderColor: this.getTheme().topTabBarBorderColor
},
textStyle: {
color: this.getTheme().topTabBarTextColor,
lineHeight: (Platform.OS == 'ios') ? 17 : undefined
},
activeTextStyle: {
fontWeight: '600',
color: this.getTheme().topTabBarActiveTextColor,
lineHeight: (Platform.OS == 'ios') ? 16 : undefined
}
}
}

prepareRootProps() {

var defaultProps = {
style: this.getInitialStyle().tab
};

return computeProps(this.props, defaultProps);

}

componentDidMount() {
let childrenArray = React.Children.toArray(this.props.children);
let length = childrenArray.length;
this.setState({
length: length
});
this.getWidth();
}

checkIconPresent() {
let icon = false;
React.Children.forEach(this.props.children, function (child) {
if(typeof child.props.children == 'object')
icon = true;
})
return icon;
}

getWidth() {
let childrenArray = React.Children.toArray(this.props.children);
let activeIndex = _.findIndex(childrenArray, (child) => child.props.active);
this.setState({
activeIndex : activeIndex
});


}

renderTab() {
let childrenArray = React.Children.toArray(this.props.children);
let length = childrenArray.length;
let newChildren = [];

{childrenArray.map((child, i) => {
newChildren.push(React.cloneElement(child, {
style: [this.getInitialStyle().button, {borderBottomWidth: (child.props.active) ? 3 : 0}],
capitalize: true,
transparent:true,
tabButton: true,
activeTabButton: (child.props.active) ? true : false,
vertical:true,
textStyle: (child.props.active) ? this.getInitialStyle().activeTextStyle : this.getInitialStyle().textStyle,
key: i}));
}
)}
return newChildren;
}

render() {
return(
<View {...this.prepareRootProps()}>
{this.renderTab()}
</View>
);
}
}
72 changes: 37 additions & 35 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import Textarea from './Components/Widgets/Textarea';
import InputGroup from './Components/Widgets/InputGroup';
import Icon from './Components/Widgets/Icon';
import FooterTab from './Components/Widgets/FooterTab';
import Tab from './Components/Widgets/Tab';
import Thumbnail from './Components/Widgets/Thumbnail';
import CheckBox from './Components/Widgets/Checkbox';
import Radio from './Components/Widgets/Radio';
Expand All @@ -37,39 +38,40 @@ import ScrollableTabView from './Components/Widgets/Tabs';


module.exports = {
Header: Header,
Footer: Footer,
Title: Title,
Container: Container,
Content: Content,
Button: Button,
Text: Text,
Switch: Switch,
Picker: Picker,
List: List,
ListItem: ListItem,
CardItem: CardItem,
H1: H1,
H2: H2,
H3: H3,
View: View,
Row: Row,
Col: Col,
Grid: Grid,
InputGroup: InputGroup,
Input: Input,
Textarea: Textarea,
Icon: Icon,
Thumbnail: Thumbnail,
Card: Card,
CardSwiper: CardSwiper,
DeckSwiper: DeckSwiper,
Badge: Badge,
Spinner: Spinner,
CheckBox: CheckBox,
Radio: Radio,
// ProgressBar: ProgressBar,
Drawer: Drawer,
FooterTab: FooterTab,
Tabs : ScrollableTabView
Header: Header,
Footer: Footer,
Title: Title,
Container: Container,
Content: Content,
Button: Button,
Text: Text,
Switch: Switch,
Picker: Picker,
List: List,
ListItem: ListItem,
CardItem: CardItem,
H1: H1,
H2: H2,
H3: H3,
View: View,
Row: Row,
Col: Col,
Grid: Grid,
InputGroup: InputGroup,
Input: Input,
Textarea: Textarea,
Icon: Icon,
Thumbnail: Thumbnail,
Card: Card,
CardSwiper: CardSwiper,
DeckSwiper: DeckSwiper,
Badge: Badge,
Spinner: Spinner,
CheckBox: CheckBox,
Radio: Radio,
// ProgressBar: ProgressBar,
Drawer: Drawer,
FooterTab: FooterTab,
TabBar: Tab,
Tabs : ScrollableTabView
};

0 comments on commit 0cd2553

Please sign in to comment.