Skip to content
This repository was archived by the owner on Sep 9, 2025. It is now read-only.

Commit 349f3c6

Browse files
committed
Revert "Revert "Update avatar documentation (#987)""
This reverts commit d908ad7.
1 parent d908ad7 commit 349f3c6

File tree

20 files changed

+504
-296
lines changed

20 files changed

+504
-296
lines changed
382 KB
Loading
383 KB
Loading
325 KB
Loading
101 KB
Loading
2.98 KB
Loading
2.78 KB
Loading
3.02 KB
Loading
2.49 KB
Loading
33.9 KB
Loading
Lines changed: 196 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,196 @@
1+
import { MDXComponentPage } from '../../../components/mdx/mdx';
2+
import baseGetStaticProps from '../../../utils/mdx-get-static-props';
3+
export const getStaticProps = ctx => baseGetStaticProps(ctx, metadata);
4+
export default props => <MDXComponentPage {...props} {...metadata} />;
5+
6+
export const metadata = {
7+
title: 'Avatar',
8+
description: 'Display user images and badges on Thumbtack.',
9+
component: {
10+
id: 'avatar',
11+
platformId: 'android',
12+
},
13+
};
14+
15+
import { Img } from '../../../components/mdx/components';
16+
17+
import variations from '../../../images/pages/components/avatar/android/variations.png';
18+
import sizes from '../../../images/pages/components/avatar/android/sizes.png';
19+
import withoutImages from '../../../images/pages/components/avatar/android/without-images.png';
20+
import onlineIndicator from '../../../images/pages/components/avatar/android/online-indicator.png';
21+
22+
## Avatar variations
23+
24+
Avatars can be placed in your layout files as either: `EntityAvatarView` or `UserAvatarView`.
25+
26+
<Img
27+
{...variations}
28+
className="db mw7 m_h-auto"
29+
fill={false}
30+
alt="Screenshot of both Avatar types"
31+
></Img>
32+
33+
```xml
34+
<com.thumbtack.thumbprint.views.EntityAvatarView
35+
android:id="@+id/variationEntity"
36+
style="@style/avatarExtraLarge" />
37+
```
38+
39+
```xml
40+
<com.thumbtack.thumbprint.views.UserAvatarView
41+
android:id="@+id/variationUser"
42+
style="@style/avatarExtraLarge"/>
43+
```
44+
45+
```java
46+
variationEntity.bind(imageUrl = NICOLAS_CAGE_URL, initials = "N")
47+
variationUser.bind(imageUrl = NICOLAS_CAGE_URL, initials = "NC")
48+
```
49+
50+
`UserAvatarView` is for people or users whereas `EntityAvatarView` is for companies, businesses, or services.
51+
52+
Note that image URLs and avatar initials are _not_ specified in the layout; those are specified in the avatar's `.bind()` method.
53+
54+
```java
55+
/**
56+
* Begins loading the image from the given [imageUrl], positions and sizes the online badge,
57+
* sets its visiblity based on [isOnline], and create a [BlankAvatarDrawable] as the
58+
* fallback avatar. The [BlankAvatarDrawable] will contain the string [initials] and use the
59+
* colors specified in [BlankAvatarDrawable.setColorsFromInitials], which maps the first letter
60+
* of [initials] to background and text color values.
61+
*
62+
* If no [imageUrl] is given, or if there is an error fetching the image, then the
63+
* [BlankAvatarDrawable] created from [initials] will be displayed. A gray placeholder is shown
64+
* during the image's loading if an [imageUrl] is specified.
65+
*
66+
* If both [imageUrl] and [initials] are unspecified, no avatar will be displayed.
67+
*
68+
* As specified in Thumbprint style guides, entity avatars should pass in one letter
69+
* for [initials] and user avatars should pass in two letters for [initials].
70+
*/
71+
fun bind(imageUrl: String? = null, initials: String? = null, isOnline: Boolean = false) {
72+
...
73+
}
74+
```
75+
76+
## Avatar sizes
77+
78+
Both `UserAvatarView` and `EntityAvatarView` are available in five sizes ranging from `avatarExtraLarge` to `avatarExtraSmall`.
79+
80+
<Img {...sizes} className="db mw7 m_h-auto" fill={false} alt="Avatar sizes"></Img>
81+
82+
```xml
83+
<com.thumbtack.thumbprint.views.UserAvatarView
84+
style="@style/avatarExtraLarge"/>
85+
```
86+
87+
```xml
88+
<com.thumbtack.thumbprint.views.UserAvatarView
89+
style="@style/avatarLarge"/>
90+
```
91+
92+
```xml
93+
<com.thumbtack.thumbprint.views.UserAvatarView
94+
style="@style/avatarMedium"/>
95+
```
96+
97+
```xml
98+
<com.thumbtack.thumbprint.views.UserAvatarView
99+
style="@style/avatarSmall"/>
100+
```
101+
102+
```xml
103+
<com.thumbtack.thumbprint.views.UserAvatarView
104+
style="@style/avatarExtraSmall"/>
105+
```
106+
107+
---
108+
109+
```xml
110+
<com.thumbtack.thumbprint.views.EntityAvatarView
111+
style="@style/avatarExtraLarge"/>
112+
```
113+
114+
```xml
115+
<com.thumbtack.thumbprint.views.EntityAvatarView
116+
style="@style/avatarLarge"/>
117+
```
118+
119+
```xml
120+
<com.thumbtack.thumbprint.views.EntityAvatarView
121+
style="@style/avatarMedium"/>
122+
```
123+
124+
```xml
125+
<com.thumbtack.thumbprint.views.EntityAvatarView
126+
style="@style/avatarSmall"/>
127+
```
128+
129+
```xml
130+
<com.thumbtack.thumbprint.views.EntityAvatarView
131+
style="@style/avatarExtraSmall"/>
132+
```
133+
134+
## Avatars without images
135+
136+
Avatars without images can display the the user or entity’s initials instead. The initials and background colors are assigned based on the first letter in the `initials` parameter of the `.bind()` method.
137+
138+
<Img {...withoutImages} className="db mw7 m_h-auto" fill={false} alt="Avatar Without Images"></Img>
139+
140+
```xml
141+
<LinearLayout
142+
android:id="@+id/noImagesUser"
143+
android:layout_width="wrap_content"
144+
android:layout_height="wrap_content"
145+
android:orientation="horizontal"
146+
android:gravity="center">
147+
148+
<com.thumbtack.thumbprint.views.UserAvatarView
149+
style="@style/avatarMedium"/>
150+
...
151+
152+
</LinearLayout>
153+
```
154+
155+
```xml
156+
<LinearLayout
157+
android:id="@+id/noImagesEntity"
158+
android:layout_width="wrap_content"
159+
android:layout_height="wrap_content"
160+
android:orientation="horizontal"
161+
android:gravity="center">
162+
163+
<com.thumbtack.thumbprint.views.EntityAvatarView
164+
style="@style/avatarMedium"/>
165+
...
166+
167+
</LinearLayout>
168+
```
169+
170+
```java
171+
var letters = sequenceOf("A", "B", "C", "D", "E", "F").iterator()
172+
noImagesUser.forEachChild {
173+
(it as? UserAvatarView)?.bind(imageUrl = null, initials = letters.next() + "A")
174+
}
175+
176+
letters = sequenceOf("A", "B", "C", "D", "E", "F").iterator()
177+
noImagesEntity.forEachChild {
178+
(it as? EntityAvatarView)?.bind(imageUrl = null, initials = letters.next())
179+
}
180+
```
181+
182+
### Online
183+
184+
This badge indicates that a user or entity is online. It can be set initially through the `.bind()` method, or dynamically through the `setIsOnline()` method.
185+
186+
<Img {...onlineIndicator} className="db mw7 m_h-auto" fill={false} alt="Avatar badges"></Img>
187+
188+
```java
189+
badgesUser.forEachChild {
190+
(it as? UserAvatarView)?.bind(imageUrl = NICOLAS_CAGE_URL, isOnline = true)
191+
}
192+
193+
badgesEntity.forEachChild {
194+
(it as? EntityAvatarView)?.bind(imageUrl = NICOLAS_CAGE_URL, isOnline = true)
195+
}
196+
```

0 commit comments

Comments
 (0)