ScrollView in React Native
Scroll View Example in React Native
ScrollView:- When we wrap up the scroll view component around the elements we can scroll all the elements in a vertical or horizontal manner. See the example below.
import React from 'react';
import { View, StyleSheet , Text, ScrollView} from 'react-native';
//Sample data to display
const DATA=[
'Text1',
'Text2',
'Text3',
'Text4',
'Text5',
'Text6',
'Text7',
'Text8',
'Text9',
'Text10',
'Text11',
'Text12',
'Text13',
'Text14',
'Text15',
]
export default function ScrollViewExample() {
return (
<View style={styles.conatainer}>
{/* here we are using the srollview. see all the scroll view properties
in React Native official website */}
<ScrollView>
{
//mapping the data to display each item in the object
DATA.map((item, index)=>{
return(
<View style={[styles.view1,]} key={index}>
<Text style={styles.text}>{item}</Text>
</View>
)
})
}
</ScrollView>
</View>
);
}
const styles = StyleSheet.create({
conatainer: {
flex: 1,
},
view1:{
//backgroundColor:'pink',
alignItems:'center',
justifyContent:'center',
height:100
},
text:{
fontSize:25,
fontWeight:'bold',
color:'black'
}
})
OUTPUT:-
Comments
Post a Comment