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 2a64fbbcaf0..00000000000 --- a/blog/2017/03/01/better-list-views.html +++ /dev/null @@ -1,38 +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.
  • 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/releases/next/docs/statusbar.html b/releases/next/docs/statusbar.html index fcf88fa407d..d7ecfe4ae2b 100644 --- a/releases/next/docs/statusbar.html +++ b/releases/next/docs/statusbar.html @@ -19,9 +19,9 @@ API exposed as static functions on the component. It is however not recommended to use the static API and the component for the same prop because any value set by the static API will get overriden by the one set by the component in the next render.

Constants #

currentHeight (Android only) The height of the status bar.

Props #

animated bool #

If the transition between status bar property changes should be animated. -Supported for backgroundColor, barStyle and hidden.

hidden bool #

If the status bar is hidden.

androidbackgroundColor color #

The background color of the status bar.

androidtranslucent bool #

If the status bar is translucent. +Supported for backgroundColor, barStyle and hidden.

barStyle enum('default', 'light-content', 'dark-content') #

Sets the color of the status bar text.

hidden bool #

If the status bar is hidden.

androidbackgroundColor color #

The background color of the status bar.

androidtranslucent bool #

If the status bar is translucent. When translucent is set to true, the app will draw under the status bar. -This is useful when using a semi transparent status bar color.

iosbarStyle enum('default', 'light-content', 'dark-content') #

Sets the color of the status bar text.

iosnetworkActivityIndicatorVisible bool #

If the network activity indicator should be visible.

iosshowHideTransition enum('fade', 'slide') #

The transition effect when showing and hiding the status bar using the hidden +This is useful when using a semi transparent status bar color.

iosnetworkActivityIndicatorVisible bool #

If the network activity indicator should be visible.

iosshowHideTransition enum('fade', 'slide') #

The transition effect when showing and hiding the status bar using the hidden prop. Defaults to 'fade'.

Methods #

static setHidden(hidden, animation?) #

Show or hide the status bar

Parameters:
Name and TypeDescription
hidden

boolean

Hide the status bar.

[animation]

Optional animation when changing the status bar hidden property.

static setBarStyle(style, animated?) #

Set the status bar style

Parameters:
Name and TypeDescription
style

Status bar style to set

[animated]

boolean

Animate the style change.

static setNetworkActivityIndicatorVisible(visible) #

Control the visibility of the network activity indicator

Parameters:
Name and TypeDescription
visible

boolean

Show the indicator.

static setBackgroundColor(color, animated?) #

Set the background color for the status bar

Parameters:
Name and TypeDescription
color

string

Background color.

[animated]

boolean

Animate the style change.

static setTranslucent(translucent) #

Control the translucency of the status bar

Parameters:
Name and TypeDescription
translucent

boolean

Set as translucent.

Type Definitions #

StatusBarStyle #

Status bar style

Type:
$Enum

Constants:
ValueDescription
default

Default status bar style (dark for iOS, light for Android)

light-content

Dark background, white texts and icons

dark-content

Light background, dark texts and icons

StatusBarAnimation #

Status bar animation

Type:
$Enum

Constants:
ValueDescription
none

No animation

fade

Fade animation

slide

Slide animation

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

Examples #

Edit on GitHub
'use strict'; diff --git a/releases/next/index.html b/releases/next/index.html index ad5b2535e20..c308261ca06 100644 --- a/releases/next/index.html +++ b/releases/next/index.html @@ -52,7 +52,7 @@ class SomethingFast extends /View> ); } -}

Who's using React Native?

Thousands of apps are using React Native, from established Fortune 500 companies to hot new startups. If you're curious to see what can be accomplished with React Native, check out these apps!

Facebook
Facebook Ads Manager
Facebook Groups
Instagram
Airbnb
Baidu(手机百度)
Discord
Gyroscope
li.st
QQ
Townske
Vogue
Walmart

Some of these are hybrid native/React Native apps.

Who's using React Native?

Thousands of apps are using React Native, from established Fortune 500 companies to hot new startups. If you're curious to see what can be accomplished with React Native, check out these apps!

Vogue

Vogue

iOS

Some of these are hybrid native/React Native apps. If you built a popular application using React Native, we'd love to have your app on this showcase. Check out the guidelines on GitHub to update this page.

Also, a curated list of open source React Native apps is being kept by React Native News.

Who's using React Native?

Thousands of apps are using React Native, from established Fortune 500 companies to hot new startups. If you're curious to see what can be accomplished with React Native, check out these apps!

Vogue

Vogue

iOS

Some of these are hybrid native/React Native apps. If you built a popular application using React Native, we'd love to have your app on this showcase. Check out the guidelines on GitHub to update this page.

Also, a curated list of open source React Native apps is being kept by React Native News.