react-native#CameraRoll JavaScript Examples

The following examples show how to use react-native#CameraRoll. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ImageUtil.js    From RRWallet with MIT License 6 votes vote down vote up
async function saveToCameraRoll(uri) {
  if (!_.isString(uri) || uri.length <= 0) {
    throw new Error(ERROR_MESSAGE_SAVE_IMAGE);
  }
  if (Platform.OS === "android") {
    try {
      const granted = await PermissionsAndroid.request(PermissionsAndroid.PERMISSIONS.WRITE_EXTERNAL_STORAGE);
      if (granted !== PermissionsAndroid.RESULTS.GRANTED) {
        throw new Error(ERROR_MESSAGE_SAVE_IMAGE);
      }
    } catch (err) {
      throw new Error(ERROR_MESSAGE_SAVE_IMAGE);
    }
  }
  try {
    await CameraRoll.saveToCameraRoll(uri);
  } catch (error) {
    throw new Error(ERROR_MESSAGE_SAVE_IMAGE);
  }
}