React Native – ScrollView
ScrollView
is a scrollable container that can hold multiple components and views. It supports both vertical and horizontal scrolling.
Use Cases:
- Displaying a large number of components or a long form.
- Creating carousels or image galleries.
- Scrolling through content that exceeds the screen size.
Example:
import React from 'react';
import { ScrollView, Text, StyleSheet } from 'react-native';
const App = () => {
return (
<ScrollView style={styles.scrollView}>
{[...Array(20).keys()].map(i => (
<Text style={styles.text} key={i}>Item {i + 1}</Text>
))}
</ScrollView>
);
};
const styles = StyleSheet.create({
scrollView: {
marginHorizontal: 20,
marginTop: 50,
},
text: {
fontSize: 20,
marginVertical: 10,
},
});
export default App;