Skip to content

Commit 4316d5c

Browse files
authored
Merge pull request #8 from zachgibson/feature/progress-bar
Feature/progress bar
2 parents f20feab + f40e990 commit 4316d5c

File tree

2 files changed

+67
-0
lines changed

2 files changed

+67
-0
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ __Features__
99
- __Flexible.__ Pass your own Animated.Value and use that value for both ParallaxSwiper and your own UI.
1010
- __Performant.__ Leverages useNativeDriver for 60FPS and no latency.
1111
- __Cross-platform.__ Implement your parallax on both iOS and Android.
12+
- __Progress Bar.__ Horizontal or vertical progress bar.
1213

1314
![Twitter Moments Demo](https://user-images.githubusercontent.com/10658888/30244667-636cfc0e-9588-11e7-9805-3a0c5649ab4b.gif)
1415
![Vevo Demo](https://user-images.githubusercontent.com/10658888/30244668-66164c3a-9588-11e7-9cfa-c0c5dc29090c.gif)
@@ -49,6 +50,7 @@ constructor() {
4950
dividerColor="black"
5051
backgroundColor="#fff"
5152
onMomentumScrollEnd={activePageIndex => console.log(activePageIndex)}
53+
showProgressBar={true}
5254
>
5355
<ParallaxSwiperPage
5456
BackgroundComponent={<FireVideoComponent />}
@@ -79,6 +81,10 @@ constructor() {
7981
| __`showsHorizontalScrollIndicator`__ | _Boolean_ | `false` | When true, shows a horizontal scroll indicator. The default value is false. |
8082
| __`showsVerticalScrollIndicator`__ | _Boolean_ | `false` | When true, shows a vertical scroll indicator. The default value is false. |
8183
| __`children`__ | _React component (ParallaxSwiperPage)_ | `N/A` | Each top-level ParallaxSwiperPage child. |
84+
| __`showProgressBar`__ | _Boolean_ | false | When true, a progress bar will render on bottom for horizontal and left on vertical. |
85+
| __`progressBarThickness`__ | _Number_ | 4 | Thickness translates to height for horizontal and width for vertical progress bar. |
86+
| __`progressBarBackgroundColor`__ | _String_ | `rgba(255,255,255,0.25)` | Background color of progress bar background. |
87+
| __`progressBarValueBackgroundColor`__ | _String_ | `white` | Background color of progress bar value background. |
8288

8389
## ParallaxSwiperPage Props
8490
| Prop | Type | Default | Description |

src/ParallaxSwiper.js

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@ class ParallaxSwiper extends Component {
7171
vertical,
7272
animatedValue,
7373
scrollEnabled,
74+
showProgressBar,
75+
progressBarThickness,
76+
progressBarBackgroundColor,
77+
progressBarValueBackgroundColor,
7478
} = this.props;
7579

7680
return (
@@ -137,6 +141,52 @@ class ParallaxSwiper extends Component {
137141
);
138142
})}
139143
</Animated.ScrollView>
144+
{showProgressBar && (
145+
<View
146+
style={{
147+
width: vertical ? progressBarThickness : this.state.width,
148+
height: vertical ? this.state.height : progressBarThickness,
149+
top: vertical ? -this.state.height : -progressBarThickness,
150+
backgroundColor: progressBarBackgroundColor,
151+
}}
152+
>
153+
<Animated.View
154+
style={[
155+
styles.progressBar,
156+
{
157+
backgroundColor: progressBarValueBackgroundColor,
158+
transform: [
159+
{
160+
translateX: vertical
161+
? 0
162+
: animatedValue.interpolate({
163+
inputRange: [
164+
0,
165+
(this.state.width + dividerWidth) *
166+
(children.length - 1),
167+
],
168+
outputRange: [-this.state.width, 0],
169+
extrapolate: 'clamp',
170+
}),
171+
},
172+
{
173+
translateY: vertical
174+
? animatedValue.interpolate({
175+
inputRange: [
176+
0,
177+
this.state.height * (children.length - 1),
178+
],
179+
outputRange: [-this.state.height, 0],
180+
extrapolate: 'clamp',
181+
})
182+
: 0,
183+
},
184+
],
185+
},
186+
]}
187+
/>
188+
</View>
189+
)}
140190
</View>
141191
);
142192
}
@@ -146,6 +196,9 @@ const styles = StyleSheet.create({
146196
pageOuterContainer: {
147197
flexDirection: 'row',
148198
},
199+
progressBar: {
200+
...StyleSheet.absoluteFillObject,
201+
},
149202
});
150203

151204
ParallaxSwiper.propTypes = {
@@ -174,6 +227,10 @@ ParallaxSwiper.propTypes = {
174227
animatedValue: PropTypes.instanceOf(Animated.Value),
175228
scrollEnabled: PropTypes.bool,
176229
scrollToIndex: PropTypes.number,
230+
showProgressBar: PropTypes.bool,
231+
progressBarThickness: PropTypes.number,
232+
progressBarBackgroundColor: PropTypes.string,
233+
progressBarValueBackgroundColor: PropTypes.string,
177234
};
178235

179236
ParallaxSwiper.defaultProps = {
@@ -188,6 +245,10 @@ ParallaxSwiper.defaultProps = {
188245
onMomentumScrollEnd: () => null,
189246
scrollToIndex: 0,
190247
scrollEnabled: true,
248+
showProgressBar: false,
249+
progressBarThickness: 4,
250+
progressBarBackgroundColor: 'rgba(255,255,255,0.25)',
251+
progressBarValueBackgroundColor: 'white',
191252
};
192253

193254
export default ParallaxSwiper;

0 commit comments

Comments
 (0)