Background image load slowly in react native

前端 未结 1 1852
后悔当初
后悔当初 2021-02-14 22:37

I use an image for background like this


  {this.renderHeader(navigation)}
  {this.renderCo         


        
1条回答
  •  滥情空心
    2021-02-14 22:57

    Because images in RN are decoded natively in a separate thread.

    Image decoding can take more than a frame-worth of time. This is one of the major sources of frame drops on the web because decoding is done in the main thread.

    So RN displaying the placeholder for a few more frames while it is decoding the images used in components, then show them at different times after each individual image has loaded (instead of waiting then show the whole component at once when it's ready).

    See: Off-thread Decoding

    Note

    Images are loaded differently in development/debugging and "real" production. During local debugging the images will be served over HTTP from the packager server, whereas in production they will be bundled with the app.

    Solution

    Try doing a production build (full release build) on device to see if it's actually a problem or just a development mode side effect.

    Or try the workaround from this issue

    componentWillMount() {
        this.image = ();
    }
    

    and in your render() function:

    render() {
        return(
            
                {this.image}
            
        );
    }
    

    0 讨论(0)
提交回复
热议问题