diff --git a/src/status_im/components/camera.cljs b/src/status_im/components/camera.cljs index d49fb7caf0..2569690e2c 100644 --- a/src/status_im/components/camera.cljs +++ b/src/status_im/components/camera.cljs @@ -1,16 +1,25 @@ (ns status-im.components.camera (:require [reagent.core :as r] - [clojure.walk :refer [keywordize-keys]])) + [clojure.walk :refer [keywordize-keys]] + [status-im.utils.platform :as platform])) (def camera-class (js/require "react-native-camera")) +(def camera-default (.-default camera-class)) (defn constants [t] - (-> (aget camera-class "default" "constants" t) + (-> (aget camera-default "constants" t) (js->clj) (keywordize-keys))) (def aspects (constants "Aspect")) (def capture-targets (constants "CaptureTarget")) +(defn request-access [callback] + (if platform/android? + (callback true) + (let [result (.checkDeviceAuthorizationStatus camera-default) + result (.then result #(callback %)) + result (.catch result #(callback false))]))) + (defn camera [props] - (r/create-element (.-default camera-class) (clj->js (merge {:inverted true} props)))) + (r/create-element camera-default (clj->js (merge {:inverted true} props)))) diff --git a/src/status_im/profile/edit/screen.cljs b/src/status_im/profile/edit/screen.cljs index 65e11f171b..5691188a73 100644 --- a/src/status_im/profile/edit/screen.cljs +++ b/src/status_im/profile/edit/screen.cljs @@ -1,15 +1,19 @@ (ns status-im.profile.edit.screen (:require-macros [status-im.utils.views :refer [defview]]) - (:require [status-im.profile.styles :as st] + (:require [cljs.spec :as s] + [clojure.string :as str] + [reagent.core :as r] + [re-frame.core :refer [dispatch]] + [status-im.profile.styles :as st] [status-im.components.text-input-with-label.view :refer [text-input-with-label]] [status-im.components.styles :refer [color-blue color-gray5]] - [re-frame.core :refer [dispatch]] [status-im.components.status-bar :refer [status-bar]] [status-im.components.toolbar-new.view :refer [toolbar]] [status-im.components.toolbar-new.actions :as act] [status-im.i18n :refer [label]] [status-im.profile.screen :refer [colorize-status-hashtags]] [status-im.components.sticky-button :refer [sticky-button]] + [status-im.components.camera :as camera] [status-im.components.chat-icon.screen :refer [my-profile-icon]] [status-im.components.context-menu :refer [context-menu]] [status-im.profile.validations :as v] @@ -19,11 +23,8 @@ text touchable-highlight text-input]] - [status-im.utils.utils :refer [clean-text]] - [cljs.spec :as s] - [clojure.string :as str] - [status-im.utils.platform :refer [ios?]] - [reagent.core :as r])) + [status-im.utils.utils :as utils :refer [clean-text]] + [status-im.utils.platform :refer [ios?]])) (defn edit-my-profile-toolbartoolbar [] [toolbar {:title (label :t/edit-profile) @@ -43,7 +44,11 @@ :value (fn [] (dispatch [:request-permissions [:camera :write-external-storage] - #(dispatch [:navigate-to :profile-photo-capture])]))}]) + (fn [] + (camera/request-access + #(if % (dispatch [:navigate-to :profile-photo-capture]) + (utils/show-popup (label :t/error) + (label :t/camera-access-error)))))]))}]) (defn edit-profile-bage [contact] [view st/edit-profile-bage diff --git a/src/status_im/qr_scanner/handlers.cljs b/src/status_im/qr_scanner/handlers.cljs index d19a81d6db..779d3a6791 100644 --- a/src/status_im/qr_scanner/handlers.cljs +++ b/src/status_im/qr_scanner/handlers.cljs @@ -1,8 +1,10 @@ (ns status-im.qr-scanner.handlers (:require [re-frame.core :refer [after dispatch debug enrich]] - [status-im.utils.handlers :refer [register-handler]] + [status-im.components.camera :as camera] [status-im.navigation.handlers :as nav] - [status-im.utils.handlers :as u])) + [status-im.utils.handlers :as u :refer [register-handler]] + [status-im.utils.utils :as utils] + [status-im.i18n :as i18n])) (defmethod nav/preload-data! :qr-scanner [db [_ _ identifier]] @@ -15,7 +17,11 @@ [_ [_ identifier]] (dispatch [:request-permissions [:camera] - #(dispatch [:navigate-to :qr-scanner identifier])])) + (fn [] + (camera/request-access + #(if % (dispatch [:navigate-to :qr-scanner identifier]) + (utils/show-popup (i18n/label :t/error) + (i18n/label :t/camera-access-error)))))])) (register-handler :scan-qr-code (after navigate-to-scanner) diff --git a/src/status_im/translations/en.cljs b/src/status_im/translations/en.cljs index 72181e5a1a..4a04a7accb 100644 --- a/src/status_im/translations/en.cljs +++ b/src/status_im/translations/en.cljs @@ -15,6 +15,8 @@ :type-a-command "Start typing a command..." :error "Error" + :camera-access-error "To grant the required camera permission, please, go to your system settings and make sure that Status > Camera is selected." + ;drawer :invite-friends "Invite friends" :faq "FAQ"