App crashes if access to camera was denied and user tries to scan QR or capture image (#1134)
This commit is contained in:
parent
6e5c8d91dd
commit
a8566759b5
|
@ -1,16 +1,25 @@
|
||||||
(ns status-im.components.camera
|
(ns status-im.components.camera
|
||||||
(:require [reagent.core :as r]
|
(: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-class (js/require "react-native-camera"))
|
||||||
|
(def camera-default (.-default camera-class))
|
||||||
|
|
||||||
(defn constants [t]
|
(defn constants [t]
|
||||||
(-> (aget camera-class "default" "constants" t)
|
(-> (aget camera-default "constants" t)
|
||||||
(js->clj)
|
(js->clj)
|
||||||
(keywordize-keys)))
|
(keywordize-keys)))
|
||||||
|
|
||||||
(def aspects (constants "Aspect"))
|
(def aspects (constants "Aspect"))
|
||||||
(def capture-targets (constants "CaptureTarget"))
|
(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]
|
(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))))
|
||||||
|
|
|
@ -1,15 +1,19 @@
|
||||||
(ns status-im.profile.edit.screen
|
(ns status-im.profile.edit.screen
|
||||||
(:require-macros [status-im.utils.views :refer [defview]])
|
(: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.text-input-with-label.view :refer [text-input-with-label]]
|
||||||
[status-im.components.styles :refer [color-blue color-gray5]]
|
[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.status-bar :refer [status-bar]]
|
||||||
[status-im.components.toolbar-new.view :refer [toolbar]]
|
[status-im.components.toolbar-new.view :refer [toolbar]]
|
||||||
[status-im.components.toolbar-new.actions :as act]
|
[status-im.components.toolbar-new.actions :as act]
|
||||||
[status-im.i18n :refer [label]]
|
[status-im.i18n :refer [label]]
|
||||||
[status-im.profile.screen :refer [colorize-status-hashtags]]
|
[status-im.profile.screen :refer [colorize-status-hashtags]]
|
||||||
[status-im.components.sticky-button :refer [sticky-button]]
|
[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.chat-icon.screen :refer [my-profile-icon]]
|
||||||
[status-im.components.context-menu :refer [context-menu]]
|
[status-im.components.context-menu :refer [context-menu]]
|
||||||
[status-im.profile.validations :as v]
|
[status-im.profile.validations :as v]
|
||||||
|
@ -19,11 +23,8 @@
|
||||||
text
|
text
|
||||||
touchable-highlight
|
touchable-highlight
|
||||||
text-input]]
|
text-input]]
|
||||||
[status-im.utils.utils :refer [clean-text]]
|
[status-im.utils.utils :as utils :refer [clean-text]]
|
||||||
[cljs.spec :as s]
|
[status-im.utils.platform :refer [ios?]]))
|
||||||
[clojure.string :as str]
|
|
||||||
[status-im.utils.platform :refer [ios?]]
|
|
||||||
[reagent.core :as r]))
|
|
||||||
|
|
||||||
(defn edit-my-profile-toolbartoolbar []
|
(defn edit-my-profile-toolbartoolbar []
|
||||||
[toolbar {:title (label :t/edit-profile)
|
[toolbar {:title (label :t/edit-profile)
|
||||||
|
@ -43,7 +44,11 @@
|
||||||
:value (fn []
|
:value (fn []
|
||||||
(dispatch [:request-permissions
|
(dispatch [:request-permissions
|
||||||
[:camera :write-external-storage]
|
[: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]
|
(defn edit-profile-bage [contact]
|
||||||
[view st/edit-profile-bage
|
[view st/edit-profile-bage
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
(ns status-im.qr-scanner.handlers
|
(ns status-im.qr-scanner.handlers
|
||||||
(:require [re-frame.core :refer [after dispatch debug enrich]]
|
(: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.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
|
(defmethod nav/preload-data! :qr-scanner
|
||||||
[db [_ _ identifier]]
|
[db [_ _ identifier]]
|
||||||
|
@ -15,7 +17,11 @@
|
||||||
[_ [_ identifier]]
|
[_ [_ identifier]]
|
||||||
(dispatch [:request-permissions
|
(dispatch [:request-permissions
|
||||||
[:camera]
|
[: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
|
(register-handler :scan-qr-code
|
||||||
(after navigate-to-scanner)
|
(after navigate-to-scanner)
|
||||||
|
|
|
@ -15,6 +15,8 @@
|
||||||
:type-a-command "Start typing a command..."
|
:type-a-command "Start typing a command..."
|
||||||
:error "Error"
|
: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
|
;drawer
|
||||||
:invite-friends "Invite friends"
|
:invite-friends "Invite friends"
|
||||||
:faq "FAQ"
|
:faq "FAQ"
|
||||||
|
|
Loading…
Reference in New Issue