Skip to content

Commit 1b48357

Browse files
committed
Update README
1 parent 4f2483d commit 1b48357

File tree

8 files changed

+183
-4
lines changed

8 files changed

+183
-4
lines changed

β€Ž.npmignoreβ€Ž

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
example/
2-
demo.gif
3-
demo.mp4
2+
demo/

β€ŽREADME.mdβ€Ž

Lines changed: 182 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,182 @@
1-
# react-native-userpic
2-
React native user picture with gravatar support.
1+
# React Native Userpic
2+
3+
Full featured and highly customizable React Native component to display user avatars. The component allows you to show gravatar images, fallback to user's initials, fine tune shape and size, add badges and custom statuses to avatar image.
4+
5+
---
6+
7+
<img width="200" align="left" src="https://user-images.githubusercontent.com/4656448/173195684-55d89be7-7037-4050-a5e3-6beb85b38b7b.png" />
8+
9+
**Shape that fits your design**
10+
Square, circle, rounded borders. For your convenience, the `borderRadius` prop supports percent values just like in CSS.
11+
12+
---
13+
14+
<img width="200" align="left" src="https://user-images.githubusercontent.com/4656448/173195937-eb636936-181d-4acb-b404-c851ddeb9d1a.png" />
15+
16+
**Custom fallback image or even emoji**
17+
For users without an image you can leave the default profile icon, or use your own fallback image, or even show an emoji.
18+
19+
---
20+
21+
<img width="200" align="left" src="https://user-images.githubusercontent.com/4656448/173196145-b06e448d-b31b-4df9-a751-d2c6d84600a4.png" />
22+
23+
**Fallback to user's initials**
24+
Another option for those who have no image is to display their initials. The `colorize` option will generate unique colors based on user's name.
25+
26+
---
27+
28+
<img width="200" align="left" src="https://user-images.githubusercontent.com/4656448/173196152-2b0dc063-443c-4910-bc42-2f7b11e85761.png" />
29+
30+
**Gravatar support**
31+
Add user's email address to display their gravatar image. This can be combined with your own avatar images as a fallback option.
32+
33+
---
34+
35+
<img width="200" align="left" src="https://user-images.githubusercontent.com/4656448/173196169-4fda6644-49e0-4ef8-8eb2-5682a36dd48a.png" />
36+
37+
**Numeric badges**
38+
You can add a badge to display unread messages count, or user's online/offline status. Badge position can be customized as well.
39+
40+
---
41+
42+
<img width="200" align="left" src="https://user-images.githubusercontent.com/4656448/173196176-51a670e3-9d4c-4102-8c5e-460c51bb6853.png" />
43+
44+
**Custom badges**
45+
Another way of using badges is allowing your users to attach a status icon to their avatar by picking up an emoji.
46+
47+
---
48+
49+
## Installation
50+
51+
```sh
52+
yarn add react-native-userpic
53+
# or
54+
npm install react-native-userpic
55+
```
56+
57+
## Usage
58+
59+
```jsx
60+
import React from 'react';
61+
import { View, StyleSheet } from 'react-native';
62+
import { Userpic } from 'react-native-userpic';
63+
64+
const MyComponent = ({ userImage, userEmail }) => (
65+
<View style={styles.wrapper}>
66+
<Userpic source={{ uri: userImage }} email={userEmail} />
67+
</View>
68+
);
69+
70+
const styles = StyleSheet.create({
71+
wrapper: {
72+
flex: 1,
73+
alignItems: 'center',
74+
justifyContent: 'center',
75+
},
76+
});
77+
78+
export default MyComponent;
79+
```
80+
81+
## Advanced example
82+
83+
```jsx
84+
import React from 'react';
85+
import { View, StyleSheet } from 'react-native';
86+
import { Userpic } from 'react-native-userpic';
87+
88+
const defaultImage = require('./assets/defaultAvatar.png');
89+
const badgeProps = {
90+
size: 30,
91+
borderRadius: 5,
92+
}
93+
94+
const MyComponent = ({ userImage, userEmail, userName }) => (
95+
<View style={styles.wrapper}>
96+
<Userpic
97+
size={75}
98+
defaultSource={defaultImage}
99+
source={{ uri: userImage }}
100+
email={userEmail}
101+
name={userName}
102+
colorize={true}
103+
borderRadius="25%"
104+
badge={35}
105+
badgeColor="#007aff"
106+
badgeProps={badgeProps}
107+
/>
108+
</View>
109+
);
110+
111+
const styles = StyleSheet.create({
112+
wrapper: {
113+
flex: 1,
114+
alignItems: 'center',
115+
justifyContent: 'center',
116+
},
117+
});
118+
119+
export default MyComponent;
120+
```
121+
122+
## Props
123+
124+
Prop | Type | Default | Description
125+
---|---|---|---
126+
`size` | number | 50 | Size of the image
127+
`borderRadius` | number \| string | '50%' | In addition to a number you can use percentage strings "0%...50%" where "50%" creates circle shape
128+
`name` | string | | User name for showing initials when no image provided
129+
`email` | string | | User email for showing their gravatar image
130+
`colorize` | boolean | false | This will generate a unique color when showing initials
131+
`source` | ImageSourcePropType | | The image source (either a remote URL or a local file resource)
132+
`defaultSource` | ImageSourcePropType | | The fallback image source
133+
`style` | ViewStyle | | Style of the container
134+
`textStyle` | TextStyle | | Style of the initials text
135+
`imageStyle` | ImageStyle | | Style of the image
136+
`badge` | number \| boolean \| string | | A number or string value to show in the badge, passing `true` will show a color dot
137+
`badgeColor` | string | | Color of the badge
138+
`badgePosition` | string | 'top-right' | Possible values are `top-right`, `bottom-right`, `bottom-left`, `top-left'`
139+
`badgeProps` | BadgeProps | | See [badge props](#badge-props) below
140+
141+
## Badge
142+
143+
You can also use the badge as a stand-alone component.
144+
145+
```jsx
146+
import React from 'react';
147+
import { View, StyleSheet } from 'react-native';
148+
import { Badge } from 'react-native-userpic';
149+
150+
const MyComponent = ({ count }) => (
151+
<View style={styles.wrapper}>
152+
<Badge value={count} color="#34c759" size={30} animate={false} />
153+
</View>
154+
);
155+
156+
const styles = StyleSheet.create({
157+
wrapper: {
158+
flex: 1,
159+
alignItems: 'center',
160+
justifyContent: 'center',
161+
},
162+
});
163+
164+
export default MyComponent;
165+
```
166+
167+
## Badge props
168+
169+
Prop | Type | Default | Description
170+
---|---|---|---
171+
`size` | number | 20 | Size (height) of the badge
172+
`color` | string | '#ff3b30' | Background color of the badge
173+
`borderRadius` | number \| string | '50%' | In addition to a number you can use percentage strings "0%...50%" where "50%" creates a circle or pill shape
174+
`animate` | boolean | true | When `true`, the badge will appear with a spring animation
175+
`value` | number \| boolean \| string | | A number or string value to show in the badge, passing `true` will show a color dot
176+
`limit` | number \| boolean | 99 | Will show "99+" when the value exceeds the limit, set `false` to turn it off
177+
`style` | ViewStyle | | Style of the container
178+
`textStyle` | TextStyle | | Style of the text value
179+
180+
## License
181+
182+
MIT

β€Ždemo/badge.pngβ€Ž

57.2 KB
Loading

β€Ždemo/default.pngβ€Ž

19.9 KB
Loading

β€Ždemo/gravatar.pngβ€Ž

61.7 KB
Loading

β€Ždemo/initials.pngβ€Ž

15.6 KB
Loading

β€Ždemo/shape.pngβ€Ž

6.24 KB
Loading

β€Ždemo/status.pngβ€Ž

59.9 KB
Loading

0 commit comments

Comments
Β (0)