diff --git a/.babelrc b/.babelrc index 4a3d985..c43ebcd 100644 --- a/.babelrc +++ b/.babelrc @@ -1,6 +1,3 @@ { - "plugins": [ - "transform-class-properties" - ], - "presets": ["stage-0", "es2015", "react"] -} + "presets": ["react-native-stage-0"] +} \ No newline at end of file diff --git a/components/demo/ExampleList.js b/components/demo/ExampleList.js index 5adf376..5b11d5a 100644 --- a/components/demo/ExampleList.js +++ b/components/demo/ExampleList.js @@ -15,7 +15,8 @@ import ErrorPage from './ErrorExample' import LoadingPage from './LoadingExample' import IconsExample from './IconsExample' import ImageExample from './ImageExample' -import NavbarExample from './NavBarExample' +import NavBarExample from './NavBarExample' +import TabBarExample from './TabBarExample' import AllTogetherNow from './AllTogetherNow' @@ -52,7 +53,11 @@ const Examples: Array = [ }, { name: 'NavBar', - module: NavbarExample + module: NavBarExample + }, + { + name: 'TabBar', + module: TabBarExample }, { name: 'Rows', diff --git a/components/demo/TabBarExample.js b/components/demo/TabBarExample.js new file mode 100644 index 0000000..a4ebca1 --- /dev/null +++ b/components/demo/TabBarExample.js @@ -0,0 +1,43 @@ +import React, {PropTypes} from 'react' +import { + View, + Text, + ScrollView, + Platform +} from 'react-native' + +import { + Base, + TabBar +} from '../panza' + +function noop() { +} + +export default class NavBarExample extends React.Component { + render() { + return ( + + + + + + + + ) + } +} diff --git a/components/panza/Nav/TabBar.js b/components/panza/Nav/TabBar.js new file mode 100644 index 0000000..334b2cf --- /dev/null +++ b/components/panza/Nav/TabBar.js @@ -0,0 +1,141 @@ +import React, {Component} from 'react'; +import { + StyleSheet, + Text, + View, + Animated, + TouchableOpacity, + LayoutAnimation, + Dimensions +} from 'react-native'; +import { Base, TextBase } from '../Base' + +export default class TabBar extends Component { + static propTypes = { + onTabPress: React.PropTypes.func, + activeTab: React.PropTypes.number, + tabs: React.PropTypes.array, + width: React.PropTypes.number, + height: React.PropTypes.number, + underlineColor: React.PropTypes.string, + underlineHeight: React.PropTypes.number, + backgroundColor: React.PropTypes.string, + activeTextColor: React.PropTypes.string, + inactiveTextColor: React.PropTypes.string, + textProps: Text.propTypes.style, + tabStyle: View.propTypes.style, + containerStyle: View.propTypes.style + }; + static defaultProps = { + height: 40, + activeTextColor: 'primary', + inactiveTextColor: 'secondary', + underlineColor: 'primary', + backgroundColor: 'white', + underlineHeight: 2, + onTabPress: () => {} + }; + + constructor(props) { + super(props); + const { activeTab, width, tabs } = props; + + this.width = width || Dimensions.get('window').width; + this.state = { + left: activeTab ? activeTab * this.width / tabs.length : 0, + activeTab: activeTab || 0 + }; + } + + componentWillReceiveProps(nextProps) { + if (nextProps.activeTab !== this.props.activeTab) { + LayoutAnimation.easeInEaseOut(); + this.setState({ + left: nextProps.activeTab * this.width / nextProps.tabs.length, + activeTab: nextProps.activeTab + }); + } + } + + onTabPress(i) { + LayoutAnimation.easeInEaseOut(); + this.setState({ + left: i * this.width / this.props.tabs.length, + activeTab: i + }); + this.props.onTabPress(i); + } + + renderTabOption(name, i) { + const isTabActive = this.state.activeTab === i; + const { activeTextColor, inactiveTextColor, textProps } = this.props; + const textColor = isTabActive ? activeTextColor : inactiveTextColor; + + return ( + { + this.onTabPress(i) + }} + > + + + {name} + + + + ); + } + + render() { + const { + height, + underlineHeight, + underlineColor, + backgroundColor, + containerStyle, + tabs, + ...other + } = this.props; + const numberOfTabs = tabs.length; + + const tabUnderlineStyle = { + position: 'absolute', + width: this.width / numberOfTabs, + height: underlineHeight, + bottom: 0 + }; + + return ( + + {tabs.map((tab, i) => this.renderTabOption(tab, i))} + + + ); + } +} + +const styles = StyleSheet.create({ + tab: { + flex: 1, + alignItems: 'center', + justifyContent: 'center' + }, + container: { + borderWidth: 0, + borderBottomWidth: 1, + borderBottomColor: '#ccc', + flexDirection: 'row', + justifyContent: 'space-around' + } +}); + diff --git a/components/panza/Nav/index.js b/components/panza/Nav/index.js index f64af05..7dcb4db 100644 --- a/components/panza/Nav/index.js +++ b/components/panza/Nav/index.js @@ -4,6 +4,7 @@ import NavIconContainer from './NavIconContainer' import NavTouchableIcon from './NavTouchableIcon' import NavTouchableText from './NavTouchableText' import SubNav from './SubNav' +import TabBar from './TabBar' export { NavIconContainer, @@ -11,5 +12,6 @@ export { NavBar, NavTitle, NavTouchableText, - SubNav + SubNav, + TabBar } diff --git a/package.json b/package.json index b7423e7..e15a3b4 100644 --- a/package.json +++ b/package.json @@ -36,35 +36,30 @@ "react-native-vector-icons": "^2.0.3" }, "devDependencies": { - "chai": "^3.5.0", - "enzyme": "^2.3.0", - "mocha": "^2.5.3", "autoprefixer": "^6.3.6", "babel-cli": "^6.8.0", "babel-core": "^6.9.1", "babel-loader": "^6.2.4", - "babel-plugin-transform-class-properties": "^6.9.1", - "babel-plugin-transform-object-assign": "^6.8.0", "babel-polyfill": "^6.9.1", - "babel-preset-es2015": "^6.6.0", - "babel-preset-react": "^6.5.0", - "babel-preset-stage-0": "^6.5.0", - "babel-preset-stage-1": "^6.5.0", + "babel-preset-react-native-stage-0": "^1.0.1", + "chai": "^3.5.0", "cookie-parser": "^1.4.2", "cookie-session": "^1.2.0", "css-loader": "^0.23.1", + "enzyme": "^2.3.0", "errorhandler": "^1.4.3", "express": "^4.13.4", "extract-text-webpack-plugin": "^1.0.1", "invariant": "^2.2.1", + "mocha": "^2.5.3", "morgan": "^1.7.0", "postcss-loader": "^0.9.1", "react": "^15.1.0", "react-addons-test-utils": "^15.1.0", "react-docgen": "^2.8.2", "react-dom": "^15.1.0", - "react-native-mock": "^0.2.3", "react-native": "^0.28.0", + "react-native-mock": "^0.2.3", "react-native-web": "git+https://github.com/bmcmahen/react-native-web.git", "rimraf": "^2.5.2", "style-loader": "^0.13.1",