-
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.
- Loading branch information
Showing
3 changed files
with
59 additions
and
7 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,37 @@ | ||
import * as ImagePicker from "expo-image-picker"; | ||
import { Alert } from "react-native"; | ||
|
||
export const useSingleImagePicker = () => { | ||
const pickImage = async () => { | ||
try { | ||
const { status } = | ||
await ImagePicker.requestMediaLibraryPermissionsAsync(); | ||
|
||
if (status !== "granted") { | ||
Alert.alert( | ||
"Photo Library Access Required", | ||
"Calorily needs access to your photos. You can enable it in your iOS settings." | ||
); | ||
return null; | ||
} | ||
|
||
const result = await ImagePicker.launchImageLibraryAsync({ | ||
mediaTypes: ImagePicker.MediaTypeOptions.Images, | ||
allowsMultipleSelection: false, | ||
quality: 0.075, | ||
}); | ||
|
||
if (!result.canceled && result.assets) { | ||
return result.assets[0].uri; | ||
} | ||
|
||
return null; | ||
} catch (error) { | ||
console.error("Error picking image:", error); | ||
Alert.alert("Error", "Failed to load photo. Please try again."); | ||
return null; | ||
} | ||
}; | ||
|
||
return { pickImage }; | ||
}; |