Last active
May 20, 2019 02:31
-
-
Save PavanKu/f3fae786d0798cee87e909b231f45311 to your computer and use it in GitHub Desktop.
React native scroll view
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
import { View, Text, Image, ActivityIndicator, StyleSheet, ScrollView } from "react-native"; | |
const initialState = { pictures: [ | |
{id:0, download_url:"https://picsum.photos/id/0/5616/3744" }, | |
{id:1, download_url: "https://picsum.photos/id/1002/4312/2868"}, | |
{id:2, download_url: "https://picsum.photos/id/1006/3000/2000"}, | |
{id:3, download_url: "https://picsum.photos/id/1015/6000/4000"} | |
] }; | |
class PictureList extends React.Component { | |
constructor(props) { | |
super(props); | |
this.state = initialState; | |
} | |
render() { | |
const { pictures } = this.state; | |
if (!pictures.length) { return (<ActivityIndicator />); } | |
return ( | |
<View> | |
<ScrollView> | |
{pictures.map(picture => ( | |
<View style={styles.container} key={picture.id}> | |
<Image style={styles.image} source={{uri: picture.download_url}} /> | |
</View> | |
))} | |
/> | |
</View> | |
); | |
} | |
} | |
const styles = StyleSheet.create({ | |
container: { | |
borderColor: '#ccc', | |
borderWidth: 1, | |
borderRadius: 5, | |
backgroundColor: '#eaf7fd', | |
marginBottom: 15, | |
}, | |
image: { | |
margin: 5, | |
borderRadius: 5, | |
width: 300, | |
height: 300, | |
} | |
}); | |
export default PictureList; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment