react-native/docs/Basics-Component-ScrollView.md
Joel Marcey d464f1d1c2 Add React Native Web Player to most component basics
Summary:
> ListView is not supported by React Native Web as of yet, so it will not have it.
Closes https://github.com/facebook/react-native/pull/8331

Differential Revision: D3472019

Pulled By: lacker

fbshipit-source-id: e5fb430b6c8f4d437943c159beb00b9d9252c92d
2016-06-22 15:13:32 -07:00

2.6 KiB

id title layout category permalink next
basics-component-scrollview ScrollView docs The Basics docs/basics-component-scrollview.html basics-component-listview

Given the screen sizes of mobile devices, the ability to scroll through data is generally paramount for a proper usability experience.

The ScrollView is a generic scrolling container that can host multiple components and views. The scrollable items need not be homogenous, and you can scroll both vertically and horizontally (by setting the horizontal property).

ScrollView works best to present a list of short, static items of a known quantity. All the elements and views of a ScrollView are rendered a priori, even if they are not currently shown on the screen. Contrast this with a ListView, which render only those views that are on the screen and remove views that go off-screen.

TextView and ListView are specialized scrollable containers.

This contrived example creates a horizontal ScrollView with a static amount of heterogenous elements (images and text).

import React, { AppRegistry, ScrollView, Image, Text, View } from 'react-native'

var SimpleScrollView = React.createClass({
  render(){
      return(
        <ScrollView horizontal={true}>
          <View>
            <Image source={require('./img/favicon.png')} />
          </View>
          <View>
            <Image source={require('./img/favicon.png')} />
          </View>
          <View>
            <Image source={require('./img/favicon.png')} />
          </View>
          <View>
            <Text style={{fontSize:96}}>Text1</Text>
          </View>
          <View>
            <Text style={{fontSize:96}}>Text2</Text>
          </View>
          <View>
            <Text style={{fontSize:96}}>Text3</Text>
          </View>
          <View>
            <Text style={{fontSize:96}}>Text4</Text>
          </View>
          <View>
            <Image source={require('./img/favicon.png')} />
          </View>
          <View>
            <Image source={require('./img/favicon.png')} />
          </View>
          <View>
            <Image source={require('./img/favicon.png')} />
          </View>
          <View>
            <Text style={{fontSize:96}}>Text5</Text>
          </View>
          <View>
            <Text style={{fontSize:96}}>Text6</Text>
          </View>
        </ScrollView>
    );
  }
});


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