How to use the react-native-unimodules.Permissions.CAMERA function in react-native-unimodules

To help you get started, we’ve selected a few react-native-unimodules examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github NervJS / taro / packages / taro-rn / src / api / media / chooseMedia.js View on Github external
async function chooseMedia (opts, mediaTypes) {
  if (!opts || typeof opts !== 'object') {
    opts = {}
  }
  const { sizeType = [], sourceType = [], success, fail, complete } = opts
  const options = {
    mediaTypes,
    quality: sizeType[0] === 'compressed' ? 0.7 : 1
  }
  const isCamera = sourceType[0] === 'camera'
  const status = isCamera ? await askAsyncPermissions(Permissions.CAMERA) : await askAsyncPermissions(Permissions.CAMERA_ROLL)
  if (status !== 'granted') {
    const res = { errMsg: 'Permissions denied!' }
    return Promise.reject(res)
  }

  let p
  return new Promise((resolve, reject) => {
    p = isCamera ? ImagePicker.launchCameraAsync(options) : ImagePicker.launchImageLibraryAsync(options)
    p.then((resp) => {
      const { uri } = resp
      resp.path = uri
      const res = {
        tempFilePaths: [uri],
        tempFiles: [resp]
      }
      success && success(res)