GithubHelp home page GithubHelp logo

Comments (4)

HugoCerdeiraSkrey avatar HugoCerdeiraSkrey commented on June 13, 2024

It should be simple, you can set a flag to true on your state at the beginning of the loadMoreAsync function, and to false when it reaches its end.
In the render function if that flag is true you render the loading icon!

Hopefully, I helped, good luck!

from react-native-infinite-scroll-view.

dzpt avatar dzpt commented on June 13, 2024

@HugoCerdeiraSkrey what's flag? I've tried to set this.state.isLoading = true but didn't see any loading indicator showed

from react-native-infinite-scroll-view.

dimaportenko avatar dimaportenko commented on June 13, 2024

I'm using following
<ListView dataSource={this.dataSource} renderRow={this.renderRow} renderScrollComponent={props => <InfiniteScrollView {...props} />} canLoadMore={this.props.canLoadMoreContent} onLoadMoreAsync={this.loadMoreContentAsync} />

loadMoreContentAsync is invoked, but I don't see any activity indicator. Am I doing something wrong?

from react-native-infinite-scroll-view.

hqtoan94 avatar hqtoan94 commented on June 13, 2024

@troublediehard I think you're right based on the document. But the problem might be because ListView won't render when your rowData is the same (at the end of the list, number of rows is the same until onLoadMoreAsync finish). That's what i think, i'm not sure about that also.

And my solution for that is:

  • Modify the InfiniteScrollView class:
class InfiniteScrollViewCustom extends InfiniteScrollView {
    render() {
        let statusIndicator;

        //Here is what i did: Instead of waiting for a status to add statusIndicator to the end of this.props.children I added an Indicator element at the end of the children list.
        statusIndicator = React.cloneElement(
            this.props.renderLoadingIndicator(),
            { key: 'loading-indicator' },
        );

        if (this.state.isDisplayingError) {
            statusIndicator = React.cloneElement(
                this.props.renderLoadingErrorIndicator(
                    { onRetryLoadMore: this._loadMoreAsync }
                ),
                { key: 'loading-error-indicator' },
            );
        }

        let {
            renderScrollComponent,
            ...props,
        } = this.props;
        Object.assign(props, {
            onScroll: this._handleScroll,
            children: [this.props.children, statusIndicator],
        });

        console.log(props);

        return cloneReferencedElement(renderScrollComponent(props), {
            ref: component => { this._scrollComponent = component; },
        });
    }
}
  • Set renderLoadingIndicator property and use the flag in here:
<ListView
      renderScrollComponent={props => <InfiniteScrollViewCustom renderLoadingIndicator={() => this.state.loading ? <ActivityIndicator style={{ marginTop: 10 }}/> : <View/>} {...props} />}
      dataSource={...}
      renderRow={...}
      canLoadMore={...}
      onLoadMoreAsync={...} />

So that we always have a child at the end of this.props.children and the Indicator will appear when the flag is true.

Here is my first solution, that might be a trick than a solution, but hope that helps somebody.

from react-native-infinite-scroll-view.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.