Giter VIP home page Giter VIP logo

react-infinity's Introduction

React Infinity

React Infinity is an implementation of the UITableView from iOS for the web. (Another famous implementation is Infinity.js by AirBnB.)

React Infinity is much more than just infinity.js repackaged for react.js. React Infinity has been written from the ground up for React.js with maximum performance and using the TransitionGroup addon, animations for every element coming in, going out, or moving around.

Why?

Join the chat at https://gitter.im/nmn/react-infinity

Showing extremely long pages with a very large number of elements is becoming increasingly common on the web. However, sometimes with with very large number of elements, performance can suffer. As has been a guiding principle behind React.js, DOM nodes can be extremely expensive and can quickly hurt scroll performance of your page.

UITable on iOS solves this by simply only rendering the elements currently visible on the screen. React Infinity brings that logic the web. This way you can have a huge number of elements with smooth performance without memory issues. This is important to ensure a good experience while scrolling, and this is especially important on mobile devices, where the browser can crash if your website has too many DOM elements.

Why React Infinity

React Infinity solves more than one problem. Inspired by the animations of Metafizzy's Isoptope, React Infinity provides smooth animations to elements, while they enter, leave, or change positions.

Usage

I have tried to design an API that requires the minimum possible options to work, with sensible defaults, but when you do want, everything is extremely customisable. Also, standing on the strengths of React, there are no options to change data. Anytime, something changes, you can just re-render the React Infinity Component with it.

The basic props for React Infinity

var Infinity = require('react-infinity');

// ...
  Infinity({
    data: data, //Array of objects.
    elementWidth: 300, // Width of one element
    elementHeight: 300, // height of one element
    margin: 300,
    childComponent: ArticleCard, // React Class that will render actual cards. Must accept one object from the data array as props

    /* optional values:
    transitionable: // an object of type famous.Transitionable. transitionable.get() will replace window.scrollY
    mobileWidth: // breakpoint for switching to mobile view
    justifyOnMobile: // pass true to switch to a list instead of a grid on mobile.
    elementMobileHeight: // element height to use for mobile view
    elementMobileWidth: // element width to use for mobile view when `justifyOnMobile === false`
    scrollDelta: // Number of pixels from the top of the page to where React-Infinity is placed.
    */
  })
//...

The props are fairly straightforward.

data array

This is the data on which the content is based. It should be an array of objects that can have any data that your application may require and will be passed in to the childComponent as props that you pass in to render.

The only manadatory property of each object in data is an id field which is unique.

elementWidth number

Width of each element in pixels for desktop view.

elementHeight number

Height of each element in pixels for desktop view

margin number

margin between the elements. This is both the vertical and horizontal margin. v2.0 will bring more flexibility

childComponent React Class

This is the react component that is responsible for rendering each object in the data array. This can be any component and will receive the data you pass in. You are responsible for making sure that it renders in way that it conforms to size you have provided.

Example

There will soon be a fully customisable example to let you experience the power of React Infinity. You can take a look at the Scribbler to see an early version of React Infinity in action.

Support

React Infinity is in active development and is being dogfooded at Rushmore.fm. The project will be using the same version of React Infinity as on react, and bugs will be fixed promptly and performance improvements will land early.

On the other hand, React Infinity does some things well, and lets you take care of the other things. If you run in to a problem where you're not being able to accomplish something with React-Infinity that you want to, I may be able to let you know of a way. But some things may simply not be possible, such as a masonry layout.

Contribution

While it is in early development, the API will not change dramatically. After a short period of small evolution, the API will quickly be stabilized and any breaking changes in the API will not be accepted. That said, any other improvements are welcome. Testing a UI component can be hard, and I'm particularly interested in any help setting up tests for this component.

The style guide is important, but it's fairly straightforward.

  • 2 spaces
  • no JSX
  • try to be consistent with the existing code
  • Prefer clear code over comments.

Also, please feel free to leave issues with questions, bugs, feature requests etc.

Changelog

v1.2.1

  • Made transitionable completely optional. Will use window.scrollY by default.
  • Lots of small bug fixes.

v1.0.0

  • Fixed bug - incorrectly named function for removing event listener
  • Pre-Rendering made an option and turned off by default
  • Option to choose the DOM element for the container
  • Update to React 0.12.x

react-infinity's People

Contributors

aknuds1 avatar chrisui avatar gitter-badger avatar kyleamathews avatar mattmarcello avatar nichoth avatar nmn avatar rivertam 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

react-infinity's Issues

Exception error

Hi, could you help me with this error :

Uncaught TypeError: Cannot read property '__reactAutoBindMap'

this is my complete gist https://gist.github.com/daimagine/529a5fc24cee094281f8

By the way, thank you for your awesome react infinity

Blank on mobile screen

Hi again,

I found another problem in rendering on mobile screen with 320px width. Somehow it doesnt show anything (blank).
I checked the style of infinite-container and I found the height attr is NaN :

<div class="infinite-container" style="height:NaNpx;width:100%;position:relative;" data-reactid=".0.0.3.0.1">
<span data-reactid=".0.0.3.0.1.0"></span>
</div>

Please help me figured this out since I dont have any clue of whats going on. And this is my gist:
https://gist.github.com/daimagine/e5e11a3a85118f6b5d9c

Thank you

TypeError: object is not a function

Do you have an example on how to get this working ?
I ran into problem where I set data

//this.state.messages = [
{
    "id": 1,
    "title": "heading 1",
    "content": "abc"
  },
{
    "id": 2,
    "title": "heading 2",
    "content": "abcde"
  }
]
<Infinite data={this.state.messages} elementWidth={300} elementHeight={300} />

Horizontal scroll

Does this lib support horizontal scrolling (x axis)? If yes, is there any example I can see?

Add a standalone demo

Demo time!!! It would be nice to be able to see a couple of examples in the Repo. You put so much work into it and having examples makes it so much easier to play around with it.

Allow specifying container other than window

  onResize: function () {
    this.setState({windowHeight: global.innerHeight, windowWidth: global.innerWidth});
  },

Currently the code in places such as above is assuming the user wants to render the component into the full width of the viewport.

Instead of calculating based on the window dimensions, it would enable more possibilities to allow users to supply a container. For example, the user might have a max-width set on their HTML template, or they might want to render the react-infinite component on just the right 50% of the page, etc.

Make it compatible with newer React versions (15.3.2 and up)

Hi I'm willing to integrate this library into my current project.
Now if I add the library I cannot compile the project due to this error:

Error: Cannot find module 'react/addons'

I've installed react-addons package and required into my component code.

var addons = require('react-addons')

and also I've added the 'externals' reference into my webpack.config file

externals: { 'react/addons': true }

I'm currently using React 15.3.2 and I wonder if there is a workaround for fixing that issue.

Thanks a lot!

Provide props to child elements

Hi again,
Can I provide another props into child elements beside the array of items itself? Because I need to pass parent's state into child elements.

Regards,

Overflow child components

Hi again,

I found an issue today. I use a sidebar for navigation and ReactInfinity is in content side on the right side.
In mobile view grid displayed correctly, grids divide evenly and fill the screen correctly.
But in desktop mode, the grid is overflowed onto right side so the rest of child component is not shown or clipped.

screen shot 2015-08-03 at 4 22 53 pm

this is my gist https://gist.github.com/daimagine/e5e11a3a85118f6b5d9c

Please help me find what is wrong with my grid
Best regards,

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.