Do not navigate-back when selecting from gallery

Signed-off-by: Julien Eluard <julien.eluard@gmail.com>
This commit is contained in:
Julien Eluard 2019-02-13 11:52:51 +01:00
parent c0d659d008
commit 19fc26c1c2
No known key found for this signature in database
GPG Key ID: 6FD7DB5437FCBEF6
5 changed files with 16 additions and 25 deletions

View File

@ -32,10 +32,11 @@
(handlers/register-handler-fx (handlers/register-handler-fx
:extensions/camera-picture-taken :extensions/camera-picture-taken
(fn [cofx [_ base64 {{:keys [on-success]} :data}]] (fn [cofx [_ data {{:keys [on-success]} :data back? :back?}]]
(fx/merge cofx (fx/merge cofx
{:dispatch (on-success {:result base64})} {:dispatch (on-success {:result data})}
(navigation/navigate-back)))) (when back?
(navigation/navigate-back)))))
(handlers/register-handler-fx (handlers/register-handler-fx
:extensions/camera-picture :extensions/camera-picture

View File

@ -12,16 +12,12 @@
[status-im.ui.screens.profile.photo-capture.styles :as styles] [status-im.ui.screens.profile.photo-capture.styles :as styles]
[status-im.utils.image-processing :as image-processing])) [status-im.utils.image-processing :as image-processing]))
;; ensure photo taken or picked are not too big (def default-max-size 1024)
(def max-width 1024)
(def max-height 1024)
(defn- process-image-and-finish [path context] (defn- process-image-and-finish [path context]
(let [on-success (fn [base64] (let [on-success #(re-frame/dispatch [:extensions/camera-picture-taken % context])
(re-frame/dispatch [:extensions/camera-picture-taken base64 context])) on-error #(re-frame/dispatch [:extensions/camera-error %2 context])]
on-error (fn [type error] (image-processing/img->base64 path on-success on-error default-max-size default-max-size)))
(re-frame/dispatch [:extensions/camera-error error context]))]
(image-processing/img->base64 path on-success on-error max-width max-height)))
(defview take-picture [] (defview take-picture []
(letsubs [context [:get-screen-params] (letsubs [context [:get-screen-params]
@ -64,6 +60,6 @@
{:label (i18n/label :t/image-source-make-photo) {:label (i18n/label :t/image-source-make-photo)
:action (fn [] :action (fn []
(re-frame/dispatch [:request-permissions {:permissions [:camera :write-external-storage] (re-frame/dispatch [:request-permissions {:permissions [:camera :write-external-storage]
:on-allowed #(re-frame/dispatch [:navigate-to :take-picture context]) :on-allowed #(re-frame/dispatch [:navigate-to :take-picture (merge context {:back? true})])
:on-denied #(re-frame/dispatch [:extensions/camera-denied context])}]))}] :on-denied #(re-frame/dispatch [:extensions/camera-denied context])}]))}]
:on-cancel #(re-frame/dispatch [:extensions/camera-cancel context])}) :on-cancel #(re-frame/dispatch [:extensions/camera-cancel context])})

View File

@ -63,7 +63,7 @@
(defn- http-post [{:keys [url data response-validator success-event-creator failure-event-creator timeout-ms opts]}] (defn- http-post [{:keys [url data response-validator success-event-creator failure-event-creator timeout-ms opts]}]
(let [on-success #(re-frame/dispatch (success-event-creator %)) (let [on-success #(re-frame/dispatch (success-event-creator %))
on-error #(re-frame/dispatch (failure-event-creator %)) on-error (when failure-event-creator #(re-frame/dispatch (failure-event-creator %)))
all-opts (assoc opts all-opts (assoc opts
:valid-response? response-validator :valid-response? response-validator
:timeout-ms timeout-ms)] :timeout-ms timeout-ms)]
@ -75,7 +75,7 @@
(defn- http-raw-post [{:keys [url body response-validator success-event-creator failure-event-creator timeout-ms opts]}] (defn- http-raw-post [{:keys [url body response-validator success-event-creator failure-event-creator timeout-ms opts]}]
(let [on-success #(re-frame/dispatch (success-event-creator %)) (let [on-success #(re-frame/dispatch (success-event-creator %))
on-error #(re-frame/dispatch (failure-event-creator %)) on-error (when failure-event-creator #(re-frame/dispatch (failure-event-creator %)))
all-opts (assoc opts all-opts (assoc opts
:valid-response? response-validator :valid-response? response-validator
:timeout-ms timeout-ms)] :timeout-ms timeout-ms)]

View File

@ -67,7 +67,7 @@
[status-bar/status-bar {:type :wallet}] [status-bar/status-bar {:type :wallet}]
[toolbar/toolbar {:style wallet.styles/toolbar} [toolbar/toolbar {:style wallet.styles/toolbar}
[toolbar/nav-button (actions/back-white #(do (when on-close [toolbar/nav-button (actions/back-white #(do (when on-close
(on-close (create-payload address))) (re-frame/dispatch (on-close (create-payload address))))
(re-frame/dispatch [:update-wallet]) (re-frame/dispatch [:update-wallet])
(re-frame/dispatch [:navigate-back])))] (re-frame/dispatch [:navigate-back])))]
[toolbar/content-title {:color colors/white} [toolbar/content-title {:color colors/white}
@ -78,7 +78,7 @@
{:label label {:label label
:action #(do :action #(do
(when on-open (when on-open
(on-open address)) (re-frame/dispatch (on-open address)))
(re-frame/dispatch [:navigate-to :wallet-settings-hook m]))}) (re-frame/dispatch [:navigate-to :wallet-settings-hook m]))})
(defview toolbar-view [] (defview toolbar-view []

View File

@ -1,8 +1,6 @@
(ns status-im.utils.image-processing (ns status-im.utils.image-processing
(:require [goog.object :as object] (:require [goog.object :as object]
[status-im.utils.fs :refer [read-file]] [status-im.utils.fs :as fs]
[taoensso.timbre :as log]
[clojure.string :as str]
[status-im.react-native.js-dependencies :as rn-dependencies])) [status-im.react-native.js-dependencies :as rn-dependencies]))
(defn- resize [path max-width max-height on-resize on-error] (defn- resize [path max-width max-height on-resize on-error]
@ -14,16 +12,12 @@
(.catch on-error)))) (.catch on-error))))
(defn- image-base64-encode [path on-success on-error] (defn- image-base64-encode [path on-success on-error]
(let [on-error (fn [error] (fs/read-file path "base64" on-success #(on-error :base64 %)))
(on-error :base64 error))]
(read-file path "base64" on-success on-error)))
(defn img->base64 [path on-success on-error max-width max-height] (defn img->base64 [path on-success on-error max-width max-height]
(let [on-resized (fn [image] (let [on-resized (fn [image]
(let [path (object/get image "path")] (let [path (object/get image "path")]
(log/debug "Resized: " path)
(image-base64-encode path on-success on-error))) (image-base64-encode path on-success on-error)))
on-error (fn [error] on-error (fn [error]
(log/debug "Resized error: " error)
(on-error :resize error))] (on-error :resize error))]
(resize path max-width max-height on-resized on-error))) (resize path max-width max-height on-resized on-error)))