Skip to content

Commit 31d426a

Browse files
committed
handle foreground
1 parent e68faeb commit 31d426a

File tree

2 files changed

+60
-40
lines changed

2 files changed

+60
-40
lines changed

src/index.js

Lines changed: 58 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -222,14 +222,14 @@ class ParallaxScrollView extends Component {
222222
}
223223

224224
_renderBackground({
225-
fadeOutBackground,
226-
backgroundScrollSpeed,
227-
backgroundColor,
228-
parallaxHeaderHeight,
229-
stickyHeaderHeight,
230-
renderBackground,
231-
outputScaleValue
232-
}) {
225+
fadeOutBackground,
226+
backgroundScrollSpeed,
227+
backgroundColor,
228+
parallaxHeaderHeight,
229+
stickyHeaderHeight,
230+
renderBackground,
231+
outputScaleValue
232+
}) {
233233
const { viewWidth, viewHeight } = this.state
234234
const { scrollY } = this
235235
const p = pivotPoint(parallaxHeaderHeight, stickyHeaderHeight)
@@ -276,35 +276,55 @@ class ParallaxScrollView extends Component {
276276
}
277277

278278
_renderForeground({
279-
fadeOutForeground,
280-
parallaxHeaderHeight,
281-
stickyHeaderHeight,
282-
renderForeground
283-
}) {
279+
fadeOutForeground,
280+
parallaxHeaderHeight,
281+
stickyHeaderHeight,
282+
renderForeground
283+
}) {
284+
const { viewWidth, viewHeight } = this.state
284285
const { scrollY } = this
285286
const p = pivotPoint(parallaxHeaderHeight, stickyHeaderHeight)
286287
return (
287-
<View style={styles.parallaxHeaderContainer}>
288-
<Animated.View
289-
style={[
290-
styles.parallaxHeader,
291-
{
292-
height: parallaxHeaderHeight,
293-
opacity: fadeOutForeground
294-
? interpolate(scrollY, {
295-
inputRange: [0, p * (1 / 2), p * (3 / 4), p],
296-
outputRange: [1, 0.3, 0.1, 0],
288+
289+
<Animated.View
290+
style={[
291+
styles.parallaxHeader,
292+
{
293+
backgroundColor: 'white',
294+
height: parallaxHeaderHeight,
295+
width: viewWidth,
296+
opacity: fadeOutForeground
297+
? interpolate(scrollY, {
298+
inputRange: [0, p * (1 / 2), p * (3 / 4), p],
299+
outputRange: [1, 0.3, 0.1, 0],
300+
extrapolate: 'clamp'
301+
})
302+
: 1,
303+
transform: [
304+
{
305+
translateY: interpolate(scrollY, {
306+
inputRange: [0, p],
307+
outputRange: [0, -(p / 100)],
308+
extrapolateRight: 'extend',
309+
extrapolateLeft: 'clamp'
310+
})
311+
},
312+
{
313+
scale: interpolate(scrollY, {
314+
inputRange: [-viewHeight, 0],
315+
outputRange: [5 * 1.5, 1],
297316
extrapolate: 'clamp'
298317
})
299-
: 1
300-
}
301-
]}
302-
>
303-
<View style={{ height: parallaxHeaderHeight }}>
304-
{renderForeground()}
305-
</View>
306-
</Animated.View>
307-
</View>
318+
}
319+
]
320+
}
321+
]}
322+
>
323+
<View >
324+
{renderForeground()}
325+
</View>
326+
</Animated.View>
327+
308328
)
309329
}
310330

@@ -363,12 +383,12 @@ class ParallaxScrollView extends Component {
363383
}
364384

365385
_maybeRenderStickyHeader({
366-
parallaxHeaderHeight,
367-
stickyHeaderHeight,
368-
backgroundColor,
369-
renderFixedHeader,
370-
renderStickyHeader
371-
}) {
386+
parallaxHeaderHeight,
387+
stickyHeaderHeight,
388+
backgroundColor,
389+
renderFixedHeader,
390+
renderStickyHeader
391+
}) {
372392
const { viewWidth } = this.state
373393
const { scrollY } = this
374394
if (renderStickyHeader || renderFixedHeader) {

src/styles.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ const styles = StyleSheet.create({
66
backgroundColor: 'transparent'
77
},
88
parallaxHeaderContainer: {
9-
backgroundColor: 'transparent',
10-
overflow: 'hidden'
9+
// backgroundColor: 'transparent',
10+
// overflow: 'hidden'
1111
},
1212
parallaxHeader: {
1313
backgroundColor: 'transparent',

0 commit comments

Comments
 (0)