Skip to content

Instantly share code, notes, and snippets.

@antonzhyliuk
Created January 10, 2018 18:56
Show Gist options
  • Save antonzhyliuk/7ec3d61c6a6177055bebfa820e2bd8b2 to your computer and use it in GitHub Desktop.
Save antonzhyliuk/7ec3d61c6a6177055bebfa820e2bd8b2 to your computer and use it in GitHub Desktop.
react-native-camera with re-natal
(ns forest-community.components.camera
(:require [reagent.core :as r]))
(def ReactNative (js/require "react-native"))
(def text (r/adapt-react-class (.-Text ReactNative)))
(def view (r/adapt-react-class (.-View ReactNative)))
(def react-native-camera (js/require "react-native-camera"))
(def camera (-> react-native-camera
.-default
r/adapt-react-class))
(def styles {:container {:flex 1
:flexDirection "row"}
:preview {:flex 1
:justifyContent "flex-end"
:alignItems "center"}
:capture {:flex 0
:backgroundColor "#fff"
:borderRadius 5
:color "#000"
:padding 10
:margin 40}})
(def camera-dom-element (atom nil))
(defn take-capture []
(-> @camera-dom-element
(.capture (clj->js {:metadata {}}))
(.then #(println %))))
(defn camera-panel []
(let [aspect (-> react-native-camera
.-constants
.-Aspect
.-fill)]
[view {:style (:container styles)}
[camera {:aspect aspect
:style (:preview styles)
:ref #(reset! camera-dom-element %)}
[text {:style (:capture styles)
:on-press take-capture}
"[CAPTURE]"]]]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment