Navigate back to the homepage

React Native ScrollView

Infinitbility
ScrollView
February 10th, 2021 · 1 min read
React Native ScrollView

This Article Part of React Native Tutorial Series want to start from scrach follow below link

https://infinitbility.com/react-native/table-of-contents


Ever have the situation where you sometimes had content that was shorter than the screen size and didn’t require scrolling but occasionally had content taller than the screen size, thus necessitating scroll to allow the user to see all the content.

React native scrollview provide feature to create scrolllable content on both direction ( vertically and horizontally ).

React Native ScrollView example.

App.js

1import React, { Component } from "react";
2import { ScrollView, StyleSheet, Text, View } from "react-native";
3class App extends Component {
4 state = {
5 products: [
6 { product: "Rice", id: 1 },
7 { product: "Sweets", id: 2 },
8 { product: "Fruits", id: 3 },
9 { product: "Animals", id: 4 },
10 { product: "humans", id: 5 },
11 { product: "sport", id: 6 },
12 { product: "kitchen", id: 7 },
13 { product: "childrens", id: 8 },
14 { product: "men", id: 9 },
15 { product: "old people", id: 10 },
16 { product: "shafty", id: 11 },
17 { product: "transport", id: 12 }
18 ]
19 };
20 render() {
21 return (
22 <View>
23 <ScrollView>
24 {this.state.products.map((item, index) => (
25 <View key={item.id} style={styles.item}>
26 <Text>{item.product}</Text>
27 </View>
28 ))}
29 </ScrollView>
30 </View>
31 );
32 }
33}
34const styles = StyleSheet.create({
35 item: {
36 flexDirection: "row",
37 justifyContent: "space-between",
38 alignItems: "left",
39 padding: 20,
40 margin: 2,
41 borderColor: "pink",
42 borderWidth: 3,
43 backgroundColor: "yellow"
44 }
45});
46export default App;

Scroll horizontally

react native scrollview provide horizontal props. When true, the scroll view’s children are arranged horizontally in a row instead of vertically in a column. The default value is false.

Use like below example

1...
2 <ScrollView
3 horizontal={true}
4 >
5 {this.state.products.map((item, index) => (
6 <View key={item.id} style={styles.item}>
7 <Text>{item.product}</Text>
8 </View>
9 ))}
10 </ScrollView>
11...

Common Q & A

Common Q & A section explain commonly question ask on google.

How do you get the scroll position in react native?

react native scrollview provide onScroll props to get scrolled position of screen.

just like below example

1<ScrollView
2 onScroll={event =>
3 this.setState({horizontalScroll:event.nativeEvent.contentOffset.x, VerticalScroll:event.nativeEvent.contentOffset.y})
4 }
5>
6// Your list data
7</ScrollView>

React native Scroll programmatically

infinitbility already published Tutorial related to Scroll programmatically. please check out the below link.

Thanks For reading…

More From React Native Tutorial

Basics

  1. Introduction To React Native
  2. React Native Environment Setup using expo
  3. React Native Environment Setup for windows
  4. React Native Environment setup on Mac OS
  5. React Native Environment setup on linux
  6. React Native Project Structure
  7. React Native State
  8. React Native Props
  9. React Native Styling
  10. React Native Flexbox
  11. React Native Text
  12. React Native Textinput
  13. React Native Commands
  14. React Native ScrollView

Advances

  1. React Native Dark Mode
  2. React Native Fonts
  3. React Native SQLite
  4. React Native DatepickerAndroid
  5. React native ScrollView scroll to position
  6. How to align icon with text in react native
  7. React Native Image
  8. React Native Firebase Crashlytics
  9. React Native Async Storage
  10. React Native Share

Error & Issue Solution

  1. Task :app:transformDexArchiveWithDexMergerForDebug FAILED In React Native
  2. Expiring Daemon because JVM heap space is exhausted In React Native
  3. Task :app:transformNativeLibsWithMergeJniLibsForDebug FAILED In React Native
  4. Unable to determine the current character, it is not a string, number, array, or object in react native
  5. App crashed immediately after install react native video or track player
  6. how to delete SQLite database in android react native
  7. React native material dropdown twice click issue
  8. How to get the current route in react-navigation?
  9. how to disable drawer on the drawer navigation screen?
  10. Image not showing in ios 14 react native

Join our email list and get notified about new content

No worries, I respect your privacy and I will never abuse your email.

Every week, on Tuesday, you will receive a list of free tutorials I made during the week (I write one every day) and news on other training products I create.

More articles from Infinitbility

React Native Textinput

React Native Textinput

React Native Tutorial - React Native Textinput

January 28th, 2021 · 1 min read
React Native Text

React Native Text

React Native Tutorial - React Native Text

January 27th, 2021 · 1 min read
© 2021 Infinitbility
Link to $https://medium.com/infinitbilityLink to $https://www.facebook.com/InfinitbilityLink to $https://github.com/infinitbilityLink to $https://twitter.com/infinitbilityLink to $https://www.buymeacoffee.com/infinitbilityLink to $mailto:[email protected]