diff --git a/blog/2017/03/01/better-list-views.html b/blog/2017/03/01/better-list-views.html deleted file mode 100644 index 0888d42fc87..00000000000 --- a/blog/2017/03/01/better-list-views.html +++ /dev/null @@ -1,55 +0,0 @@ -Better List Views in React Native
React Native Blog
Stay up-to-date with the latest React Native news and events.

Better List Views in React Native

Many of you have started playing with some of our new List components already after our teaser announcement in the community group, but we are officially announcing them today! No more ListViews or DataSources, stale rows, ignored bugs, or excessive memory consumption - with the just-released RN 0.43-rc.1 you can pick from the new suite of components what best fits your use-case, with great perf and feature sets out of the box:

<FlatList> #

This is the workhorse component for simple, performant lists. Provide an array of data and a renderItem function and you're good to go:

<FlatList - data={[{title: 'Title Text', key: 'item1'}, ...]} - renderItem={({item}) => <ListItem title={item.title}} -/>

<SectionList> #

If you want to render a set of data broken into logical sections, maybe with section headers (e.g. in an alphabetical address book), and potentially with heterogeneous data and rendering (such as a profile view with some buttons followed by a composer, then a photo grid, then a friend grid, and finally a list of stories), this is the way to go.

<SectionList - renderItem={({item}) => <ListItem title={item.title}} - renderSectionHeader={({section}) => <H1 title={section.key} />} - sections={[ // homogenous rendering between sections - {data: [...], key: ...}, - {data: [...], key: ...}, - {data: [...], key: ...}, - ]} -/> - -<SectionList - sections={[ // heterogeneous rendering between sections - {data: [...], key: ..., renderItem: ...}, - {data: [...], key: ..., renderItem: ...}, - {data: [...], key: ..., renderItem: ...}, - ]} -/>

<VirtualizedList> #

The implementation behind the scenes with a more flexible API. Especially handy if your data is not in a plain array (e.g. an immutable list).

Some Caveats #

  • The internal state of item subtrees is not preserved when content scrolls out of the render window. Make sure all your data is captured in the item data or external stores like Flux, Redux, or Relay.
  • These are based on PureComponent which means that they will not re-render if props remains shallow-equal. Make sure that everything your renderItem function depends on directly is passed as a prop that is not === after updates, otherwise your UI may not update on changes. This includes the data prop and parent component state. For example:

    <FlatList - data={this.state.data} - renderItem={({item}) => <MyItem - item={item} - onPress={() => this.setState((oldState) => ({ - selected: { // New instance breaks `===` - ...oldState.selected, // copy old data - [item.key]: !oldState.selected[item.key], // toggle - }})) - } - selected={ - !!this.state.selected[item.key] // renderItem depends on state - } - />} - selected={ // Can be any prop that doesn't collide with existing props - this.state.selected // A change to selected should re-render FlatList - } -/>
  • In order to constrain memory and enable smooth scrolling, content is rendered asynchronously offscreen. This means it's possible to scroll faster than the fill rate and momentarily see blank content. This is a tradeoff that can be adjusted to suit the needs of each application, and we are working on improving it behind the scenes.

  • By default, these new lists look for a key prop on each item and use that for the React key. Alternatively, you can provide a custom keyExtractor prop.

Features #

Lists are used in many contexts, so we packed the new components full of features to handle the majority of use cases out of the box:

  • Scroll loading (onEndReached).
  • Pull to refresh (onRefresh / refreshing).
  • Configurable viewability (VPV) callbacks (onViewableItemsChanged / viewabilityConfig).
  • Horizontal mode (horizontal).
  • Intelligent item and section separators.
  • Multi-column support (numColumns)
  • scrollToEnd, scrollToIndex, and scrollToItem
  • Better Flow typing.

Performance #

Besides simplifying the API, the new list components also have significant performance enhancements, the main one being nearly constant memory usage for any number of rows. This is done by 'virtualizing' elements that are outside of the render window by completely unmounting them from the component hierarchy and reclaiming the JS memory from the react components, along with the native memory from the shadow tree and the UI views. This has a catch which is that internal component state will not be preserved, so make sure you track any important state outside of the components themselves, e.g. in Relay or Redux or Flux store.

Limiting the render window also reduces the amount of work that needs to be done by React and the native platform, e.g from view traversals. Even if you are rendering the last of a million elements, with these new lists there is no need to iterate through all those elements in order to render. You can even jump to the middle with scrollToIndex without excessive rendering.

We've also made some improvements with scheduling which should help with application responsiveness. Items at the edge of the render window are rendered infrequently and at a lower priority after any active gestures or animations or other interactions have completed.

Advanced Usage #

By default, all items in the render window are re-rendered any time any props change. Often this is fine because there is a finite window of items, but if you want to further optimize performance you can implement shouldItemUpdate. If you do, be careful that your renderItem function does not depend on anything not compared in shouldItemUpdate.

If you can calculate the height of your rows without rendering them, you can improve the user experience by providing the getItemLayout prop. This makes it much smoother to scroll to specific items with e.g. scrollToIndex, and will improve the scroll indicator UI because the height of the content can be determined without rendering it.

If you have an alternative data type, like an immutable list, <VirtualizedList> is the way to go. It takes a getItem prop that lets you return the item data for any given index and has looser flow typing.

There are also a bunch of parameters you can tweak if you have an unusual use case. For example, you can use windowSize to trade off memory usage vs. user experience, maxToRenderPerBatch to adjust fill rate vs. responsiveness, onEndReachedThreshold to control when scroll loading happens, and more.

Future Work #

  • Migration of existing surfaces (ultimately deprecation of ListView).
  • More features as we see/hear the need (let us know!).
  • Sticky section header support.
  • More performance optimizations.
  • Support functional item components with state.
\ No newline at end of file diff --git a/blog/2017/03/13/better-list-views.html b/blog/2017/03/13/better-list-views.html index 6f9cc0299f7..0a81865eacb 100644 --- a/blog/2017/03/13/better-list-views.html +++ b/blog/2017/03/13/better-list-views.html @@ -1,6 +1,6 @@ Better List Views in React Native
React Native Blog
Stay up-to-date with the latest React Native news and events.

Better List Views in React Native

Many of you have started playing with some of our new List components already after our teaser announcement in the community group, but we are officially announcing them today! No more ListViews or DataSources, stale rows, ignored bugs, or excessive memory consumption - with the latest React Native March 2017 release candidate (0.43-rc.1) you can pick from the new suite of components what best fits your use-case, with great perf and feature sets out of the box:

<FlatList> #

This is the workhorse component for simple, performant lists. Provide an array of data and a renderItem function and you're good to go:

<FlatList data={[{title: 'Title Text', key: 'item1'}, ...]} - renderItem={({item}) => <ListItem title={item.title}} + renderItem={({item}) => <ListItem title={item.title} />} />

<SectionList> #

If you want to render a set of data broken into logical sections, maybe with section headers (e.g. in an alphabetical address book), and potentially with heterogeneous data and rendering (such as a profile view with some buttons followed by a composer, then a photo grid, then a friend grid, and finally a list of stories), this is the way to go.

<SectionList renderItem={({item}) => <ListItem title={item.title}} renderSectionHeader={({section}) => <H1 title={section.key} />} diff --git a/releases/next/docs/animated.html b/releases/next/docs/animated.html index c0f36648dd0..783ff508a32 100644 --- a/releases/next/docs/animated.html +++ b/releases/next/docs/animated.html @@ -82,7 +82,10 @@ before starting the next. If the current running animation is stopped, no following animations will be started.

static parallel(animations, config?) #

Starts an array of animations all at the same time. By default, if one of the animations is stopped, they will all be stopped. You can override this with the stopTogether flag.

static stagger(time, animations) #

Array of animations may run in parallel (overlap), but are started in -sequence with successive delays. Nice for doing trailing effects.

static event(argMapping, config?) #

Takes an array of mappings and extracts values from each arg accordingly, +sequence with successive delays. Nice for doing trailing effects.

static loop(animation) #

Loops a given animation continuously, so that each time it reaches the +end, it resets and begins again from the start. Can specify number of +times to loop using the key 'iterations' in the config. Will loop without +blocking the UI thread if the child animation is set to 'useNativeDriver'.

static event(argMapping, config?) #

Takes an array of mappings and extracts values from each arg accordingly, then calls setValue on the mapped outputs. e.g.

onScroll={Animated.event( [{nativeEvent: {contentOffset: {x: this._scrollX}}}] {listener}, // Optional async listener @@ -106,7 +109,7 @@ The final output of the value is unchanged.

removeListener(id) #

removeAllListeners() #

stopAnimation(callback?) #

Stops any running animation or tracking. callback is invoked with the final value after stopping the animation, which is useful for updating -state to match the animation position with layout.

interpolate(config) #

Interpolates the value before updating the property, e.g. mapping 0-1 to +state to match the animation position with layout.

resetAnimation(callback?) #

Stops any animation and resets the value to its original

interpolate(config) #

Interpolates the value before updating the property, e.g. mapping 0-1 to 0-10.

animate(animation, callback) #

Typically only used internally, but could be used by a custom Animation class.

stopTracking() #

Typically only used internally.

track(tracking) #

Typically only used internally.

class AnimatedValueXY #

    2D Value for driving 2D animations, such as pan gestures. Almost identical API to normal Animated.Value, but multiplexed. Contains two regular @@ -139,7 +142,7 @@ API to normal Animated.Value, but multiplexed. Contains two regula </Animated.View> ); } - }

Methods #

constructor(valueIn?) #

setValue(value) #

setOffset(offset) #

flattenOffset() #

extractOffset() #

stopAnimation(callback?) #

addListener(callback) #

removeListener(id) #

removeAllListeners() #

getLayout() #

Converts {x, y} into {left, top} for use in style, e.g.

style={this.state.anim.getLayout()}

getTranslateTransform() #

Converts {x, y} into a useable translation transform, e.g.

style={{ + }

Methods #

constructor(valueIn?) #

setValue(value) #

setOffset(offset) #

flattenOffset() #

extractOffset() #

resetAnimation(callback?) #

stopAnimation(callback?) #

addListener(callback) #

removeListener(id) #

removeAllListeners() #

getLayout() #

Converts {x, y} into {left, top} for use in style, e.g.

style={this.state.anim.getLayout()}

getTranslateTransform() #

Converts {x, y} into a useable translation transform, e.g.

style={{ transform: this.state.anim.getTranslateTransform() }}

class AnimatedInterpolation #

    Methods #

    constructor(parent, config) #

    interpolate(config) #

You can edit the content above on GitHub and send us a pull request!

Examples #

Edit on GitHub
'use strict';