This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-04-15
Channels
- # announcements (3)
- # architecture (1)
- # babashka (52)
- # beginners (228)
- # calva (1)
- # chlorine-clover (31)
- # cider (9)
- # clj-kondo (16)
- # cljs-dev (25)
- # cljsrn (21)
- # clojure (116)
- # clojure-argentina (8)
- # clojure-europe (18)
- # clojure-france (17)
- # clojure-germany (1)
- # clojure-nl (5)
- # clojure-spec (49)
- # clojure-uk (63)
- # clojurescript (59)
- # community-development (14)
- # conjure (89)
- # core-matrix (1)
- # cursive (18)
- # data-science (1)
- # datomic (27)
- # exercism (4)
- # figwheel-main (5)
- # fulcro (38)
- # ghostwheel (8)
- # graalvm (5)
- # hoplon (2)
- # jobs-discuss (17)
- # juxt (1)
- # lambdaisland (5)
- # luminus (1)
- # lumo (9)
- # malli (7)
- # off-topic (32)
- # planck (24)
- # re-frame (14)
- # reagent (14)
- # reitit (14)
- # rum (23)
- # shadow-cljs (80)
- # spacemacs (2)
- # sql (6)
- # unrepl (1)
- # xtdb (2)
Anyone know a best practices guide on doing animations with react native, reagent and re-frame? I have gotten a simple animation going with reacts Animated API. But everytime I fire off a re-frame event, the animation runs again. Also the animation starts without me having to click the button to start it. So basically all buttons that have reframes (dispatch) function makes the animation restart, and the animation starts automatically on app load. This is definitely not the desired function. Any ideas?
I typically use a form-3 component: https://cljdoc.org/d/reagent/reagent/0.10.0/doc/tutorials/creating-reagent-components#form-3-a-class-with-life-cycle-methods
And :component-did-mount
is typically the place to fire off animations that should run once when the component is created.
A common mistake is to put it in the :render
method (which, if your reagent component is just a function, you're already doing without realizing it.) . Then, you animation will run on every state change.
Ok. So I have to create a seperate component for animations. But how do I start an animation on a button click that is perhaps part of a different component?
I would put the Animated.Value object in your DB, when the animated component is mounted. Then, in your button component, subscribe to it and call (when-let [animated-value @animated-value-atm] (.start (.timing animated-value 1 500)))
or something like that
I see. So when the component is mounted, I create a Animated.Value and dispatch that to the DB. Then I have a button that has that when-let function and triggers the animation on-press. Ok that makes kinda sense. May I share with you my setup so that I can get your opinion on it? I feel like I maybe have setup my app a bit wrong.
For sure!
Inside (home/view) I have all my component code. I will link that as well.
Here I am just trying a bunch of stuff with components and seeing what works. This is also where I tried to define the animation. This doesn't look good, just a playground for me to learn.
So basically I have a root component setup like this. When I create a different form 3 component and put it inside this root component, will things still be ok? Have I setup the app correct or should I change some things? I am using shadow-cljs with my project.
Oh, I got you. On line 147 of home.cljs, it should be #(start-anim fade-anim)
. You're calling start-anim
each time the component is rendered rather than on a press event.
Ahha! My god ><
Hahah!
It works as expected now! 😄
Wow! Thank you so much!
But my core.cljs setup is ok? I have basically just gone for a template I found and I added some of the things I learned from reagent and re-frame web app development.
I'll take a look at it a bit later - I have some suggestions for how to clean it up if you're interested 😄
Oh yes please!
Be as brutal as you can! I am doing this to learn!
Thank you in advance! ^^