Skip to content

Instantly share code, notes, and snippets.

@roman01la
Last active September 24, 2017 19:22
Show Gist options
  • Save roman01la/5029fab68412d251709a to your computer and use it in GitHub Desktop.
Save roman01la/5029fab68412d251709a to your computer and use it in GitHub Desktop.
Reagent + react-motion
;; Reagent component
(defn new-task-input-component [props]
(let [new-task (subscribe [:get-new-task])]
[view
{:style (assoc (:slide-up styles) :transform [{:translateY (- (:y props))}])}
[input {:style (:input styles)
:default-value @new-task
:auto-focus true
:on-change-text #(dispatch [:set-new-task %])
:on-submit-editing #(do
(dispatch [:create-task])
(dispatch [:hide-task-input])
(dispatch [:clear-new-task]))}]
[text
{:style
{:font-size 20
:text-align "center"
:margin-top 20}}
"Type in your task description"]]))
;; (Reagent -> React) component
(def react-new-task-input-component
(r/reactify-component new-task-input-component))
;; (React Motion -> Reagent Motion) component
(def motion (r/adapt-react-class (.-Motion js/ReactMotion)))
;; (Reagent -> React) + (React Motion -> Reagent Motion) component
(defn slide-up-input [visible]
[motion
{:style {:y (spring (if visible 105 0) (if visible (.. presets -wobbly)))}}
#(r/create-element react-new-task-input-component %)])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment