Last active
September 23, 2016 10:45
-
-
Save yeknava/4a3255c0e917e6f75de48a8c83258397 to your computer and use it in GitHub Desktop.
React Native Progress Bar Component
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ```` | |
| import React, { Component } from 'react'; | |
| import { Text, View, StyleSheet } from 'react-native'; | |
| export default class ProgressBar extends Component { | |
| constructor(props) { | |
| super(props); | |
| this.state = { | |
| }; | |
| } | |
| render() { | |
| var color = this.props.color; | |
| var percentage = this.props.percentage; | |
| var emptyProgressBar = parseFloat(1-this.props.percentage); | |
| var direction = this.props.direction == 'right' || this.props.direction == 'rtl' ? 'row-reverse' : 'row'; | |
| return ( | |
| <View style={[styles.progress, {flexDirection:direction}]}> | |
| <View | |
| style={[styles.progressBar, {flex:percentage, backgroundColor:color}]}> | |
| <Text style={styles.text}> | |
| {this.props.title} | |
| </Text> | |
| </View> | |
| <View | |
| style={[styles.emptyProgressBar, {flex:emptyProgressBar}]}> | |
| </View> | |
| </View> | |
| ); | |
| } | |
| }; | |
| var styles = StyleSheet.create({ | |
| progress: { | |
| height: 20, | |
| marginBottom: 20, | |
| overflow: 'hidden', | |
| backgroundColor: '#f5f5f5', | |
| borderRadius: 4, | |
| flex: 1, | |
| alignItems: 'stretch', | |
| flexDirection: 'row' | |
| }, | |
| progressBar: { | |
| backgroundColor: 'red', | |
| alignItems: 'center', | |
| borderRadius: 4, | |
| }, | |
| emptyProgressBar: { | |
| backgroundColor: '#f5f5f5', | |
| borderRadius: 4, | |
| }, | |
| text: { | |
| color: '#fff', | |
| } | |
| }); | |
| ```` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment