-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: upload profile picture --------- Signed-off-by: Iuri Pereira <[email protected]>
- Loading branch information
Showing
17 changed files
with
790 additions
and
592 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
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,51 @@ | ||
import React, { useState } from 'react'; | ||
import { TouchableOpacity } from 'react-native'; | ||
import * as ImagePicker from 'expo-image-picker'; | ||
import { useGnoNativeContext } from '@gnolang/gnonative'; | ||
import { compressImage } from '@gno/utils/file-utils'; | ||
import { reloadAvatar, saveAvatar, selectAccount, selectAvatar, useAppDispatch, useAppSelector } from "@gno/redux"; | ||
import Avatar from './avatar'; | ||
|
||
const AvatarPicker: React.FC = () => { | ||
const [base64Image, setBase64Image] = useState<string | null>(null); | ||
|
||
const { gnonative } = useGnoNativeContext(); | ||
|
||
const account = useAppSelector(selectAccount); | ||
const avatarBase64 = useAppSelector(selectAvatar); | ||
|
||
const dispatch = useAppDispatch(); | ||
|
||
const pickImage = async () => { | ||
let result = await ImagePicker.launchImageLibraryAsync({ | ||
mediaTypes: ImagePicker.MediaTypeOptions.Images, | ||
allowsEditing: true, | ||
aspect: [4, 3], | ||
quality: 0.5, // compress image for smaller size | ||
}); | ||
|
||
if (!result.canceled) { | ||
|
||
const imagePath = result.assets[0].uri; | ||
const mimeType = result.assets[0].mimeType; | ||
|
||
const imageCompressed = await compressImage(imagePath) | ||
if (!imageCompressed || !mimeType || !imageCompressed.base64) { | ||
console.log("Error compressing image or missing data"); | ||
return; | ||
} | ||
await dispatch(saveAvatar({ mimeType, base64: imageCompressed.base64 })).unwrap(); | ||
|
||
await dispatch(reloadAvatar()).unwrap(); | ||
} | ||
} | ||
|
||
return ( | ||
<TouchableOpacity onPress={pickImage} > | ||
{base64Image ? <Avatar uri={base64Image} /> : null} | ||
{avatarBase64 ? <Avatar uri={avatarBase64} /> : null} | ||
</TouchableOpacity> | ||
) | ||
} | ||
|
||
export default AvatarPicker |
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,26 @@ | ||
import { View, Image, StyleSheet, StyleProp, ImageStyle } from "react-native"; | ||
|
||
interface Props { | ||
uri: string; | ||
style?: StyleProp<ImageStyle>; | ||
} | ||
|
||
const Avatar: React.FC<Props> = ({ uri, style }) => { | ||
return ( | ||
<View> | ||
<Image source={{ uri }} style={[styles.image, style]} /> | ||
</View> | ||
); | ||
}; | ||
|
||
const SIZE = 80; | ||
|
||
const styles = StyleSheet.create({ | ||
image: { | ||
width: SIZE, | ||
height: SIZE, | ||
borderRadius: SIZE, | ||
}, | ||
}); | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export * from "./view"; | ||
export * from "./avatar"; |
Oops, something went wrong.