cljsrn

https://github.com/drapanjanas/re-natal | https://github.com/drapanjanas/re-natal/wiki/FAQ | https://github.com/condense/mercury-app/wiki | https://github.com/seantempesta/expo-cljs-template/ https://www.npmjs.com/package/create-expo-cljs-app
Shako Farhad 2020-04-15T20:47:25.099800Z

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?

jimberlage 2020-04-15T20:55:10.101400Z

And :component-did-mount is typically the place to fire off animations that should run once when the component is created.

jimberlage 2020-04-15T20:56:20.102500Z

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.

Shako Farhad 2020-04-15T21:00:55.106200Z

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?

jimberlage 2020-04-15T21:03:08.108500Z

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

Shako Farhad 2020-04-15T21:06:13.110500Z

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.

jimberlage 2020-04-15T21:06:23.110700Z

For sure!

Shako Farhad 2020-04-15T21:06:54.110800Z

Inside (home/view) I have all my component code. I will link that as well.

Shako Farhad 2020-04-15T21:07:49.111100Z

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.

Shako Farhad 2020-04-15T21:10:09.113100Z

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.

jimberlage 2020-04-15T21:12:28.114600Z

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.

Shako Farhad 2020-04-15T21:12:43.114800Z

Ahha! My god ><

Shako Farhad 2020-04-15T21:13:14.115Z

Hahah!

Shako Farhad 2020-04-15T21:13:21.115300Z

It works as expected now! 😄

Shako Farhad 2020-04-15T21:13:30.115500Z

Wow! Thank you so much!

Shako Farhad 2020-04-15T21:15:33.116900Z

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.

jimberlage 2020-04-15T21:49:28.117700Z

I'll take a look at it a bit later - I have some suggestions for how to clean it up if you're interested 😄

Shako Farhad 2020-04-15T21:51:43.117900Z

Oh yes please!

Shako Farhad 2020-04-15T21:51:55.118200Z

Be as brutal as you can! I am doing this to learn!

Shako Farhad 2020-04-15T21:52:47.118400Z

Thank you in advance! ^^