Skip to content

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
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
+196
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+
```

next/pages/components/avatar/ios.mdx

+84
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
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: 'ios',
12+
},
13+
};
14+
15+
import { Img } from '../../../components/mdx/components';
16+
17+
import avatarOnlineNow from '../../../images/pages/components/avatar/ios/online-now.png';
18+
import avatarVariations from '../../../images/pages/components/avatar/ios/variations.png';
19+
20+
## Summary
21+
22+
Avatars provide a container for displaying Entity or User images on Thumbtack. This `UIView` container displays either the filled images after loading the image via URL or the blank Avatar view if there’s no backing image and initials are provided.
23+
24+
Use `EntityAvatar` or `UserAvatar` classes directly depending on the object to be displayed.
25+
26+
<div>
27+
<b>Entity</b>: a company, business, or service.
28+
</div>
29+
30+
<div>
31+
<b>User</b>: a person or user.
32+
</div>
33+
34+
<Img {...avatarVariations} className="db mw6 m_h-auto" fill={false}></Img>
35+
36+
```swift
37+
let entityAvatar = EntityAvatar(size: .medium)
38+
entityAvatar.name = "Nicolas Cage"
39+
entityAvatar.initials = "NC"
40+
entityAvatar.setImageURL(avatarImageURL)
41+
42+
let userAvatar = UserAvatar(size: .medium)
43+
userAvatar.name = "Nicolas Cage"
44+
userAvatar.initials = "NC"
45+
userAvatar.setImageURL(avatarImageURL)
46+
```
47+
48+
## Accessibility
49+
50+
Provide the `name` property to override the view’s accessibility label. If not provided, the accessibility label will be `nil`.
51+
52+
## Public API
53+
54+
### `public var image: UIImage?`
55+
56+
The image displayed in the avatar image view.
57+
58+
### `public var size: Avatar.Size`
59+
60+
One of the provided avatar sizes: `xSmall`, `small`, `medium`, `large`, `xLarge`
61+
62+
### `public var isOnline: Bool`
63+
64+
Boolean value that controls whether the online badge is shown or not.
65+
66+
<Img {...avatarOnlineNow} className="db mw6 m_h-auto" fill={false}></Img>
67+
68+
### `public var initials: String?`
69+
70+
The initials to be shown when displaying the blank avatar. Any string longer than one character will be truncated for display.
71+
72+
### `public var name: String?`
73+
74+
Used for accessibility label for the avatar.
75+
76+
### `public init(size: Avatar.Size, initials: String? = nil, name: String? = nil, isOnline: Bool = false)`
77+
78+
Initializes an EntityAvatar/UserAvatar. Parameters: size: The initial `Avatar.Size` class for the component. initials: Any string longer that one character will be truncated for display. name: Used for accessibility label for the avatar.
79+
80+
_Note_ A URL extension is provided for utility for loading a remote image. It is not part of the core Thumbprint API as it relies on SDWebImage.
81+
82+
### `func setImageURL(_ url: URL?) -> SDWebImageOperation?`
83+
84+
Loads an image from the given URL and sets a blank placeholder image while loading. Once loaded, the image is displayed in the Avatar.

0 commit comments

Comments
 (0)