Created
August 27, 2017 02:36
-
-
Save aaronblondeau/a98a19ec6c0ad0a71deab4e560bbcaf9 to your computer and use it in GitHub Desktop.
Use a List with Thumbnails for each item
This file contains 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, { Component } from 'react'; | |
import { | |
StyleSheet, | |
} from 'react-native'; | |
import { Spinner, Container, Content, Button, List, ListItem, Text, Thumbnail, Body } from 'native-base'; | |
import {observer} from 'mobx-react'; | |
import applicationState from '../ApplicationState' | |
@observer | |
export default class HomeScreen extends Component { | |
static navigationOptions = ({ navigation }) => ({ | |
title: 'React Native Quickly', | |
}); | |
componentDidMount() { | |
// Fetch the list as soon the app opens | |
applicationState.getThings() | |
} | |
render() { | |
const { navigate } = this.props.navigation; | |
let content = null; | |
if (applicationState.loading_routes) { | |
content = <Spinner /> | |
} | |
else { | |
// MobX' ObservableArray is not handled properly by NativeBase, so convert it to a plain array first | |
let items = applicationState.things.map((item) => {return item;}) | |
content = <List dataArray={items} | |
renderRow={(item) => | |
<ListItem onPress={() => navigate('Detail', { thing: item }) }> | |
<Thumbnail square size={80} source={{ uri: item.thumbnail }} /> | |
<Body> | |
<Text>{ item.name }</Text> | |
<Text note>{ item.description }</Text> | |
</Body> | |
</ListItem> | |
}> | |
</List> | |
} | |
return ( | |
<Container> | |
<Content> | |
{ content } | |
</Content> | |
</Container> | |
); | |
} | |
} | |
const styles = StyleSheet.create({ | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment