Skip to content

Instantly share code, notes, and snippets.

@kiok46
Created June 28, 2017 17:41
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kiok46/7f183b4b2556b7151fb811bfa8e5dbb0 to your computer and use it in GitHub Desktop.
Save kiok46/7f183b4b2556b7151fb811bfa8e5dbb0 to your computer and use it in GitHub Desktop.
Display a nice Component when no Items are available to show.

NoItemComponent

Display a nice Component when no Items are available to show.

import React, { Component } from 'react';
import { Text, View, Dimensions, StyleSheet } from 'react-native';
import { FontAwesome } from '@expo/vector-icons';
import Colors from '../constants/Colors';


class NoItemComponent extends Component {
	constructor(props) {
		super(props);
	}
	render (){
		return (
            <View style={styles.alignContainers}>
				<View style={styles.containerStyle}>
					<FontAwesome
						name={this.props.iconName}
						size={64}
						color={Colors.tabIconDefault}
					  />
					  <Text style={styles.infoHeadingStyle}>
					  {this.props.infoHeading}
					  </Text>
					  <Text style={styles.infoParagraphStyle}>
					  {this.props.infoParagraph}
					  </Text>
				</View>
		    </View>
		);
	}
};

const styles = StyleSheet.create({
	alignContainers: {
		justifyContent: 'center',
		alignItems: 'center',
		width: Dimensions.get('window').width,
		height: Dimensions.get('window').height - 150
	},
	containerStyle: {
		alignItems: 'center',
		justifyContent: 'center'
	},
	infoHeadingStyle: {
		fontSize: 24,
		textAlign: 'center',
		marginTop: 5
	},
	infoParagraphStyle: {
        textAlign: 'center',
		padding: 10,
		fontSize: 16,
		color: '#888',
		width: Dimensions.get('window').width/1.75
	},
	textStyle: {
		fontSize: 20
	}
});

export default NoItemComponent;

and use the component like this.

<NoItemComponent
  iconName='heart'
  infoHeading="No Favourites"
  infoParagraph="Add stories to your favouries, and they will be shown here."
/>

cool!

@kiok46
Copy link
Author

kiok46 commented Jun 28, 2017

screen shot 2017-06-28 at 11 12 01 pm

file is at components/NoItemComponent.js

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment