Skip to content

Commit

Permalink
Merge pull request #539 from shoutem/release/4.0.11
Browse files Browse the repository at this point in the history
Release/4.0.11
  • Loading branch information
majaklajic authored Nov 10, 2020
2 parents 7d5d651 + a6a093a commit 7b57bfe
Show file tree
Hide file tree
Showing 5 changed files with 141 additions and 1 deletion.
53 changes: 53 additions & 0 deletions assets/images/emptyList.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
61 changes: 61 additions & 0 deletions components/EmptyListImage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import PropTypes from 'prop-types';
import React, { PureComponent } from 'react';
import autoBindReact from 'auto-bind/react';
import _ from 'lodash';
import { connectStyle } from '@shoutem/theme';
import { Text, Title, View } from '@shoutem/ui';
import EmptyList from '../assets/images/emptyList.svg'

class EmptyListImage extends PureComponent {
static defaultProps = {
title: "It's empty in here",
message: "We couldn't find anything to show...",
}

constructor(props) {
super(props);

autoBindReact(this);
}

resolveImage() {
const { image } = this.props;

if (image && !_.isFunction(image)) {
console.warn(`Image must be an SVG file imported as a React component.`);
} else if (image && _.isFunction(image)) {
return image;
}

return EmptyList;
}

render() {
const { message, title, imageStyle, titleStyle, messageStyle, style } = this.props
const EmptyStateImage = this.resolveImage();

return (
<View styleName="vertical h-center ">
<EmptyStateImage style={[style.image, imageStyle]} />
<Title styleName="title" style={[style.title, titleStyle]}>{title}</Title>
<Text styleName="description" style={[style.message, messageStyle]}>{message}</Text>
</View >
);
}
}

EmptyListImage.propTypes = {
...EmptyListImage.propTypes,
image: PropTypes.func,
imageStyle: PropTypes.object,
message: PropTypes.string,
messageStyle: PropTypes.object,
title: PropTypes.string,
titleStyle: PropTypes.object,
};

const StyledView = connectStyle('shoutem.ui.EmptyListImage')(EmptyListImage);

export {
StyledView as EmptyListImage,
};
11 changes: 10 additions & 1 deletion components/ListView.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { connectStyle } from '@shoutem/theme';
import { Caption } from './Text';
import { Divider } from './Divider';
import { Spinner } from './Spinner';
import { EmptyListImage } from './EmptyListImage';

const Status = {
LOADING: 'loading',
Expand All @@ -37,6 +38,7 @@ class ListView extends PureComponent {
static propTypes = {
autoHideHeader: PropTypes.bool,
style: PropTypes.object,
contentContainerStyle: PropTypes.object,
data: PropTypes.array,
loading: PropTypes.bool,
onLoadMore: PropTypes.func,
Expand Down Expand Up @@ -122,6 +124,8 @@ class ListView extends PureComponent {
onRefresh,
onLoadMoreThreshold,
keyExtractor,
contentContainerStyle,
ListEmptyComponent,
} = this.props;
const { refreshing } = this.state;
const mappedProps = {
Expand All @@ -134,7 +138,7 @@ class ListView extends PureComponent {

// style
mappedProps.style = style.list;
mappedProps.contentContainerStyle = style.listContent;
mappedProps.contentContainerStyle = { ...contentContainerStyle, ...style.listContent };

if ((Platform.OS === 'ios') && (parseInt(Platform.Version, 10) === 13)) {
mappedProps.scrollIndicatorInsets = { right: 1 };
Expand Down Expand Up @@ -177,6 +181,11 @@ class ListView extends PureComponent {
// is data refreshing
mappedProps.refreshing = refreshing === Status.REFRESHING;

// if list is empty, show empty placeholder
if (!ListEmptyComponent) {
mappedProps.ListEmptyComponent = EmptyListImage;
}

// refresh control
mappedProps.refreshControl = onRefresh && this.renderRefreshControl();

Expand Down
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ export { Tile } from './components/Tile';
export { Lightbox } from './components/Lightbox';

export { EmptyStateView } from './components/EmptyStateView';
export { EmptyListImage } from './components/EmptyListImage';
export { NumberInput } from './components/NumberInput';
export { SearchField } from './components/SearchField';

Expand Down
16 changes: 16 additions & 0 deletions theme.js
Original file line number Diff line number Diff line change
Expand Up @@ -1544,6 +1544,22 @@ export default (variables = defaultThemeVariables) => ({
};
},
},
'shoutem.ui.EmptyListImage': {
image: {
resizeMode: 'contain',
marginTop: 45,
marginBottom: 30,
},
title: {
maxWidth: 250,
marginBottom: 20,
textAlign: 'center',
},
message: {
textAlign: 'center',
maxWidth: 250,
},
},
'shoutem.ui.NavigationBar': {
[INCLUDE]: ['navigationBar'],
'.clear': {
Expand Down

0 comments on commit 7b57bfe

Please sign in to comment.