Skip to content

Commit e46d161

Browse files
committed
renderContentBackground added
1 parent 861aeeb commit e46d161

1 file changed

Lines changed: 19 additions & 3 deletions

File tree

src/index.js

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React, { Component } from 'react'
2-
import { Animated, Dimensions, ScrollView, View, ViewPropTypes } from 'react-native'
2+
import { Animated, Dimensions, ScrollView, View, ViewPropTypes, Image } from 'react-native'
33

44
const styles = require('./styles')
55

@@ -13,6 +13,8 @@ const pivotPoint = (a, b) => a - b
1313

1414
const renderEmpty = () => <View />
1515

16+
const noRender = () => <View style={{display: 'none'}} />
17+
1618
// Override `toJSON` of interpolated value because of
1719
// an error when serializing style on view inside inspector.
1820
// See: https://github.com/jaysoo/react-native-parallax-scroll-view/issues/23
@@ -32,6 +34,7 @@ const IPropTypes = {
3234
onChangeHeaderVisibility: func,
3335
parallaxHeaderHeight: number.isRequired,
3436
renderBackground: func,
37+
renderContentBackground: func,
3538
renderFixedHeader: func,
3639
renderForeground: func,
3740
renderScrollComponent: func,
@@ -79,6 +82,7 @@ class ParallaxScrollView extends Component {
7982
fadeOutBackground,
8083
parallaxHeaderHeight,
8184
renderBackground,
85+
renderContentBackground,
8286
renderFixedHeader,
8387
renderForeground,
8488
renderParallaxHeader,
@@ -109,6 +113,7 @@ class ParallaxScrollView extends Component {
109113
const bodyComponent = this._wrapChildren(children, {
110114
contentBackgroundColor,
111115
stickyHeaderHeight,
116+
renderContentBackground,
112117
contentContainerStyle
113118
})
114119
const footerSpacer = this._renderFooterSpacer({ contentBackgroundColor })
@@ -305,16 +310,25 @@ class ParallaxScrollView extends Component {
305310

306311
_wrapChildren(
307312
children,
308-
{ contentBackgroundColor, stickyHeaderHeight, contentContainerStyle }
313+
{ contentBackgroundColor, stickyHeaderHeight, contentContainerStyle, renderContentBackground }
309314
) {
310315
const { viewHeight } = this.state
311316
const containerStyles = [{ backgroundColor: contentBackgroundColor }]
312317

313318
if (contentContainerStyle) containerStyles.push(contentContainerStyle)
314319

320+
this.containerHeight = this.state.viewHeight;
321+
322+
children.forEach((item) => {
323+
console.log(item);
324+
if (item && Object.keys(item).length != 0) {
325+
this.containerHeight = 0;
326+
}
327+
});
328+
315329
return (
316330
<View
317-
style={containerStyles}
331+
style={[containerStyles, { minHeight: this.containerHeight }]}
318332
onLayout={e => {
319333
// Adjust the bottom height so we can scroll the parallax header all the way up.
320334
const { nativeEvent: { layout: { height } } } = e
@@ -330,6 +344,7 @@ class ParallaxScrollView extends Component {
330344
}
331345
}}
332346
>
347+
{renderContentBackground()}
333348
{children}
334349
</View>
335350
)
@@ -417,6 +432,7 @@ ParallaxScrollView.defaultProps = {
417432
onChangeHeaderVisibility: () => {},
418433
renderScrollComponent: props => <Animated.ScrollView {...props} />,
419434
renderBackground: renderEmpty,
435+
renderContentBackground: noRender,
420436
renderParallaxHeader: renderEmpty, // Deprecated (will be removed in 0.18.0)
421437
renderForeground: null,
422438
stickyHeaderHeight: 0,

0 commit comments

Comments
 (0)