-
Notifications
You must be signed in to change notification settings - Fork 987
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
125 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
(ns status-im.extensions.camera | ||
(:require [re-frame.core :as re-frame] | ||
[reagent.core :as reagent] | ||
[status-im.utils.fx :as fx] | ||
[status-im.qr-scanner.core :as qr-scanner] | ||
[status-im.ui.screens.navigation :as navigation] | ||
[status-im.utils.handlers :as handlers])) | ||
|
||
;; Photo taker | ||
|
||
(handlers/register-handler-fx | ||
:extensions/picture-taken | ||
(fn [cofx [_ _ base64 {{:keys [on-success]} :data}]] | ||
(fx/merge cofx | ||
{:dispatch (on-success {:result base64})} | ||
(navigation/navigate-back)))) | ||
|
||
(handlers/register-handler-fx | ||
:extensions/camera-picture | ||
(fn [{db :db} [_ _ {:keys [on-success on-failure]}]] | ||
(re-frame/dispatch [:request-permissions {:permissions [:camera :write-external-storage] | ||
:on-allowed #(re-frame/dispatch [:navigate-to :take-picture {:test-param "test value"}]) | ||
:on-denied #(print "denied!")}]))) | ||
|
||
;; QR code scanner | ||
|
||
(handlers/register-handler-fx | ||
:extensions/qr-code-scanned | ||
(fn [cofx [_ _ qr-code {{:keys [on-success]} :data}]] | ||
(fx/merge cofx | ||
{:dispatch (on-success {:result qr-code})} | ||
(navigation/navigate-back)))) | ||
|
||
(handlers/register-handler-fx | ||
:extensions/qr-code-cancel | ||
(fn [_ [_ _ {{:keys [on-failure]} :data}]] | ||
(when on-failure | ||
(re-frame/dispatch (on-failure {:result "user cancelled"}))))) | ||
|
||
(handlers/register-handler-fx | ||
:extensions/qr-code-denied | ||
(fn [_ [_ _ {{:keys [on-failure]} :data}]] | ||
(when on-failure | ||
(re-frame/dispatch (on-failure {:result "user denied access to camera"}))))) | ||
|
||
(handlers/register-handler-fx | ||
:extensions/camera-qr-code | ||
(fn [{:keys [db] :as cofx} [_ _ {:keys [on-success on-failure]}]] | ||
(qr-scanner/scan-qr-code cofx {:modal? false | ||
:deny-handler :extensions/qr-code-denied} | ||
{:handler :extensions/qr-code-scanned | ||
:cancel-handler :extensions/qr-code-cancel | ||
:data {:on-success on-success | ||
:on-failure on-failure}}))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
(ns status-im.extensions.views | ||
(:require-macros [status-im.utils.views :refer [defview letsubs]]) | ||
(:require [re-frame.core :as re-frame] | ||
[reagent.core :as reagent] | ||
[status-im.utils.handlers :as handlers] | ||
[status-im.ui.screens.navigation :as navigation] | ||
[status-im.ui.components.camera :as camera] | ||
[status-im.ui.components.react :as react] | ||
[status-im.ui.components.status-bar.view :as status-bar] | ||
[status-im.ui.components.toolbar.view :as toolbar] | ||
[status-im.i18n :as i18n] | ||
[taoensso.timbre :as log] | ||
[status-im.ui.screens.profile.photo-capture.styles :as styles] | ||
[status-im.utils.image-processing :as image-processing] | ||
[status-im.ui.components.icons.vector-icons :as icons])) | ||
|
||
(defn image-captured [data param] | ||
(let [path (.-path data) | ||
_ (log/debug "Captured image: " path) | ||
on-success (fn [base64] | ||
(print "Captured success: " base64 "param: " param) | ||
(re-frame/dispatch [:extensions/picture-taken base64]) | ||
(re-frame/dispatch [:navigate-back])) | ||
on-error (fn [type error] | ||
(log/debug type error))] | ||
(image-processing/img->base64 path on-success on-error))) | ||
|
||
(defview take-picture [] | ||
(letsubs [{param :test-param} [:get-screen-params] | ||
camera-ref (reagent/atom false)] | ||
[react/view styles/container | ||
[status-bar/status-bar] | ||
[toolbar/toolbar {} | ||
toolbar/default-nav-back | ||
[toolbar/content-title (i18n/label :t/image-source-title)]] | ||
[camera/camera {:style {:flex 1} | ||
:aspect (:fill camera/aspects) | ||
:captureQuality "480p" | ||
:captureTarget (:disk camera/capture-targets) | ||
:type "front" | ||
:ref #(reset! camera-ref %)}] | ||
[react/view styles/button-container | ||
[react/view styles/button | ||
[react/touchable-highlight {:on-press (fn [] | ||
(let [camera @camera-ref] | ||
(-> (.capture camera) | ||
(.then image-captured param) | ||
(.catch #(print "ERROR! " %)))))} | ||
[react/view | ||
[icons/icon :icons/camera {:color :white}]]]]]])) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters