about summary refs log tree commit diff
path: root/src/view/com/util/UserAvatar.tsx
diff options
context:
space:
mode:
authorPaul Frazee <pfrazee@gmail.com>2022-12-08 13:45:23 -0600
committerPaul Frazee <pfrazee@gmail.com>2022-12-08 13:45:23 -0600
commit539bf5d35069a654fb31b1ff636358fe28793c06 (patch)
tree89672e39e506ff3898aa1e4b9a306b6b31d89b47 /src/view/com/util/UserAvatar.tsx
parent273e6d29734153e86a4b42b7e81d05fe5627f649 (diff)
downloadvoidsky-539bf5d35069a654fb31b1ff636358fe28793c06.tar.zst
Add avatar images and fix some type signatures
Diffstat (limited to 'src/view/com/util/UserAvatar.tsx')
-rw-r--r--src/view/com/util/UserAvatar.tsx53
1 files changed, 26 insertions, 27 deletions
diff --git a/src/view/com/util/UserAvatar.tsx b/src/view/com/util/UserAvatar.tsx
index 05a0a9ed9..f4ac4a322 100644
--- a/src/view/com/util/UserAvatar.tsx
+++ b/src/view/com/util/UserAvatar.tsx
@@ -6,23 +6,23 @@ import {
   openCamera,
   openCropper,
   openPicker,
+  Image as PickedImage,
 } from 'react-native-image-crop-picker'
 import {getGradient} from '../../lib/asset-gen'
 import {colors} from '../../lib/styles'
-import {IMAGES_ENABLED} from '../../../build-flags'
 
 export function UserAvatar({
   size,
   handle,
-  userAvatar,
+  avatar,
   displayName,
-  setUserAvatar,
+  onSelectNewAvatar,
 }: {
   size: number
   handle: string
   displayName: string | undefined
-  userAvatar?: string | null
-  setUserAvatar?: React.Dispatch<React.SetStateAction<string | null>>
+  avatar?: string | null
+  onSelectNewAvatar?: (img: PickedImage) => void
 }) {
   const initials = getInitials(displayName || handle)
   const gradient = getGradient(handle)
@@ -35,14 +35,12 @@ export function UserAvatar({
           openCamera({
             mediaType: 'photo',
             cropping: true,
-            width: 80,
-            height: 80,
+            width: 400,
+            height: 400,
             cropperCircleOverlay: true,
-          }).then(item => {
-            if (setUserAvatar != null) {
-              setUserAvatar(item.path)
-            }
-          })
+            forceJpg: true, // ios only
+            compressImageQuality: 0.7,
+          }).then(onSelectNewAvatar)
         },
       },
       {
@@ -54,19 +52,17 @@ export function UserAvatar({
             await openCropper({
               mediaType: 'photo',
               path: item.path,
-              width: 80,
-              height: 80,
+              width: 400,
+              height: 400,
               cropperCircleOverlay: true,
-            }).then(croppedItem => {
-              if (setUserAvatar != null) {
-                setUserAvatar(croppedItem.path)
-              }
-            })
+              forceJpg: true, // ios only
+              compressImageQuality: 0.7,
+            }).then(onSelectNewAvatar)
           })
         },
       },
     ])
-  }, [setUserAvatar])
+  }, [onSelectNewAvatar])
 
   const renderSvg = (size: number, initials: string) => (
     <Svg width={size} height={size} viewBox="0 0 100 100">
@@ -89,11 +85,14 @@ export function UserAvatar({
     </Svg>
   )
 
-  // setUserAvatar is only passed as prop on the EditProfile component
-  return setUserAvatar != null && IMAGES_ENABLED ? (
+  // onSelectNewAvatar is only passed as prop on the EditProfile component
+  return onSelectNewAvatar ? (
     <TouchableOpacity onPress={handleEditAvatar}>
-      {userAvatar ? (
-        <Image style={styles.avatarImage} source={{uri: userAvatar}} />
+      {avatar ? (
+        <Image
+          style={{width: size, height: size, borderRadius: (size / 2) | 0}}
+          source={{uri: avatar}}
+        />
       ) : (
         renderSvg(size, initials)
       )}
@@ -105,11 +104,11 @@ export function UserAvatar({
         />
       </View>
     </TouchableOpacity>
-  ) : userAvatar ? (
+  ) : avatar ? (
     <Image
-      style={styles.avatarImage}
+      style={{width: size, height: size, borderRadius: (size / 2) | 0}}
       resizeMode="stretch"
-      source={{uri: userAvatar}}
+      source={{uri: avatar}}
     />
   ) : (
     renderSvg(size, initials)