Skip to content

Update index.js #1

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

Merged
merged 1 commit into from
Jan 22, 2018
Merged
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
53 changes: 34 additions & 19 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
import React, { Component } from "react";
import { StyleSheet, View, Image, Animated } from "react-native";
import React, { Component } from 'react';
import { StyleSheet, View, Image, Animated } from 'react-native';

import LinearGradient from "react-native-linear-gradient";
import LinearGradient from 'react-native-linear-gradient';

class ScrollIndicator extends Component {
static defaultProps = {
minScrollHeight: 0,
style: {},
scrollEnabled: true,
showIndicator: true,
picto: false
picto: false,
renderPicto: false,
linearGradientColors: ['transparent', '#212121'],
styleGradientBackground: {}
};

constructor(props) {
Expand All @@ -35,22 +38,31 @@ class ScrollIndicator extends Component {

render() {
const { scrollViewHeight, contentHeight, bottom } = this.state;
const { children, scrollEnabled, showIndicator, style, picto } = this.props;
const {
children,
scrollEnabled,
showIndicator,
style,
picto,
renderPicto,
linearGradientColors,
styleGradientBackground
} = this.props;
const maxValue = Math.max(contentHeight - scrollViewHeight, 0);
const slideViewBottom = bottom.interpolate({
inputRange: [0, maxValue],
outputRange: [0, 100],
extrapolate: "clamp"
extrapolate: 'clamp'
});

const slideViewTop = bottom.interpolate({
inputRange: [0, maxValue],
outputRange: [60, 100],
extrapolate: "clamp"
extrapolate: 'clamp'
});

return (
<View style={{ flex: 1, overflow: "hidden" }}>
<View style={{ flex: 1, overflow: 'hidden' }}>
{showIndicator && this.displayIndicator(false) ? (
<Animated.View
style={[
Expand All @@ -61,7 +73,7 @@ class ScrollIndicator extends Component {
]}
>
<LinearGradient
colors={["#212121", "transparent"]}
colors={['#212121', 'transparent']}
style={[styles.gradientBackground]}
/>
</Animated.View>
Expand Down Expand Up @@ -114,10 +126,13 @@ class ScrollIndicator extends Component {
]}
>
<LinearGradient
colors={["transparent", "#212121"]}
style={[styles.gradientBackground]}
colors={linearGradientColors}
style={[styles.gradientBackground, styleGradientBackground ]}
>
{picto ? <Image source={picto} /> : <View />}
<View>
{renderPicto && renderPicto()}
{!renderPicto && picto ? <Image source={picto} /> : <View />}
</View>
</LinearGradient>
</Animated.View>
) : null}
Expand All @@ -130,25 +145,25 @@ export default ScrollIndicator;

const styles = StyleSheet.create({
swipeWrapperTop: {
backgroundColor: "transparent",
position: "absolute",
backgroundColor: 'transparent',
position: 'absolute',
left: 0,
right: 0,
top: -160,
zIndex: 999
},
swipeWrapperBottom: {
backgroundColor: "transparent",
position: "absolute",
backgroundColor: 'transparent',
position: 'absolute',
left: 0,
right: 0,
bottom: 0,
zIndex: 999
},
gradientBackground: {
justifyContent: "center",
alignItems: "center",
justifyContent: 'center',
alignItems: 'center',
height: 100,
backgroundColor: "transparent"
backgroundColor: 'transparent'
}
});