Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add FlatList's on end reached #2

Merged
merged 2 commits into from
Feb 5, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 5 additions & 14 deletions src/containers/PokeList/PokeList.container.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import PropTypes from 'prop-types';
import { bindActionCreators } from 'redux';
import { connect } from 'react-redux';
import styles from './PokeList.styles';
import Button from '../../components/Button/Button';
import { pokeListRequest } from './PokeList.actions';
import Pokemon from '../../components/Pokemon/Pokemon';
import PokemonDetailModal from './view/Pokemon.DetailModal.component';
Expand Down Expand Up @@ -44,8 +43,8 @@ class PokeList extends React.PureComponent {
return <Filter onFilterList={this.getPokeList} limit={this.props.limit} />;
};

renderLoadMore = () => {
if (LoadingStatus.moreLoading === this.props.loading) {
renderLoadingMore = () => {
if (LoadingStatus.moreLoading) {
return (
<ShimmerView
imgStyle={styles.shimmerImg}
Expand All @@ -54,16 +53,7 @@ class PokeList extends React.PureComponent {
/>
);
}
return (
<View style={styles.loadMoreBtnWrapper}>
<Button
btnStyle={styles.loadMoreBtn}
txtStyle={styles.loadMoreTxt}
title={'Load More'}
onPress={this.getPokeList}
/>
</View>
);
return null;
};

renderPokeItem = ({ item }) => {
Expand Down Expand Up @@ -96,8 +86,9 @@ class PokeList extends React.PureComponent {
renderItem={this.renderPokeItem}
extraData={loading}
ListHeaderComponent={this.renderFilter}
ListFooterComponent={this.renderLoadMore}
ListFooterComponent={this.renderLoadingMore}
keyExtractor={this.keyExtractor}
onEndReached={()=>this.getPokeList()}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

onEndReached={this.getPokeList}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a open issue in react-native: facebook/react-native#16067

There is a race condition and this implementation is a possible workaround to avoid a second onEndReached call.

@melihberberolu

/>
</View>
);
Expand Down