Skip to content

Commit f74b985

Browse files
committed
Merge pull request i6mi6#13 from stashimi/feature/fadeout-background
Added 'fadeOutBackground' property which works the same way as 'fadeOutForeground'
2 parents 44c835d + bd3d0a4 commit f74b985

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/index.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ const IPropTypes = {
2424
backgroundColor: string,
2525
backgroundScrollSpeed: number,
2626
fadeOutForeground: bool,
27+
fadeOutBackground: bool,
2728
contentBackgroundColor: string,
2829
onChangeHeaderVisibility: func,
2930
parallaxHeaderHeight: number.isRequired,
@@ -60,6 +61,7 @@ class ParallaxScrollView extends Component {
6061
children,
6162
contentBackgroundColor,
6263
fadeOutForeground,
64+
fadeOutBackground,
6365
parallaxHeaderHeight,
6466
renderBackground,
6567
renderFixedHeader,
@@ -72,7 +74,7 @@ class ParallaxScrollView extends Component {
7274
...scrollViewProps
7375
} = this.props;
7476

75-
const background = this._renderBackground({ backgroundScrollSpeed, backgroundColor, parallaxHeaderHeight, stickyHeaderHeight, renderBackground });
77+
const background = this._renderBackground({ fadeOutBackground, backgroundScrollSpeed, backgroundColor, parallaxHeaderHeight, stickyHeaderHeight, renderBackground });
7678
const foreground = this._renderForeground({ fadeOutForeground, parallaxHeaderHeight, stickyHeaderHeight, renderForeground: renderForeground || renderParallaxHeader });
7779
const bodyComponent = this._wrapChildren(children, { contentBackgroundColor, stickyHeaderHeight });
7880
const footerSpacer = this._renderFooterSpacer({ contentBackgroundColor });
@@ -168,7 +170,7 @@ class ParallaxScrollView extends Component {
168170
}
169171
}
170172

171-
_renderBackground({ backgroundScrollSpeed, backgroundColor, parallaxHeaderHeight, stickyHeaderHeight, renderBackground }) {
173+
_renderBackground({ fadeOutBackground, backgroundScrollSpeed, backgroundColor, parallaxHeaderHeight, stickyHeaderHeight, renderBackground }) {
172174
const { viewWidth, viewHeight, scrollY } = this.state;
173175
const p = pivotPoint(parallaxHeaderHeight, stickyHeaderHeight);
174176
return (
@@ -177,6 +179,13 @@ class ParallaxScrollView extends Component {
177179
backgroundColor: backgroundColor,
178180
height: parallaxHeaderHeight,
179181
width: viewWidth,
182+
opacity: fadeOutBackground
183+
? scrollY.interpolate({
184+
inputRange: [0, p * (1/2), p * (3/4), p],
185+
outputRange: [1, 0.3, 0.1, 0],
186+
extrapolate: 'clamp'
187+
})
188+
: 1,
180189
transform: [{
181190
translateY: scrollY.interpolate({
182191
inputRange: [0, p],

0 commit comments

Comments
 (0)