Skip to content

Commit c9ac08d

Browse files
committed
Placeholder loading animation added
1 parent e15d7ad commit c9ac08d

File tree

7 files changed

+59
-3
lines changed

7 files changed

+59
-3
lines changed

__tests__/components/ProductsList.spec.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ const INITIAL_STATE = {
3232
price: 125.36,
3333
},
3434
],
35+
loading: false,
3536
},
3637
categories: {
3738
currentId: 3,
@@ -41,6 +42,7 @@ const INITIAL_STATE = {
4142
const STATE_WITHOUT_ITEMS = {
4243
products: {
4344
items: [],
45+
loading: false,
4446
},
4547
categories: {
4648
currentId: 3,

package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"redux": "^4.0.1",
2323
"redux-saga": "^1.0.2",
2424
"reduxsauce": "^1.1.0",
25+
"rn-placeholder": "^2.0.0",
2526
"seamless-immutable": "^7.1.4",
2627
"styled-components": "^4.2.1"
2728
},
@@ -59,6 +60,9 @@
5960
"!src/store/ducks/index.js",
6061
"src/store/sagas/*.js",
6162
"!src/store/sagas/index.js"
63+
],
64+
"transformIgnorePatterns": [
65+
"node_modules/(?!(jest-)?react-native|rn-placeholder)"
6266
]
6367
},
6468
"engines": {
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import React from 'react';
2+
3+
import Placeholder, { Media } from 'rn-placeholder';
4+
5+
import { PlaceholderView } from './styles';
6+
7+
const PlaceholderLoading = loading => (
8+
<Placeholder isReady={!loading} animation="fade">
9+
<PlaceholderView>
10+
<Media size={160} margin={13} />
11+
<Media size={160} margin={13} />
12+
<Media size={160} margin={13} />
13+
<Media size={160} margin={13} />
14+
<Media size={160} margin={13} />
15+
<Media size={160} margin={13} />
16+
</PlaceholderView>
17+
</Placeholder>
18+
);
19+
20+
export default PlaceholderLoading;
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import styled from 'styled-components/native';
2+
3+
export const PlaceholderView = styled.View`
4+
display: flex;
5+
flex-direction: row;
6+
flex-wrap: wrap;
7+
align-content: space-between;
8+
`;

src/components/ProductsList/index.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import { connect } from 'react-redux';
44
import { withNavigation } from 'react-navigation';
55
import PropTypes from 'prop-types';
66

7+
import PlaceholderLoading from '~/components/PlaceholderLoading';
8+
79
import ProductsActions from '~/store/ducks/products';
810

911
import {
@@ -53,9 +55,11 @@ class ProductList extends Component {
5355
};
5456

5557
render() {
56-
const { items } = this.props;
58+
const { items, loading } = this.props;
5759

58-
return (
60+
return loading ? (
61+
<PlaceholderLoading loading={loading} />
62+
) : (
5963
<Container>
6064
<ProductsList
6165
data={items}
@@ -78,6 +82,7 @@ class ProductList extends Component {
7882

7983
const mapStateToProps = state => ({
8084
items: state.products.items,
85+
loading: state.products.loading,
8186
categoryId: state.categories.currentId,
8287
});
8388

src/store/ducks/products.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@ export default Creators;
1111

1212
const INITIAL_STATE = Immutable({
1313
items: [],
14+
loading: false,
1415
});
1516

1617
export const reducer = createReducer(INITIAL_STATE, {
17-
[Types.LOAD_PRODUCTS_SUCCESS]: (state, { items }) => ({ items }),
18+
[Types.LOAD_PRODUCTS_REQUEST]: state => ({ ...state, loading: true }),
19+
[Types.LOAD_PRODUCTS_SUCCESS]: (state, { items }) => ({ ...state, items, loading: false }),
1820
});

yarn.lock

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5762,6 +5762,14 @@ prop-types-exact@^1.2.0:
57625762
object.assign "^4.1.0"
57635763
reflect.ownkeys "^0.2.0"
57645764

5765+
5766+
version "15.6.2"
5767+
resolved "https://registry.yarnpkg.com/prop-types/-/prop-types-15.6.2.tgz#05d5ca77b4453e985d60fc7ff8c859094a497102"
5768+
integrity sha512-3pboPvLiWD7dkI3qf3KbUe6hKFKa52w+AE0VCqECtf+QHAKgOL37tTaNCnuX1nAAQ4ZhyP+kYVKf8rLmJ/feDQ==
5769+
dependencies:
5770+
loose-envify "^1.3.1"
5771+
object-assign "^4.1.1"
5772+
57655773
prop-types@^15.5.10, prop-types@^15.5.4, prop-types@^15.5.8, prop-types@^15.6.1, prop-types@^15.6.2, prop-types@^15.7.2:
57665774
version "15.7.2"
57675775
resolved "https://registry.yarnpkg.com/prop-types/-/prop-types-15.7.2.tgz#52c41e75b8c87e72b9d9360e0206b99dcbffa6c5"
@@ -6435,6 +6443,13 @@ [email protected]:
64356443
resolved "https://registry.yarnpkg.com/rn-host-detect/-/rn-host-detect-1.1.5.tgz#fbecb982b73932f34529e97932b9a63e58d8deb6"
64366444
integrity sha512-ufk2dFT3QeP9HyZ/xTuMtW27KnFy815CYitJMqQm+pgG3ZAtHBsrU8nXizNKkqXGy3bQmhEoloVbrfbvMJMqkg==
64376445

6446+
rn-placeholder@^2.0.0:
6447+
version "2.0.0"
6448+
resolved "https://registry.yarnpkg.com/rn-placeholder/-/rn-placeholder-2.0.0.tgz#8d72a432e9a6b02f0b3cb7de8ddf22b200b80ffd"
6449+
integrity sha512-bVy0GYu3LrxR0o/fGo09YN3a4OR13f6/Y1HFZ0s9f/ejUZWU2E1cvmNuPmPvEyjRQATa8NQcwNhB0CvXFJhbSg==
6450+
dependencies:
6451+
prop-types "15.6.2"
6452+
64386453
rst-selector-parser@^2.2.3:
64396454
version "2.2.3"
64406455
resolved "https://registry.yarnpkg.com/rst-selector-parser/-/rst-selector-parser-2.2.3.tgz#81b230ea2fcc6066c89e3472de794285d9b03d91"

0 commit comments

Comments
 (0)