Skip to content

Commit ee94df0

Browse files
JoelMarceyMorgan Pretty
authored andcommitted
Add ScrollView to Basics docs
Summary: Add basic information about the generic `ScrollView` -- talk a bit about how it renders elements and a quick compare against something like a `ListView`. Provide a simple example. Fixes facebook#8261 Closes facebook#8266 Differential Revision: D3465105 Pulled By: JoelMarcey fbshipit-source-id: 3a2e1eac6e877669763fc6b8bb0fc78ebe870ab1
1 parent c3b5dc6 commit ee94df0

File tree

3 files changed

+76
-2
lines changed

3 files changed

+76
-2
lines changed

docs/Basics-Component-ListView.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@ permalink: docs/basics-component-listview.html
77
next: basics-integration-with-existing-apps
88
---
99

10-
On mobile devices, lists are a core element in many applications. The [`ListView`](/react-native/docs/listview.html#content) component is a special type of [`View`](/react-native/docs/tutorial-component-view.html) that displays a vertically scrolling list of changing data.
10+
On mobile devices, lists are a core element in many applications. The [`ListView`](/react-native/docs/listview.html#content) component is a special type of [`View`](/react-native/docs/basics-component-view.html) that displays a *vertically* scrolling list of changing, but similarly structured, data.
11+
12+
`ListView` works best for possibly lengthy datasources (e.g., from an endpoint or database), where the number of items may not be known a priori.
13+
14+
> Unlike the more generic [`ScrollView`](/react-native/docs/basics-component-scrollview.html), the `ListView` only renders elements that are currently showing on the screen, not all the elements at once.
1115
1216
The `ListView` component requires two properties, `dataSource` and `renderRow`. `dataSource` is the actual source of information that will be part of the list. `renderRow` takes the data and returns a renderable component to display.
1317

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
---
2+
id: basics-component-scrollview
3+
title: ScrollView
4+
layout: docs
5+
category: Basics
6+
permalink: docs/basics-component-scrollview.html
7+
next: basics-component-listview
8+
---
9+
10+
Given the screen sizes of mobile devices, the ability to scroll through data is generally paramount for a proper usability experience.
11+
12+
The [`ScrollView`](/react-native/docs/scrollview.html) 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).
13+
14+
`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.
15+
16+
> [`TextView`](/react-native/docs/basics-component-textview.html) and [`ListView`](/react-native/docs/basics-component-listview.html) are specialized scrollable containers.
17+
18+
This contrived example creates a horizontal `ScrollView` with a static amount of heterogenous elements (images and text).
19+
20+
```JavaScript
21+
import React, { AppRegistry, ScrollView, Image, Text, View } from 'react-native'
22+
23+
var SimpleScrollView = React.createClass({
24+
render(){
25+
return(
26+
<ScrollView horizontal={true}>
27+
<View>
28+
<Image source={require('./img/check.png')} />
29+
</View>
30+
<View>
31+
<Image source={require('./img/check.png')} />
32+
</View>
33+
<View>
34+
<Image source={require('./img/check.png')} />
35+
</View>
36+
<View>
37+
<Text style={{fontSize:96}}>Text1</Text>
38+
</View>
39+
<View>
40+
<Text style={{fontSize:96}}>Text2</Text>
41+
</View>
42+
<View>
43+
<Text style={{fontSize:96}}>Text3</Text>
44+
</View>
45+
<View>
46+
<Text style={{fontSize:96}}>Text4</Text>
47+
</View>
48+
<View>
49+
<Image source={require('./img/check.png')} />
50+
</View>
51+
<View>
52+
<Image source={require('./img/check.png')} />
53+
</View>
54+
<View>
55+
<Image source={require('./img/check.png')} />
56+
</View>
57+
<View>
58+
<Text style={{fontSize:96}}>Text5</Text>
59+
</View>
60+
<View>
61+
<Text style={{fontSize:96}}>Text6</Text>
62+
</View>
63+
</ScrollView>
64+
);
65+
}
66+
});
67+
68+
69+
AppRegistry.registerComponent('MyApp', () => SimpleScrollView);
70+
```

docs/Basics-Component-TextInput.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ title: TextInput
44
layout: docs
55
category: Basics
66
permalink: docs/basics-component-textinput.html
7-
next: basics-component-listview
7+
next: basics-component-scrollview
88
---
99

1010
Direct text-based user input is a foundation for many apps. Writing a post or comment on a page is a canonical example of this. [`TextInput`](/react-native/docs/textinput.html#content) is a basic component that allows the user to enter text.

0 commit comments

Comments
 (0)