Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update The Package futures or ReadMe file #5

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 92 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@

<br/>

<p>We often need to customize our mobile application according to our brand style needs. The easiest solution is to grab some UI kit, make some fast customizations, add custom styling etc. But some components is hard for customizing. I mean progress-bars, you know. So this is react-native progress-bar component, which could be useful when you need to customize default progress-bar with different icons of current progress.</p>
<p>This feature could be really killer in you mobile application brand style. You could use icons from <a href="https://github.com/oblador/react-native-vector-icons">react-native-vector-icons</a> repo or even your own. Currently you have plane icon by default. Also cool thing is that you have animation from initial progress to the current progress value. So progress bar could be determinate or indeterminate. Useful when you need the progress indicator for some step by step activities.</p>
<p>Project uses React Native <a href="https://facebook.github.io/react-native/docs/animations.html">Animated API</a>. Each time you update props, you will see the animation of progress-bar. The project is in search for contributors.</p>
<p>We often need to customize our mobile application according to our brand style needs. The easiest solution is to grab some UI kit, make some fast customizations, add custom styling, etc. But some components are hard for customizing. I mean progress bars, you know. So this is the react-native progress-bar component, which could be useful when you need to customize the default progress bar with different icons of current progress.</p>
<p>This feature could be really killer in your mobile application brand style. You could use icons from <a href="https://github.com/oblador/react-native-vector-icons">react-native-vector-icons</a> repo or even your own. Currently, you have a plane icon by default. Also, the cool thing is that you have animation from the initial progress to the current progress value. So progress bar could be determinate or indeterminate. Useful when you need the progress indicator for some step-by-step activities.</p>
<p>Project uses React Native <a href="https://facebook.github.io/react-native/docs/animations.html">Animated API</a>. Each time you update props, you will see the animation of the progress bar. The project is in search of contributors.</p>

</br>

Expand All @@ -27,6 +27,7 @@

```
npm install react-native-air-progress-bar --save
npm i react-native-vector-icons
```

