Skip to content
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
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ NOTE: I will put up an rnplay.org working example whenever they support React Na

## Example

There is a working example in the project `/example` folder that you can check out. Remember to run npm install inside
There is a working example in the project `/example` folder that you can check out. Remember to run npm install inside
the example folder if you'd like to run that project.

```bash
Expand Down Expand Up @@ -50,6 +50,7 @@ Additionally, here is an example of the usage
| Prop | Required | Default | Type | Description |
| :------------ |:---:|:---------------:| :---------------:| :-----|
| backgroundSource | YES | `null` | `object` | the `source` prop that get's passed to the background `<Image>` component. If left blank, no background is rendered |
| background | NO | `null` | `renderable` | content to render as the background instead of an `<Image>` component. This may be used instead of specifying `backgroundSource` |
| header | NO | `null` | `renderable` | any content you want to render on top of the image. This content's opacity get's animated down as the scrollview scrolls up. (optional) |
| windowHeight | NO | `300` | `number` | the resting height of the header image. If 0 is passed in, the background is not rendered. |
| scrollableViewStyle | NO | `null` | `object` | this style will be mixed (overriding existing fields) with scrollable view style (view which is scrolled over the background) |
Expand Down
81 changes: 53 additions & 28 deletions lib/ParallaxView.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ var ParallaxView = React.createClass({
propTypes: {
...ScrollViewPropTypes,
windowHeight: React.PropTypes.number,
background: React.PropTypes.node,
backgroundSource: React.PropTypes.oneOfType([
React.PropTypes.shape({
uri: React.PropTypes.string,
Expand Down Expand Up @@ -63,40 +64,62 @@ var ParallaxView = React.createClass({
},

renderBackground: function () {
var { windowHeight, backgroundSource, blur } = this.props;
var { windowHeight, backgroundSource, background, blur } = this.props;
var { scrollY } = this.state;
if (!windowHeight || !backgroundSource) {
if (!windowHeight || (!backgroundSource && !background)) {
return null;
}
return (
<Animated.Image
style={[styles.background, {
height: windowHeight,
transform: [{
translateY: scrollY.interpolate({
inputRange: [ -windowHeight, 0, windowHeight],
outputRange: [windowHeight/2, 0, -windowHeight/3]
})
},{
scale: scrollY.interpolate({
inputRange: [ -windowHeight, 0, windowHeight],
outputRange: [2, 1, 1]
})
}]
}]}
source={backgroundSource}>
{/*
!!blur && (BlurView || (BlurView = require('react-native-blur').BlurView)) &&
<BlurView blurType={blur} style={styles.blur} />
*/}
</Animated.Image>
);
if (background) {
return (
<Animated.View
style={[styles.background, {
height: windowHeight,
transform: [{
translateY: scrollY.interpolate({
inputRange: [ -windowHeight, 0, windowHeight],
outputRange: [windowHeight/2, 0, -windowHeight/3]
})
},{
scale: scrollY.interpolate({
inputRange: [ -windowHeight, 0, windowHeight],
outputRange: [2, 1, 1]
})
}]
}]}>
{background}
</Animated.View>
);
} else {
return (
<Animated.Image
style={[styles.background, styles.backgroundImage, {
height: windowHeight,
transform: [{
translateY: scrollY.interpolate({
inputRange: [ -windowHeight, 0, windowHeight],
outputRange: [windowHeight/2, 0, -windowHeight/3]
})
},{
scale: scrollY.interpolate({
inputRange: [ -windowHeight, 0, windowHeight],
outputRange: [2, 1, 1]
})
}]
}]}
source={backgroundSource}>
{/*
!!blur && (BlurView || (BlurView = require('react-native-blur').BlurView)) &&
<BlurView blurType={blur} style={styles.blur} />
*/}
</Animated.Image>
);
}
},

renderHeader: function () {
var { windowHeight, backgroundSource } = this.props;
var { windowHeight, backgroundSource, background } = this.props;
var { scrollY } = this.state;
if (!windowHeight || !backgroundSource) {
if (!windowHeight || (!backgroundSource && !background)) {
return null;
}
return (
Expand Down Expand Up @@ -147,7 +170,9 @@ var styles = StyleSheet.create({
background: {
position: 'absolute',
backgroundColor: '#2e2f31',
width: screen.width,
width: screen.width
},
backgroundImage: {
resizeMode: 'cover'
},
blur: {
Expand Down