mirror of
https://github.com/pezkuwichain/pezkuwi-mobile-app.git
synced 2026-06-12 18:11:03 +00:00
auto-commit for 629c0ea7-912d-4360-a3b9-11a979f46bfb
This commit is contained in:
@@ -22,16 +22,60 @@ function HomeTab() {
|
||||
const insets = useSafeAreaInsets();
|
||||
const [profileImage, setProfileImage] = useState<string | null>(null);
|
||||
|
||||
const pickImage = async () => {
|
||||
const showImagePickerOptions = () => {
|
||||
Alert.alert(
|
||||
'Change Profile Photo',
|
||||
'Choose an option',
|
||||
[
|
||||
{
|
||||
text: 'Take Photo',
|
||||
onPress: takePhoto,
|
||||
},
|
||||
{
|
||||
text: 'Choose from Gallery',
|
||||
onPress: pickImageFromGallery,
|
||||
},
|
||||
{
|
||||
text: 'Cancel',
|
||||
style: 'cancel',
|
||||
},
|
||||
],
|
||||
{ cancelable: true }
|
||||
);
|
||||
};
|
||||
|
||||
const takePhoto = async () => {
|
||||
const permissionResult = await ImagePicker.requestCameraPermissionsAsync();
|
||||
|
||||
if (permissionResult.granted === false) {
|
||||
Alert.alert('Permission Required', 'Camera permission is required!');
|
||||
return;
|
||||
}
|
||||
|
||||
const result = await ImagePicker.launchCameraAsync({
|
||||
allowsEditing: true,
|
||||
aspect: [1, 1],
|
||||
quality: 0.5,
|
||||
base64: true,
|
||||
});
|
||||
|
||||
if (!result.canceled && result.assets[0].base64) {
|
||||
const base64Image = `data:image/jpeg;base64,${result.assets[0].base64}`;
|
||||
setProfileImage(base64Image);
|
||||
// TODO: Save to backend
|
||||
}
|
||||
};
|
||||
|
||||
const pickImageFromGallery = async () => {
|
||||
const permissionResult = await ImagePicker.requestMediaLibraryPermissionsAsync();
|
||||
|
||||
if (permissionResult.granted === false) {
|
||||
Alert.alert('Permission Required', 'Permission to access camera roll is required!');
|
||||
Alert.alert('Permission Required', 'Gallery access is required!');
|
||||
return;
|
||||
}
|
||||
|
||||
const result = await ImagePicker.launchImageLibraryAsync({
|
||||
mediaTypes: ImagePicker.MediaTypeOptions.Images,
|
||||
mediaTypes: ['images'],
|
||||
allowsEditing: true,
|
||||
aspect: [1, 1],
|
||||
quality: 0.5,
|
||||
|
||||
Reference in New Issue
Block a user