showScrollToTopView = () => {
const { showScrollToTopView } = this.state
const DEVICE_HEIGHT = Dimensions.get('window').height
if (this.scrolledValue >= 2 * DEVICE_HEIGHT - HEADER_HEIGHT && !showScrollToTopView) {
this.setState({
showScrollToTopView: true
})
} else if (this.scrolledValue <= DEVICE_HEIGHT - HEADER_HEIGHT && showScrollToTopView) {
this.setState({
showScrollToTopView: false
})
}
}
getKeyExtractor = (item, index) => {
return `${get(item, '_id', '')}`
}
renderFeedCardComponent = ({ item }) => {
return (
<CommunityCardComponent
cardType={'QUESTION_CARD'}
questionData={item}
onClickOptions={this.onClickOptions}
questionPopupOptionsKey={QUESTION_CARD_OPTIONS}
onLabelPressed={this.onLabelClicked}
/>
)
}
<FlatList
onScroll={Animated.event([{ nativeEvent: { contentOffset: { y: context.scrollYValue } } }], {
useNativeDriver: true,
listener: ({ nativeEvent }) => {
const yOffsetValue = get(nativeEvent, 'contentOffset.y', 0)
this.scrolledValue = yOffsetValue
{
this.showScrollToTopView()
}
if (getScrolledPosition) {
getScrolledPosition(yOffsetValue)
}
}
})}
refreshControl={
<RefreshControl
refreshing={shouldRefresh}
progressViewOffset={HEADER_HEIGHT}
onRefresh={() => {
handleNetworkAvailableEvent(this.onRefresh)
}}
/>
}
scrollEventThrottle={16}
ref={(ref) => {
if (ref) {
this.flatListRef = ref
if (getFlatListRef) {
getFlatListRef(ref)
}
context.addFlatListRef(this.flatListRef, uniqueKey)
}
}}
renderItem={this.renderFeedCardComponent}
keyExtractor={this.getKeyExtractor}
onMomentumScrollEnd={({ nativeEvent }) => {
const { contentOffset } = nativeEvent
if (contentOffset.y === 0) {
context.flatListRef.forEach((item) => {
if (item.key !== uniqueKey) {
item.value.scrollToOffset({
offset: 0,
animated: false
})
}
})
}
}}
listKey={moment().valueOf().toString()}
/>
Whenever my state changes the flatlist render Item is getting called. I have printed some logs while developing. Now I am using key extractor then why is my flatlist render item getting called. Can explain why is this happening.Now whenever my state changes my flatlist render Item is getting called. I have printed some log while doing development.