Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: remove adorable icons requirements
- Loading branch information
Showing
15 changed files
with
102 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,95 @@ | ||
import React from 'react' | ||
import { Image } from 'react-native' | ||
import { Text, View } from 'react-native' | ||
import { | ||
blue, | ||
blue25, | ||
green, | ||
green25, | ||
pink, | ||
pink25, | ||
orange, | ||
orange25, | ||
purple, | ||
purple25, | ||
} from '@berty/common/constants/colors' | ||
import { fingerprint } from '@berty/common/helpers/fingerprint' | ||
import { conversation } from '@berty/common/helpers/entity' | ||
|
||
const Avatar = ({ data, size = 40, margin = 4, uri = null, style = [] }) => { | ||
if (uri !== null) { | ||
return ( | ||
<Image | ||
style={[ | ||
{ width: size, height: size, borderRadius: size / 2, margin: margin }, | ||
...style, | ||
]} | ||
source={{ | ||
uri: uri, | ||
}} | ||
/> | ||
) | ||
} | ||
// From https://fluentcolors.com/ | ||
const pastels = [ | ||
{ default: blue, light: blue25 }, | ||
{ default: green, light: green25 }, | ||
{ default: pink, light: pink25 }, | ||
{ default: orange, light: orange25 }, | ||
{ default: purple, light: purple25 }, | ||
] | ||
|
||
const Avatar = ({ | ||
id, | ||
name, | ||
size = 40, | ||
margin = 4, | ||
uri = null, | ||
style = [], | ||
}) => { | ||
if (!(style instanceof Array)) { | ||
style = [style] | ||
} | ||
|
||
if (!data || !data.id) { | ||
console.error(['No id provided', data]) | ||
return null | ||
} | ||
const hexCode = fingerprint(id).substring(0, 16) | ||
|
||
const extractedPublicKey = data.id | ||
const initials = name | ||
? name | ||
.replace(' ', '') | ||
.substring(0, 2) | ||
.toLocaleUpperCase() | ||
: '?' | ||
|
||
const hexCode = fingerprint(extractedPublicKey || data.id).substring(0, 16) | ||
const retinaMode = 2 | ||
let colorIdx = | ||
parseInt(hexCode.substring(hexCode.length - 2, hexCode.length), 16) % | ||
pastels.length | ||
|
||
return ( | ||
<Image | ||
<View | ||
style={[ | ||
{ width: size, height: size, borderRadius: size / 2, margin: margin }, | ||
{ | ||
width: size, | ||
height: size, | ||
borderRadius: size / 2, | ||
margin: margin, | ||
backgroundColor: pastels[colorIdx].light, | ||
}, | ||
...style, | ||
]} | ||
source={{ | ||
uri: `https://api.adorable.io/avatars/${size * | ||
retinaMode}/${hexCode}.png`, | ||
}} | ||
/> | ||
> | ||
<Text | ||
style={{ | ||
color: pastels[colorIdx].default, | ||
paddingTop: size / 4.4, | ||
fontSize: size / 2.2, | ||
textAlign: 'center', | ||
}} | ||
> | ||
{initials} | ||
</Text> | ||
</View> | ||
) | ||
} | ||
|
||
export const ContactAvatar = ({ data = {}, ...props }) => ( | ||
<Avatar id={data.id} name={data.displayName} {...props} /> | ||
) | ||
Avatar.Contact = ContactAvatar | ||
|
||
export const ConversationAvatar = ({ data = {}, ...props }) => | ||
data.kind === 1 ? ( | ||
<ContactAvatar | ||
data={data.members.find(_ => _.contact.status !== 42)?.contact} | ||
{...props} | ||
/> | ||
) : ( | ||
<Avatar id={data.id} name={conversation.getTitle(data)} {...props} /> | ||
) | ||
Avatar.Conversation = ConversationAvatar | ||
|
||
export default Avatar |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters