Skip to content

Commit

Permalink
fix(android): ask permission before saving QR code
Browse files Browse the repository at this point in the history
  • Loading branch information
glouvigny committed Feb 4, 2019
1 parent d08200c commit f4313c9
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
19 changes: 17 additions & 2 deletions client/react-native/common/helpers/saveViewToCamera.js
@@ -1,8 +1,10 @@
import ViewShot from 'react-native-view-shot'
import React, { Component } from 'react'
import { View, CameraRoll, Platform } from 'react-native'
import { View, CameraRoll, Platform, PermissionsAndroid } from 'react-native'
import { StackActions } from 'react-navigation'
import NavigationService from './NavigationService'
import { requestAndroidPermission } from './permissions'
import I18n from '../i18n'

export class ViewExportComponent extends Component {
async componentDidMount () {
Expand Down Expand Up @@ -36,7 +38,19 @@ export class ViewExportComponent extends Component {
}

export default async ({ view }) => {
if (Platform.os === 'web') {
if (Platform.OS === 'android') {
const allowed = await requestAndroidPermission({
permission: PermissionsAndroid.PERMISSIONS.WRITE_EXTERNAL_STORAGE,
title: I18n.t('settings.save-picture-perm'),
message: I18n.t('settings.save-picture-perm-desc'),
})

if (!allowed) {
throw new Error(I18n.t('settings.save-picture-perm-denied'))
}
}

if (Platform.OS === 'web') {
throw new Error('unsupported on web')
}

Expand All @@ -48,6 +62,7 @@ export default async ({ view }) => {
view,
})
})

await CameraRoll.saveToCameraRoll(uri, 'photo')
} catch (e) {
throw e
Expand Down
5 changes: 4 additions & 1 deletion client/react-native/common/i18n/en/messages.json
Expand Up @@ -102,7 +102,10 @@
"update-available": "An update is available",
"update-write-fail": "Unable to download app, not allowed to write file",
"update-write-perm": "Write to external storage",
"update-write-perm-desc": "This permission is required to download the application update"
"update-write-perm-desc": "This permission is required to download the application update",
"save-picture-perm": "Save picture",
"save-picture-perm-desc": "This permission is required to save the image to your Camera Roll",
"save-picture-perm-denied": "Unable to save the picture"
},
"chats": {
"title": "Chats",
Expand Down
5 changes: 4 additions & 1 deletion client/react-native/common/i18n/fr/messages.json
Expand Up @@ -102,7 +102,10 @@
"update-available": "Une mise à jour est disponible",
"update-write-fail": "Erreur du téléchargement de l'app, impossible de sauvegarder la mise à jour",
"update-write-perm": "Enregistrer des fichiers",
"update-write-perm-desc": "Cette permission est nécessaire au téléchargement de la mise à jour"
"update-write-perm-desc": "Cette permission est nécessaire au téléchargement de la mise à jour",
"save-picture-perm": "Enregistrer des images",
"save-picture-perm-desc": "Cette permission est nécessaire à l'enregistrement d'images dans votre galerie",
"save-picture-perm-denied": "Impossible d'enregister l'image"
},
"chats": {
"title": "Conversations",
Expand Down

0 comments on commit f4313c9

Please sign in to comment.