diff --git a/README.md b/README.md index c930311..ef73d03 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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 `` component. If left blank, no background is rendered | +| background | NO | `null` | `renderable` | content to render as the background instead of an `` 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) | diff --git a/lib/ParallaxView.js b/lib/ParallaxView.js index 776bdb3..d5c29e6 100644 --- a/lib/ParallaxView.js +++ b/lib/ParallaxView.js @@ -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, @@ -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 ( - - {/* - !!blur && (BlurView || (BlurView = require('react-native-blur').BlurView)) && - - */} - - ); + if (background) { + return ( + + {background} + + ); + } else { + return ( + + {/* + !!blur && (BlurView || (BlurView = require('react-native-blur').BlurView)) && + + */} + + ); + } }, 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 ( @@ -147,7 +170,9 @@ var styles = StyleSheet.create({ background: { position: 'absolute', backgroundColor: '#2e2f31', - width: screen.width, + width: screen.width + }, + backgroundImage: { resizeMode: 'cover' }, blur: {