Skip to content

Commit 6e74f79

Browse files
committed
Use React.Children to iterate instead of .foreach
1 parent 9217c59 commit 6e74f79

File tree

1 file changed

+36
-36
lines changed

1 file changed

+36
-36
lines changed

src/index.js

+36-36
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, Image } from 'react-native'
2+
import { Animated, Dimensions, View, ViewPropTypes } from 'react-native'
33

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

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

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

16-
const noRender = () => <View style={{display: 'none'}} />
16+
const noRender = () => <View style={{ display: 'none' }} />
1717

1818
// Override `toJSON` of interpolated value because of
1919
// an error when serializing style on view inside inspector.
@@ -63,7 +63,7 @@ class ParallaxScrollView extends Component {
6363
viewWidth: window.width
6464
}
6565
this.scrollY = new Animated.Value(0)
66-
this._footerComponent = { setNativeProps() {} } // Initial stub
66+
this._footerComponent = { setNativeProps() { } } // Initial stub
6767
this._footerHeight = 0
6868
}
6969

@@ -181,7 +181,7 @@ class ParallaxScrollView extends Component {
181181
parallaxHeaderHeight,
182182
stickyHeaderHeight,
183183
onChangeHeaderVisibility,
184-
onScroll: prevOnScroll = e => {}
184+
onScroll: prevOnScroll = () => { }
185185
} = this.props
186186
this.props.scrollEvent && this.props.scrollEvent(e)
187187
const p = pivotPoint(parallaxHeaderHeight, stickyHeaderHeight)
@@ -243,10 +243,10 @@ class ParallaxScrollView extends Component {
243243
width: viewWidth,
244244
opacity: fadeOutBackground
245245
? interpolate(scrollY, {
246-
inputRange: [0, p * (1 / 2), p * (3 / 4), p],
247-
outputRange: [1, 0.3, 0.1, 0],
248-
extrapolate: 'clamp'
249-
})
246+
inputRange: [0, p * (1 / 2), p * (3 / 4), p],
247+
outputRange: [1, 0.3, 0.1, 0],
248+
extrapolate: 'clamp'
249+
})
250250
: 1,
251251
transform: [
252252
{
@@ -292,10 +292,10 @@ class ParallaxScrollView extends Component {
292292
height: parallaxHeaderHeight,
293293
opacity: fadeOutForeground
294294
? interpolate(scrollY, {
295-
inputRange: [0, p * (1 / 2), p * (3 / 4), p],
296-
outputRange: [1, 0.3, 0.1, 0],
297-
extrapolate: 'clamp'
298-
})
295+
inputRange: [0, p * (1 / 2), p * (3 / 4), p],
296+
outputRange: [1, 0.3, 0.1, 0],
297+
extrapolate: 'clamp'
298+
})
299299
: 1
300300
}
301301
]}
@@ -319,7 +319,7 @@ class ParallaxScrollView extends Component {
319319

320320
this.containerHeight = this.state.viewHeight;
321321

322-
children.forEach((item) => {
322+
React.Children.forEach(children, (item) => {
323323
if (item && Object.keys(item).length != 0) {
324324
this.containerHeight = 0;
325325
}
@@ -385,32 +385,32 @@ class ParallaxScrollView extends Component {
385385
>
386386
{renderStickyHeader
387387
? <Animated.View
388+
style={{
389+
backgroundColor: backgroundColor,
390+
height: stickyHeaderHeight,
391+
opacity: interpolate(scrollY, {
392+
inputRange: [0, p],
393+
outputRange: [0, 1],
394+
extrapolate: 'clamp'
395+
})
396+
}}
397+
>
398+
<Animated.View
388399
style={{
389-
backgroundColor: backgroundColor,
390-
height: stickyHeaderHeight,
391-
opacity: interpolate(scrollY, {
392-
inputRange: [0, p],
393-
outputRange: [0, 1],
394-
extrapolate: 'clamp'
395-
})
400+
transform: [
401+
{
402+
translateY: interpolate(scrollY, {
403+
inputRange: [0, p],
404+
outputRange: [stickyHeaderHeight, 0],
405+
extrapolate: 'clamp'
406+
})
407+
}
408+
]
396409
}}
397410
>
398-
<Animated.View
399-
style={{
400-
transform: [
401-
{
402-
translateY: interpolate(scrollY, {
403-
inputRange: [0, p],
404-
outputRange: [stickyHeaderHeight, 0],
405-
extrapolate: 'clamp'
406-
})
407-
}
408-
]
409-
}}
410-
>
411-
{renderStickyHeader()}
412-
</Animated.View>
411+
{renderStickyHeader()}
413412
</Animated.View>
413+
</Animated.View>
414414
: null}
415415
{renderFixedHeader && renderFixedHeader()}
416416
</View>
@@ -428,7 +428,7 @@ ParallaxScrollView.defaultProps = {
428428
backgroundColor: '#000',
429429
contentBackgroundColor: '#fff',
430430
fadeOutForeground: true,
431-
onChangeHeaderVisibility: () => {},
431+
onChangeHeaderVisibility: () => { },
432432
renderScrollComponent: props => <Animated.ScrollView {...props} />,
433433
renderBackground: renderEmpty,
434434
renderContentBackground: noRender,

0 commit comments

Comments
 (0)