-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathREADME.md
More file actions
155 lines (116 loc) · 5.02 KB
/
README.md
File metadata and controls
155 lines (116 loc) · 5.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
## React Native Skeleton
[](https://www.npmjs.com/package/react-native-skeleton-component)
[](https://www.npmjs.com/package/react-native-skeleton-component)
[](https://www.npmjs.com/package/react-native-skeleton-component)
[](https://www.npmjs.com/package/react-native-skeleton-component)
[](https://www.npmjs.com/package/react-native-skeleton-component)
React Native Skeleton is a react-native and react-native-web library to easily create a loading effect.
### Installation
#### Step #1
Using yarn:
```bash
yarn add react-native-skeleton-component
```
Using npm:
```bash
npm install react-native-skeleton-component --save
```
#### Step #2 (Mobile Only)
> Note: Only if you are using this package on `react-native` it requires the dependency **@react-native-masked-view/masked-view** for the `wave` animation (only available on mobile).<br/>If your project includes the react-navigation >= 4.x you probably already have it installed and you can SKIP this step.
Using yarn:
```bash
yarn add @react-native-masked-view/masked-view
```
Using npm:
```bash
npm install @react-native-masked-view/masked-view --save
```
If you are running a **react-native** version below 0.60:
```bash
react-native link @react-native-masked-view/masked-view
```
Otherwise:
```bash
cd ios
pod install
```
### Example
Check the following example to see it in action and try changing the default props to see how it works.
[](https://snack.expo.io/@nicolaslazzos/react-native-skeleton-component-example)
### Usage
You always need to wrap the skeletons with the `SkeletonContainer` like in the following example.
```javascript
import React from 'react';
import { View, StyleSheet } from 'react-native';
import { SkeletonContainer, Skeleton } from 'react-native-skeleton-component';
const App = () => {
return (
<SkeletonContainer>
<View style={styles.container}>
<Skeleton style={styles.avatar} />
<View style={styles.textContainer}>
<Skeleton style={styles.title} />
<Skeleton style={styles.subtitle} />
</View>
<Skeleton style={styles.icon} />
</View>
</SkeletonContainer>
);
};
const styles = StyleSheet.create({
container: { flexDirection: 'row', alignItems: 'center', marginBottom: 16 },
avatar: { height: 40, width: 40, borderRadius: 0 },
textContainer: { flex: 1, marginLeft: 16 },
title: { width: '90%', height: 14, borderRadius: 7, marginBottom: 5 },
subtitle: { width: '70%', height: 14, borderRadius: 7 },
icon: { height: 16, width: 16, borderRadius: 4 },
});
```
Also you can do things like this.
```javascript
import React from "react";
import { View } from "react-native";
import { SkeletonContainer, Skeleton } from "react-native-skeleton-component";
const App = () => {
return (
<SkeletonContainer>
<ListItem />
<ListItem />
<ListItem />
</SkeletonContainer>
);
};
const ListItem = () => {
return (
<View style={styles.container}>
<Skeleton style={styles.avatar} />
<View style={styles.textContainer}>
<Skeleton style={styles.title} />
<Skeleton style={styles.subtitle} />
</View>
<Skeleton style={styles.icon} />
</View>
);
};
const styles = StyleSheet.create({
container: { flexDirection: 'row', alignItems: 'center', marginBottom: 16 },
avatar: { height: 40, width: 40, borderRadius: 0 },
textContainer: { flex: 1, marginLeft: 16 },
title: { width: '90%', height: 14, borderRadius: 7, marginBottom: 5 },
subtitle: { width: '70%', height: 14, borderRadius: 7 },
icon: { height: 16, width: 16, borderRadius: 4 },
});
```
### Properties
#### SkeletonContainer
| Prop | Description | Type | Default |
| :-------------: | :--------------------------------------------: | :----: | :-------: |
| backgroundColor | Determines the color of placeholder | `string` | `#E1E9EE` |
| highlightColor | Determines the highlight color of placeholder | `string` | `#EDF3F7` |
| speed | Determines the animation speed in milliseconds | `number` | `800` |
| animation | Determines type of animation for the skeletons | `wave`, `pulse` or `none` | `pulse` |
> Note: The `wave` animaton is only available for mobile, because it makes use of the `@react-native-masked-view/masked-view` package.
#### Skeleton
Accepts any `View` prop.
### License
[MIT](https://choosealicense.com/licenses/mit/)