Fixes #1220 Do not let catch escape

This commit is contained in:
Julien Eluard 2017-05-19 00:19:46 +02:00 committed by Roman Volosovskyi
parent 01fabc243d
commit 034ff3e413
5 changed files with 22 additions and 14 deletions

View File

@ -17,9 +17,9 @@
(defn request-access [callback]
(if platform/android?
(callback true)
(let [result (.checkVideoAuthorizationStatus camera-default)
result (.then result #(callback %))
result (.catch result #(callback false))])))
(-> (.checkVideoAuthorizationStatus camera-default)
(.then #(callback %))
(.catch #(callback false)))))
(defn camera [props]
(r/create-element camera-default (clj->js (merge {:inverted true} props))))

View File

@ -19,10 +19,12 @@
(defn request-permissions [permissions then else]
(if platform/android?
(let [permissions (mapv #(get permissions-map %) permissions)
result (.requestMultiple permissions-class (clj->js permissions))
result (.then result #(if (all-granted? (js->clj %))
(then)
(when else (else))))
result (.catch result #(else))])
(letfn [(else-fn [] (when else (else)))]
(let [permissions (mapv #(get permissions-map %) permissions)]
(-> (.requestMultiple permissions-class (clj->js permissions))
(.then #(if (all-granted? (js->clj %))
(then)
(else-fn)))
(.catch else-fn))))
(then)))

View File

@ -120,11 +120,17 @@
(def image-picker-class (js/require "react-native-image-crop-picker"))
(defn show-access-error [o]
(when (= "ERROR_PICKER_UNAUTHORIZED_KEY" (aget o "code")) ; Do not show error when user cancel selection
(u/show-popup (i18n/label :t/error)
(i18n/label :t/photos-access-error))))
(defn show-image-picker [images-fn]
(let [image-picker (.-default image-picker-class)]
(-> image-picker
(.openPicker (clj->js {:multiple false}))
(.then images-fn))))
(.then images-fn)
(.catch show-access-error))))
(def swiper (adapt-class (js/require "react-native-swiper")))

View File

@ -16,6 +16,7 @@
: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."
:photos-access-error "To grant the required photos permission, please, go to your system settings and make sure that Status > Photos is selected."
;drawer
:invite-friends "Invite friends"

View File

@ -3,10 +3,9 @@
(def fs (js/require "react-native-fs"))
(defn move-file [src dst handler]
(let [result (.moveFile fs src dst)
result (.then result #(handler nil %))
result (.catch result #(handler % nil))]
result))
(-> (.moveFile fs src dst)
(.then #(handler nil %))
(.catch #(handler % nil))))
(defn read-file [path encoding on-read on-error]
(-> (.readFile fs path encoding)