Skip to content

Commit 7211964

Browse files
committed
feat(edit-profile): implement take photo option in profile media
1 parent 40b96f8 commit 7211964

1 file changed

Lines changed: 29 additions & 23 deletions

File tree

src/screens/profile/EditProfileScreen.tsx

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -101,14 +101,14 @@ const EditProfileScreen = () => {
101101
return true;
102102
};
103103

104-
// const requestCameraPermissions = async () => {
105-
// const { status } = await ImagePicker.requestCameraPermissionsAsync();
106-
// if (status !== 'granted') {
107-
// Alert.alert('Permission needed', 'Please grant permission to access your camera');
108-
// return false;
109-
// }
110-
// return true;
111-
// };
104+
const requestCameraPermissions = async () => {
105+
const { status } = await ImagePicker.requestCameraPermissionsAsync();
106+
if (status !== 'granted') {
107+
Alert.alert('Permission needed', 'Please grant permission to access your camera');
108+
return false;
109+
}
110+
return true;
111+
};
112112

113113
const pickImageFromGallery = async () => {
114114
const hasPermission = await requestPermissions();
@@ -141,20 +141,21 @@ const EditProfileScreen = () => {
141141
}
142142
};
143143

144-
// const takePhoto = async () => {
145-
// const hasPermission = await requestCameraPermissions();
146-
// if (!hasPermission) return;
144+
const takePhoto = async () => {
145+
const hasPermission = await requestCameraPermissions();
146+
if (!hasPermission) return;
147147

148-
// const result = await ImagePicker.launchCameraAsync({
149-
// allowsEditing: true,
150-
// aspect: [1, 1],
151-
// quality: 0.8,
152-
// });
148+
const result = await ImagePicker.launchCameraAsync({
149+
allowsEditing: true,
150+
aspect: [1, 1],
151+
quality: 0.8,
152+
});
153153

154-
// if (!result.canceled && result.assets[0]) {
155-
// setProfileImage(result.assets[0].uri);
156-
// }
157-
// };
154+
if (!result.canceled && result.assets[0]) {
155+
if (isEditingBanner) setBannerUrl(result.assets[0].uri);
156+
else setAvatarUrl(result.assets[0].uri);
157+
}
158+
};
158159

159160
const removeBanner = () => {
160161
setBannerUrl(null);
@@ -176,8 +177,7 @@ const EditProfileScreen = () => {
176177
// get new bio entities
177178
formData.bioEntities = getBioEntities(formData.bio);
178179

179-
// update or remove profile avatar
180-
// update or remove profile banner
180+
// to be implemented with mock later: updates to profile media
181181

182182
// update birthday
183183
if (user.birthDate !== birthDate && birthDate) {
@@ -334,7 +334,13 @@ const EditProfileScreen = () => {
334334
>
335335
<Pressable onPress={() => setMenuVisible(false)} style={styles.overlay}>
336336
<View style={styles.dropdown}>
337-
<Pressable style={styles.dropdownItem} onPress={() => {}}>
337+
<Pressable
338+
style={styles.dropdownItem}
339+
onPress={() => {
340+
takePhoto();
341+
setMenuVisible(false);
342+
}}
343+
>
338344
<Text style={styles.dropdownText}>Take Photo</Text>
339345
</Pressable>
340346
<Pressable

0 commit comments

Comments
 (0)