<h3 align='center'>Usage</h3>
Expand All @@ -39,8 +40,96 @@ import ProgressBar from 'react-native-air-progress-bar';
<ProgressBar progress={50} initialProgress={25} />
<ProgressBar progress={75} initialProgress={50} />
<ProgressBar progress={100} initialProgress={75} />
<ProgressBar
progress={60}
initialProgress={20}
barWidth="80%"
iconName={<MaterialCommunityIcons name="train-car-passenger" size={35} color="orange" />}
iconSize={35}
iconColor="orange"
hideIcon={false}
activeBarColor="orange"
inactiveBarColor="gray"
activeBarStyle={{ borderRadius: 10 }}
inactiveBarStyle={{ borderRadius: 10 }}
/>
```

<h3>Additional props</h3>
<table>
<thead>
<tr>
<th>Prop</th>
<th>Type</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>progress</td>
<td>PropTypes.number</td>
<td>The current progress value of the progress bar.</td>
</tr>
<tr>
<td>initialProgress</td>
<td>PropTypes.number</td>
<td>The initial progress value of the progress bar. Defaults to 25.</td>
</tr>
<tr>
<td>barWidth</td>
<td>PropTypes.oneOfType([PropTypes.number, PropTypes.string])</td>
<td>The width of the progress bar. It can be either a number (interpreted as a percentage of the screen width) or a string representing a valid CSS width value.</td>
</tr>
<tr>
<td>barHeight</td>
<td>PropTypes.oneOfType([PropTypes.number, PropTypes.string])</td>
<td>The height of the progress bar.</td>
</tr>
<tr>
<td>activeBarColor</td>
<td>PropTypes.string</td>
<td>The color of the active portion of the progress bar.</td>
</tr>
<tr>
<td>inactiveBarColor</td>
<td>PropTypes.string</td>
<td>The color of the inactive portion of the progress bar.</td>
</tr>
<tr>
<td>activeBarStyle</td>
<td>ViewPropTypes.style</td>
<td>Additional styles to apply to the active portion of the progress bar.</td>
</tr>
<tr>
<td>inactiveBarStyle</td>
<td>ViewPropTypes.style</td>
<td>Additional styles to apply to the inactive portion of the progress bar.</td>
</tr>
<tr>
<td>iconName</td>
<td>PropTypes.element</td>
<td>The render any component of the icon/Image to be displayed.</td>
</tr>
<tr>
<td>iconSize</td>
<td>PropTypes.number</td>
<td>The size of the icon.</td>
</tr>
<tr>
<td>iconColor</td>
<td>PropTypes.string</td>
<td>The color of the icon.</td>
</tr>
<tr>
<td>hideIcon</td>
<td>PropTypes.bool</td>
<td>A flag indicating whether to hide the icon.</td>
</tr>
</tbody>
</table>


<h3 align='center'>License</h3>

The MIT License (MIT) Copyright (c) 2017

185 changes: 89 additions & 96 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,108 +1,101 @@
import React, { Component } from 'react';
import { Animated, View, Text, StyleSheet, Dimensions } from 'react-native';
import React, { useEffect, useRef } from 'react';
import { Animated, View, StyleSheet, Dimensions, ViewPropTypes } from 'react-native';
import PropTypes from 'prop-types';
import Icon from 'react-native-vector-icons/Ionicons';

const { width:WIDTH, height:HEIGHT } = Dimensions.get('window');
const BAR_MARGIN = 30;
const RATIO = (WIDTH - (BAR_MARGIN * 2)) / 110;

const styles = StyleSheet.create({
bar: {
alignItems: 'center',
marginTop: 20
},

line: {
position: 'absolute',
width: WIDTH - 60,
top: 17,
borderWidth: 1,
borderColor: '#eeeeee',
alignSelf: 'flex-end',
}
});

export default class ProgressBar extends Component {
static propTypes = {
progress: PropTypes.number,
initialProgress: PropTypes.number,
additionalStyles: PropTypes.oneOfType([
PropTypes.object,
PropTypes.number
])
}

state = {
activeSegmentAnim: new Animated.Value(this.props.initialProgress || 0),
planeAnim: new Animated.Value(this.props.initialProgress || 0)
}

componentDidMount() {
this.animate(this.props.progress);
}

componentWillReceiveProps(nextProps) {
this.animate(nextProps.progress);
}

animate(progress) {
const { activeSegmentAnim, planeAnim } = this.state;
const activeSegmentWidth = RATIO * progress;
import Ionicons from 'react-native-vector-icons/Ionicons';

const { width: WIDTH } = Dimensions.get('window');

const ProgressBar = ({
barWidth = '100%',
barHeight = 5,
progress,
initialProgress = 0,
activeBarColor = '#9ed3c7',
inactiveBarColor = '#eeeeee',
activeBarStyle,
inactiveBarStyle,
iconName,
iconSize = 35,
iconColor = '#dbdbdb',
hideIcon = false,
}) => {
const activeSegmentAnim = useRef(new Animated.Value(initialProgress)).current;
const planeAnim = useRef(new Animated.Value(initialProgress)).current;

useEffect(() => {
animate(progress);
}, [progress, barWidth]);

const animate = (progress) => {
const convertedWidth = WIDTH * (parseFloat(barWidth) / 100);
const activeSegmentWidth = convertedWidth * (progress / 100);

Animated.parallel([
Animated.timing(activeSegmentAnim, {
toValue: activeSegmentWidth,
duration: 1000
duration: 1000,
useNativeDriver: false,
}),
Animated.timing(planeAnim, {
toValue: activeSegmentWidth,
duration: 1000
})
duration: 1000,
useNativeDriver: false,
}),
]).start();
}

render() {
const { progress, additionalStyles } = this.props;
const { activeSegmentAnim, planeAnim } = this.state;

const lineActive = {
position: 'absolute',
top: 17,
borderWidth: 1,
borderColor: '#9ed3c7',
alignSelf: 'flex-start',
transform: [{'translate':[0,0,1]}]
};

const planeStyles = {
position: 'absolute',
top: 0,
transform: [{'translate':[0,0,1]}]
};

return (
<View style={[styles.bar, {
marginLeft: BAR_MARGIN,
marginRight: BAR_MARGIN,
width: WIDTH
}, additionalStyles]}>

<Animated.View style={{
...lineActive,
width: activeSegmentAnim
}}></Animated.View>
};

<Animated.View style={{
...planeStyles,
left: planeAnim
}}>
<Icon name='ios-plane-outline' size={35} color="#dbdbdb" />
const lineActive = {
width: progress,
height: barHeight,
borderWidth: 1,
borderColor: activeBarColor,
backgroundColor: activeBarColor,
alignSelf: 'flex-start',
...activeBarStyle,
};

const lineInactive = {
height: barHeight,
width: barWidth,
borderWidth: 1,
borderColor: inactiveBarColor,
backgroundColor: inactiveBarColor,
alignSelf: 'center',
alignItems: 'center',
justifyContent: 'center',
...inactiveBarStyle,
};

const planeStyles = { position: 'absolute' };

return (
<View style={lineInactive} >
<Animated.View style={[styles.bar, lineActive, { width: activeSegmentAnim }]} />
{!hideIcon && (
<Animated.View style={[styles.iconContainer, planeStyles, { left: planeAnim }]}>
{iconName ?? <Ionicons name={'airplane'} size={iconSize} color={iconColor} />}
</Animated.View>
)}
</View>
);
};

ProgressBar.propTypes = {
progress: PropTypes.number,
initialProgress: PropTypes.number,
barWidth: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
barHeight: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
activeBarColor: PropTypes.string,
inactiveBarColor: PropTypes.string,
activeBarStyle: ViewPropTypes.style,
inactiveBarStyle: ViewPropTypes.style,
iconName: PropTypes.element,
iconSize: PropTypes.number,
iconColor: PropTypes.string,
hideIcon: PropTypes.bool,
};
export default ProgressBar;

<View style={styles.line}></View>

</View>
);
}
}
const styles = StyleSheet.create({
bar: { height: '100%', width: '100%' },
});