Last active
March 31, 2021 10:37
-
-
Save martinklepsch/0cc942365e472671eee2ad5a363c34e7 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
(ns acme.react-spring | |
(:require [rum.core :as rum] | |
["react-spring" :as rs])) | |
(rum/defc AnimatedDiv < rum/static | |
[style child] | |
(js/React.createElement rs/animated.div (clj->js style) child)) | |
(defn use-spring | |
[config-map] | |
(rs/useSpring (clj->js config-map))) | |
(rum/defc AnimatedParticle | |
[{:keys [from to] :as _positions}] | |
(let [spring (use-spring {:config {:mass 4, :tension 180, :friction 18} | |
:delay 150 | |
:from {:xy from, :opacity 0} | |
:to {:xy to, :opacity 1}) | |
translate-xyr (fn [x y] (str "translate(" x "px," y "px)"))] | |
(AnimatedDiv | |
{:style {:position "absolute" | |
:transform (.. spring -xyrs (interpolate translate-xyr)) | |
:opacity (.. spring -opacity)}} | |
(Particle)))) | |
(AnimatedParticle {:from [0 0] | |
:to [123 456]}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment