Skip to content

Instantly share code, notes, and snippets.

@aaronblondeau
Last active August 26, 2017 19:32
Show Gist options
  • Save aaronblondeau/ab7182f44561de4ad4f2a528f6728125 to your computer and use it in GitHub Desktop.
Save aaronblondeau/ab7182f44561de4ad4f2a528f6728125 to your computer and use it in GitHub Desktop.
HomeScreen component refactored to display a list of items
import React, { Component } from 'react';
import {
StyleSheet,
} from 'react-native';
import { Spinner, Container, Content, Button, List, ListItem, Text } 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 }) }>
<Text>{ item.name }</Text>
</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