Code Monkey home page Code Monkey logo

react-native-lazyload's Introduction

react-native-lazyload


A `lazyload` components suit for React Native.

Install

npm install react-native-lazyload

Components

Component Description
LazyloadScrollView A lazyload container component based on ScrollView
LazyloadListView A lazyload container component based on ListView
LazyloadView Based on View component. This component`s content won`t be rendered util it scrolls into sight. It should be inside a LazyloadScrollView or LazyloadListView which has the same name prop as this component`s host prop.
LazyloadImage Based on Image component. The image content won`t be rendered util it scrolls into sight. It should be inside a LazyloadScrollView or LazyloadListView which has the same name prop as this component`s host prop.

Usage

LazyloadScrollView
  1. Using LazyloadScrollView instead of ScrollView, and specify a unique id for name prop.
  2. Layout the views or images which will be lazyloaded by using LazyloadView and LazyloadImage instead of View or Image.
  3. Specify host prop for every LazyloadView and LazyloadImage, the host prop should be same as outer LazyloadScrollView component`s name prop.
import React, {
    Component
} from 'react-native';

import {
    LazyloadScrollView,
    LazyloadView,
    LazyloadImage
} from 'react-native-lazyload';

const list = [...list data here]; // many rows

class LazyloadScrollViewExample extends Component{
    render() {
        return (
            <LazyloadScrollView
                style={styles.container}
                contentContainerStyle={styles.content}
                name="lazyload-list"
            >
                {list.map((file, i) => <View
                    key={i}
                    style={styles.view}
                >
                    <LazyloadView
                        host="lazyload-list"
                        style={styles.file}
                    >
                        <View style={styles.id}>
                            <Text style={styles.idText}>{file.id}</Text>
                        </View>
                        <View style={styles.detail}>
                            <Text style={styles.name}>{file.first_name} {file.last_name}</Text>
                            <Text><Text style={styles.title}>email: </Text><Text style={styles.email}>{file.email}</Text></Text>
                            <Text style={styles.ip}><Text style={styles.title}>last visit ip: </Text>{file.ip_address}</Text>
                        </View>
                    </LazyloadView>
                    <View style={styles.avatar}>
                        <LazyloadImage
                            host="lazyload-list"
                            style={styles.avatarImage}
                            source={file.avatar}
                        />
                    </View>
                </View>)}
            </LazyloadScrollView>
        );
    }
}
LazyloadListView

Same as ListView. But it won`t render LazyloadView and LazyloadImage inside it, util they are scrolled into sight.

Additional Methods

refresh - Force to trigger an update. Useful after nagivation pop/push where the memory may have been release.

Additional Props

Components that extend LazyloadView can accept a prop (function) to be called when the item's visibility changes.

onVisibilityChange - An optional function to be called with the new visibility, ref, and props

Example:


<LazyloadView onVisibilityChange={ this.handleItemVisibility }>
...
</LazyloadView>

...

handleItemVisibility(visibility, ref, props) {
    console.log('visibility, ref, props', visibility, ref, props);
}

Run Example

Clone this repository from Github and cd to 'Example' directory then run npm install.

react-native-lazyload's People

Contributors

gedzis avatar jeffhampton avatar magicismight avatar shidhincr avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

react-native-lazyload's Issues

Any examples of how to use the method "refresh"?

Hello,

I'm having an issue using the plugin. I have a LazyloadScrollView with an infinite scroll with multiple LazyloadImage items inside. The first time that i open the app, the images are being loaded correctly, however if i change to a different screen (using react-native-router-flux) and then i return to the main screen, the images are no been loaded, the rest of the contect is loaded properly, i mean there are no issues fetching the data or anything else. I was wondering if i can use the "refresh" method to handle this. Does anyone there has an example of how to implement/use the refresh method referenced on the docs of the plugin, thanks.

Touchable child must either be native or forward setNativeProps to a native component

code:

  • If I put LazyloadView under the TouchableHighlight,Debugger will throw the error
    Unhandled JS Exception: Touchable child must either be native or forward setNativeProps to a native component
    My Code:
<TouchableHighlight
  style={{flex:1}}
  onPress={this._onPressRow.bind(this, element, sectionID, rowID)}>
  <LazyloadView
        host="feature_detail_LazyloadListView"
        style={[styles.row,{height: height}]}>
   <Text>Some Text</Text>
   </LazyloadView>
</TouchableHighlight>

qq20160519-0

How to fix it ?

Thanks

ReferenceError raised when running the example

Dev Environment

  • OS: Windows 10
  • Node: 6.7.0
  • npm: 4.0.3
  • react-native: 0.32.1
  • emulator: Nexus 5x API 23

Bug

Even though running react-native run-android gives "BUILD SUCCESSFUL" as response, the example app crashes on startup. It says it can't find variable: process, but I didn't manage to find where this one is used, so I couldn't fix it on my own.

Screen

screen

lazy loading after 5 lazyloadview

How can i lazyload my lazyloadview after 5 visibility
so then i wish it can show load more in 5 visibility and then showing it again 5 visibility then 5 visibilty again
thank you

"host" property throws exception

When passing host=nameofthelistview react throws such error:
simulator screen shot 16 sep 2016 22 56 54

using as such:

<LazyloadListView
      name="lazy-load-listview"
      stickyHeaderIndices={[0]}
      renderDistance={100}
      pageSize={1}
      enableEmptySections={true}
      initialListSize={10}
      scrollRenderAheadDistance={50}
      automaticallyAdjustContentInsets={true}
      dataSource={dataSource}
      renderRow={this._renderRow}
      contentContainerStyle={AppStyles.paddingBottom}
      style={{backgroundColor: 'transparent'}}
      refreshControl={
        <RefreshControl
          refreshing={this.props.isFetching}
          onRefresh={this._fetchData}
          style={{backgroundColor: 'transparent'}}
          tintColor={AppConfig.primaryColor} />
      }
      />

and in renderRow:

_renderRow = (data) => {
    let { name, image_link } = data;
       return (
        <RowComponent
          title={name}
          image={image_link}
          onPress={()=>{
            Actions.anotherView()
          }}>
        </RowComponent>
    );
  }

and in the RowComponent:
<LazyloadImage source={{uri: image}} style={styles.imageBackground_image} host="lazy-load-listview">

Isolate from scrollview

Hello,

Maybe if you can isolate lazyimage component from lazyscrollview its very amazing.

Thanks

Exporting local "_default", which is not declared

../node_modules/react-native-lazyload/lib/LazyloadChild.js: Exporting local "_default", which is not declared. (This is an error on an internal node. Probably an internal error.)

I fixed changing in LazyloadChild.js

export default class {
to
export default class LazyloadChild {

react-native-cli: 2.0.1
react-native: 0.56.0
react: ^16.4.1

'container.contentOffset={x:x,y:y}' is null

if I push one page after another page then I want to pop first page (first page have lazyload) then have a problem. it is
[error][tid:com.facebook.react.JavaScript] null is not an object (evaluating 'container.contentOffset={x:x,y:y}') 2017-08-13 00:21:21.290 [fatal][tid:com.facebook.react.ExceptionsManagerQueue] Unhandled JS Exception: null is not an object (evaluating 'container.contentOffset={x:x,y:y}')

Prop warnings stickyHeaderIndices, onEndReachedThreshold, renderScrollComponent

I have tried the example of LazyLoadListView you provided and i am getting warnings

// I figured this out
Failed prop type: Required prop stickyHeaderIndices was not specified in LazyloadListView.
// I Figured this out
Failed prop type: Required prop onEndReachedThreshold was not specified in LazyloadListView.
// Still have to
Failed prop type: Required prop renderScrollComponent was not specified in LazyloadListView.

I have followed everything as you shown in example, but i cant seem to figure out why im getting this errors

Recycle's problem

    shouldComponentUpdate = (nextProps) => {
        return this._visible || !nextProps.host;
    };

This piece of code prevents recycle system functioning

ExceptionsManager.js:71 view <RCTShadowView: 0x6000001b4740 ...

ExceptionsManager.js:71 view <RCTShadowView: 0x6000001b4740; viewName: RCTView; reactTag: 1295; frame: {{0, 0}, {0, 0}}> (tag #1295) is not a descendant of <RCTShadowView: 0x6000003aea80; viewName: RCTScrollView; reactTag: 1256; frame: {{0, 77.5}, {375, 0}}> (tag #1256)reactConsoleErrorHandler @ ExceptionsManager.js:71console.error @ YellowBox.js:61logIfNoNativeHook @ RCTLog.js:38__callFunction @ MessageQueue.js:236(anonymous function) @ MessageQueue.js:108guard @ MessageQueue.js:46callFunctionReturnFlushedQueue @ MessageQueue.js:107message @ index.js:73

screen shot 2017-02-13 at 5 09 54 pm

What can be the possible reason ?

not working i get white screen , tested in android emulator

*If you copy the code, change the return2 to return, i did it cause guthub is remove all the lines inside the return
Code:

`
/**

'use strict';
import React, {
AppRegistry,
Component,
StyleSheet,
Text,
View
} from 'react-native';

import {
LazyloadScrollView,
LazyloadView
} from 'react-native-lazyload';

import data from './MOCK_DATA.json';
class AwesomeProject extends Component {
render() {
let start = ~~(Math.random() * 900);
let list = data.splice(start, 100);
return2 (

{list.map((file, i) =>


{file.id}


{file.first_name} {file.last_name}
email: {file.email}
last visit ip: {file.ip_address}


<Text style={[styles.genderText, file.gender === 'Male' ? styles.male : styles.female]}>{file.gender}


)}

);
}
}

const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#F5FCFF'
},
content: {
paddingTop: 20,
justifyContent: 'center',
alignItems: 'center'
},
view: {
height: 70,
width: 320,
paddingVertical: 5,
borderBottomWidth: StyleSheet.hairlineWidth,
borderBottomColor: '#666'
},
file: {
width: 320,
flex: 1,
flexDirection: 'row'
},
id: {
width: 50,
alignItems: 'center',
justifyContent: 'center'
},
idText: {
fontSize: 10
},
detail: {
justifyContent: 'space-around',
flex: 1
},
name: {
textAlign: 'center',
lineHeight: 15,
color: '#666',
marginBottom: 5
},
email: {
fontSize: 10,
color: 'blue',
textDecorationColor: 'blue',
textDecorationLine: 'underline',
textDecorationStyle: 'solid'
},
ip: {
fontSize: 12,
color: 'grey'
},
gender: {
width: 50,
alignItems: 'center',
justifyContent: 'center'
},
genderText: {
fontSize: 10
},
title: {
color: '#333',
fontSize: 12
},
male: {
color: 'skyblue'
},
female: {
color: 'pink'
}
});

AppRegistry.registerComponent('AwesomeProject', () => AwesomeProject);

`

LazyLoadImage is not working inside LazyLoadListView

renderRow = (file) => {
        return <View
            style={styles.view}
        >
            <LazyloadView
                host="listExample"
                style={styles.file}
            >
                <View style={styles.id}>
                    <Text style={styles.idText}>{file.id}</Text>
                </View>
                <LazyloadImage
                    host="scrollImage"
                    style={styles.image}
                    source={file.image}
                    animation={false}
                />
                <View style={styles.gender}>
                    <Text style={[styles.genderText, file.gender === 'Male' ? styles.male : styles.female]}>{file.gender}</Text>
                </View>
            </LazyloadView>
        </View>;
    };

    render() {
        return <LazyloadListView
            style={styles.container}
            contentContainerStyle={styles.content}
            name="listExample"
            dataSource={this.state.dataSource}
            renderRow={this.renderRow}
            scrollRenderAheadDistance={200}
            renderDistance={100}
            pageSize={1}
            initialListSize={10}
        />;
    }

screenshot_20170526-180955 1

Question: Can i use LazyLoadImage in child comp?

I will use lazyloadImage inside
ProductCardItem component calls host : "lazyload-list".
is it possible? will it work?

return(
      <LazyloadScrollView
        name="lazyload-list"
        >
          <View style={{flexDirection: 'row', flexWrap: 'wrap', paddingBottom: 10}}>
            {
              arrProdList.map((item, i) => {
                return (
                  <View key={i+1}
                    host="lazyload-list"
                    style={{width: (widthCard / 2) - 15,
                      height: 240,
                      marginLeft: 10,
                      marginTop: 5}}>
                    {<ProductCardItem  prod={item} lazyload={false}/>}
                  </View>
                );
              })
            }
        </View>
      </LazyloadScrollView>

Lazy loading of a list of LazyloadScrollView

Hello!

First at all, great library! Thanks for sharing it.

I need to implement a UI where there are several horizontal lists of images, all of them wrapped in a top vertical list, similar to Netflix´s UI. There should be lazing loading of images for the horizontal lists and the vertical one, e.g.: the lists of images at the bottom are not rendered until they appear on screen.
Using your library I´ve been able to develop the lazy loading for the horizontal lists, but I haven´t found a way to implement the vertical lazy loading, so the lists at the end are not rendered and their images are not fetched from internet. Is there a way to achieve this? Any idea?

I´ve tried wrapping all the horizontal LazyloadScrollViews on a top LazyloadScrollView, but this does not work since LazyloadScrollView doesn´t implement LazyloadView.

Thanks!

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.