selectImage.js 771 B

12345678910111213141516171819202122232425
  1. import * as Permissions from 'expo-permissions'
  2. import * as ImagePicker from 'expo-image-picker'
  3. function selectImageWithExpo (options) {
  4. return new Promise((resolve, reject) => {
  5. // This is a different `Permissions` object than eslint-plugin-compat thinks it is
  6. // eslint-disable-next-line compat/compat
  7. return Permissions.askAsync(Permissions.CAMERA_ROLL)
  8. .then((isAllowed) => {
  9. if (!isAllowed) {
  10. return reject(new Error('Permissions denied'))
  11. }
  12. return ImagePicker.launchImageLibraryAsync(options)
  13. .then((result) => {
  14. console.log(result)
  15. if (!result.cancelled) {
  16. return resolve(result)
  17. }
  18. })
  19. })
  20. })
  21. }
  22. export default selectImageWithExpo