diff --git a/Example/index.android.js b/Example/index.android.js index a88bcdf..fac5340 100644 --- a/Example/index.android.js +++ b/Example/index.android.js @@ -1,47 +1,13 @@ -/** - * Sample React Native App - * https://github.com/facebook/react-native - */ -'use strict'; - -var React = require('react-native'); -var { +import React from 'react'; +import { AppRegistry, StyleSheet, Text, View, -} = React; -var Tabs = require('react-native-tabs'); - -class Example extends React.Component { - constructor(props){ - super(props); - this.state = {}; - } - render() { - var self = this; - return ( - - - Welcome to React Native! - - - Selected page: {this.state.page} - - - First - Second - Third - Fourth - Fifth - - - ); - } -} +} from 'react-native'; +import Tabs from 'react-native-tabs'; -var styles = StyleSheet.create({ +const styles = StyleSheet.create({ container: { flex: 1, justifyContent: 'center', @@ -60,4 +26,40 @@ var styles = StyleSheet.create({ }, }); +class Example extends React.Component { + constructor(props) { + super(props); + this.state = { page: 'second' }; + } + render() { + return ( + + this.setState({ page: el.props.name })} + pressOpacity={1} + > + First + + Second + + Third + Fourth + Fifth + + + Welcome to React Native + + + Selected page: {this.state.page} + + + ); + } +} + AppRegistry.registerComponent('Example', () => Example); diff --git a/Example/index.ios.js b/Example/index.ios.js index 193861d..fac5340 100644 --- a/Example/index.ios.js +++ b/Example/index.ios.js @@ -1,48 +1,13 @@ -/** - * Sample React Native App - * https://github.com/facebook/react-native - */ -'use strict'; - -var React = require('react-native'); -var { +import React from 'react'; +import { AppRegistry, StyleSheet, Text, View, -} = React; -var Tabs = require('react-native-tabs'); - -class Example extends React.Component { - constructor(props){ - super(props); - this.state = {page:'second'}; - } - render() { - var self = this; - return ( - - this.setState({page:el.props.name})} - pressOpacity={1}> - First - Second - Third - Fourth - Fifth - - - Welcome to React Native - - - Selected page: {this.state.page} - - - ); - } -} +} from 'react-native'; +import Tabs from 'react-native-tabs'; -var styles = StyleSheet.create({ +const styles = StyleSheet.create({ container: { flex: 1, justifyContent: 'center', @@ -61,4 +26,40 @@ var styles = StyleSheet.create({ }, }); +class Example extends React.Component { + constructor(props) { + super(props); + this.state = { page: 'second' }; + } + render() { + return ( + + this.setState({ page: el.props.name })} + pressOpacity={1} + > + First + + Second + + Third + Fourth + Fifth + + + Welcome to React Native + + + Selected page: {this.state.page} + + + ); + } +} + AppRegistry.registerComponent('Example', () => Example); diff --git a/index.js b/index.js index 6d82fe2..c9fb7fe 100644 --- a/index.js +++ b/index.js @@ -1,69 +1,92 @@ -'use strict'; - import React, { - Component + PropTypes, + Component, } from 'react'; - import { - StyleSheet, - View, - Text, - TouchableOpacity, + StyleSheet, + View, + Text, + TouchableOpacity, } from 'react-native'; +const styles = StyleSheet.create({ + tabbarView: { + position: 'absolute', + bottom: 0, + right: 0, + left: 0, + height: 50, + opacity: 1, + backgroundColor: 'transparent', + flexDirection: 'row', + justifyContent: 'center', + alignItems: 'center', + }, + iconView: { + flex: 1, + height: 50, + justifyContent: 'center', + alignItems: 'center', + }, +}); + +const propTypes = { + onSelect: PropTypes.func, + selected: PropTypes.string, + children: PropTypes.array, + style: View.propTypes.style, + iconStyle: Text.propTypes.style, + selectedIconStyle: Text.propTypes.style, + selectedStyle: Text.propTypes.style, +}; + class Tabs extends Component { - onSelect(el){ - if (el.props.onSelect) { - el.props.onSelect(el); - } else if (this.props.onSelect) { - this.props.onSelect(el); - } + + onSelect(el) { + if (el.props.onSelect) { + el.props.onSelect(el); + } else if (this.props.onSelect) { + this.props.onSelect(el); } + } - render(){ - const self = this; - let selected = this.props.selected - if (!selected){ - React.Children.forEach(this.props.children.filter(c=>c), el=>{ - if (!selected || el.props.initial){ - selected = el.props.name || el.key; - } - }); + render() { + const self = this; + let selected = this.props.selected; + if (!selected) { + React.Children.forEach(this.props.children.filter(c => c), el => { + if (!selected || el.props.initial) { + selected = el.props.name || el.key; } - return ( - - {React.Children.map(this.props.children.filter(c=>c),(el)=> - !self.props.locked && self.onSelect(el)} - onLongPress={()=>self.onSelect(el)} - activeOpacity={el.props.pressOpacity}> - {selected == (el.props.name || el.key) ? React.cloneElement(el, {selected: true, style: [el.props.style, this.props.selectedStyle, el.props.selectedStyle]}) : el} - - )} - - ); + }); } + return ( + + {React.Children.map(this.props.children.filter(c => c), (el) => + !self.props.locked && self.onSelect(el)} + onLongPress={() => self.onSelect(el)} + activeOpacity={el.props.pressOpacity} + > + {selected === (el.props.name || el.key) ? + React.cloneElement(el, { + selected: true, + style: [el.props.style, this.props.selectedStyle, el.props.selectedStyle], + }) : el + } + + )} + + ); + } } -var styles = StyleSheet.create({ - tabbarView: { - position:'absolute', - bottom:0, - right:0, - left:0, - height:50, - opacity:1, - backgroundColor:'transparent', - flexDirection: 'row', - justifyContent: 'center', - alignItems: 'center' - }, - iconView: { - flex: 1, - height: 50, - justifyContent: 'center', - alignItems: 'center', - } -}); -module.exports = Tabs; +Tabs.propTypes = propTypes; + +export default Tabs;