-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[dev-launcher] Update user avatars to use the same logic as the websi…
…te (expo#23114) # Why Closes ENG-7614 # How This PR adds a building icon to `dev-client-components` (the same one used on the website) and adds a `Avatar` component to `dev-launcher` to handle all the logic for rendering an account avatar. # Test Plan Run dev-client through bare-expo <table> <tr><th>Android</th><th>iOS</th></tr> <tr> <td> <video src="https://github.com/expo/expo/assets/11707729/f1ce2d4f-a1e1-4988-85d7-5250a3a2ad23"/> </td> <td> <video src="https://github.com/expo/expo/assets/11707729/d5a7df31-2dd8-47ce-8580-f4a0b7e1cf5b" /> </td> </tr> </table> # Checklist <!-- Please check the appropriate items below if they apply to your diff. This is required for changes to Expo modules. --> - [ ] Documentation is up to date to reflect these changes (eg: https://docs.expo.dev and README.md). - [ ] Conforms with the [Documentation Writing Style Guide](https://github.com/expo/expo/blob/main/guides/Expo%20Documentation%20Writing%20Style%20Guide.md) - [ ] This diff will work correctly for `npx expo prebuild` & EAS Build (eg: updated a module plugin).
- Loading branch information
1 parent
cfeebad
commit fd7025d
Showing
18 changed files
with
611 additions
and
500 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions
9
packages/expo-dev-client-components/src/icons/BuildingIcon.tsx
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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import * as React from 'react'; | ||
|
||
import { Image } from '../Image'; | ||
|
||
const icon = require('../../assets/building-icon.png'); | ||
|
||
export function BuildingIcon(props: Partial<React.ComponentProps<typeof Image>>) { | ||
return <Image source={icon} {...props} />; | ||
} |
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
477 changes: 240 additions & 237 deletions
477
packages/expo-dev-launcher/android/src/debug/assets/expo_dev_launcher_android.bundle
Large diffs are not rendered by default.
Oops, something went wrong.
Binary file added
BIN
+225 Bytes
...id/src/debug/res/drawable-mdpi/_expodevclientcomponents_assets_buildingicon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+306 Bytes
...d/src/debug/res/drawable-xhdpi/_expodevclientcomponents_assets_buildingicon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+398 Bytes
.../src/debug/res/drawable-xxhdpi/_expodevclientcomponents_assets_buildingicon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 |
---|---|---|
@@ -0,0 +1,96 @@ | ||
import { iconSize, palette } from '@expo/styleguide-native'; | ||
import { View, Image, scale, BuildingIcon, UserIcon } from 'expo-dev-client-components'; | ||
import React from 'react'; | ||
import { StyleSheet } from 'react-native'; | ||
|
||
type Props = { | ||
name?: string; | ||
profilePhoto?: string; | ||
isOrganization?: boolean; | ||
size?: React.ComponentProps<typeof Image>['size']; | ||
}; | ||
|
||
export function Avatar({ profilePhoto, size = 'large', name = '', isOrganization = false }: Props) { | ||
const firstLetter = name?.charAt(0).toLowerCase(); | ||
const viewSize = getViewSize(size); | ||
|
||
if (isOrganization) { | ||
const { backgroundColor, tintColor } = getOrganizationColor(firstLetter); | ||
return ( | ||
<View | ||
style={{ | ||
height: viewSize, | ||
width: viewSize, | ||
backgroundColor, | ||
}} | ||
rounded="full" | ||
align="centered" | ||
bg="secondary"> | ||
<BuildingIcon resizeMode="center" style={styles.icon} tintColor={tintColor} /> | ||
</View> | ||
); | ||
} | ||
|
||
if (!profilePhoto || !firstLetter) { | ||
return ( | ||
<View | ||
style={{ height: viewSize, width: viewSize }} | ||
rounded="full" | ||
align="centered" | ||
bg="secondary"> | ||
<UserIcon resizeMode="center" style={styles.icon} /> | ||
</View> | ||
); | ||
} | ||
|
||
let _profilePhoto = profilePhoto; | ||
if (profilePhoto.match('gravatar.com')) { | ||
const defaultProfilePhoto = encodeURIComponent( | ||
`https://storage.googleapis.com/expo-website-default-avatars-2023/${firstLetter}.png` | ||
); | ||
_profilePhoto = `${profilePhoto}&d=${defaultProfilePhoto}`; | ||
} | ||
|
||
return ( | ||
<View rounded="full" bg="secondary"> | ||
<Image rounded="full" source={{ uri: _profilePhoto }} size={size} /> | ||
</View> | ||
); | ||
} | ||
|
||
function getOrganizationColor(firstLetter?: string) { | ||
if (firstLetter?.match(/[a-d]/)) { | ||
return { backgroundColor: palette.light.blue[200], tintColor: palette.light.blue[900] }; | ||
} else if (firstLetter?.match(/[e-h]/)) { | ||
return { backgroundColor: palette.light.green[200], tintColor: palette.light.green[900] }; | ||
} else if (firstLetter?.match(/[i-l]/)) { | ||
return { backgroundColor: palette.light.yellow[400], tintColor: palette.light.yellow[900] }; | ||
} else if (firstLetter?.match(/[m-p]/)) { | ||
return { backgroundColor: palette.light.orange[200], tintColor: palette.light.orange[900] }; | ||
} else if (firstLetter?.match(/[q-t]/)) { | ||
return { backgroundColor: palette.light.red[200], tintColor: palette.light.red[900] }; | ||
} else if (firstLetter?.match(/[u-z]/)) { | ||
return { backgroundColor: palette.light.pink[200], tintColor: palette.light.pink[900] }; | ||
} else { | ||
return { backgroundColor: palette.light.purple[200], tintColor: palette.light.purple[900] }; | ||
} | ||
} | ||
|
||
function getViewSize(size?: React.ComponentProps<typeof Image>['size']) { | ||
switch (size) { | ||
case 'tiny': | ||
return scale.small; | ||
case 'small': | ||
return iconSize.small; | ||
case 'large': | ||
return iconSize.large; | ||
case 'xl': | ||
return scale.xl; | ||
default: | ||
return iconSize.large; | ||
} | ||
} | ||
|
||
const styles = StyleSheet.create({ | ||
icon: { width: '45%', height: '45%' }, | ||
}); |
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
Binary file added
BIN
+225 Bytes
...po-dev-launcher/ios/assets/_expo-dev-client-components/assets/building-icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+306 Bytes
...dev-launcher/ios/assets/_expo-dev-client-components/assets/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+398 Bytes
...dev-launcher/ios/assets/_expo-dev-client-components/assets/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.