chantastic.fm

56: Paul Henschel on React Spring

Episode 56 · July 25, 2019 · 00:59:41

Hosted by chantastic · With Paul Henschel

Sponsored by GitPrime

Download MP3 · Jump to transcript

This week, on React Podcast, We sit with Paul Henschel and talk animation.

Paul is the creator of React-spring a library for animating UI based on spring physics.

We talk about the library's origin, its future, and how to create lasting beauty on the web.

Featuring

Links

Sponsors

GitPrime

GitPrime turns historical git data into easy-to-understand insights and reports that help engineering teams succeed. gitprime.com

Transcript

[00:00:00] Michael Chan: This is React Podcast. I'm Chantastic. This week on React Podcast, we sit with Paul Henschel and talk animation. Paul is the creator of React Spring, a library for animating UI based on spring physics. We talk about the library's origin, its future, and how to create lasting beauty on the web. Our sponsor is GitPrime. You know how to debug code, but how are you at debugging your development process? Drop in a console log to see who's commenting on PRs, a timeout to see how long it takes to merge a feature after completion, maybe run a profile on who's giving the most actionable feedback or which parts of the codebase are chronically resistant to change. You probably don't do this because you don't have the tools. Well, now you do. GitPrime is a debugger for your development process where they know how to locate and eradicate bugs. They've done this with Atlassian, PayPal, Adobe, VMware, Sentry, and so many more. To learn about 20 ways they help teams debug their processes, check out their free book, 20 Patterns to Watch for in Your Engineering Team. Get it at gitprime.com/20patterns. That's the number 20 patterns. And start debugging your development process today. GitPrime, engineers build Hey, Paul, welcome to the show.

[00:01:37] Paul Henschel: Hey, Michael. Thanks. And uh thanks also for having me.

[00:01:41] Michael Chan: It is super good to have you. I'm glad to have you on. Uh I am always excited to talk with people about uh animation libraries and techniques and everything because it is something that is so outside of my wheelset, outside of my comfort zone. Uh so, I'm so excited to have you on the show to talk about React Spring. Uh but first, I just have to ask, what is- what does your Twitter name mean? It feels very intentional. And so I have to know, uh, what's the- what does it mean?

[00:02:14] Paul Henschel: Yeah, no, it it doesn't mean anything. I was just like uh hacking on the on the keyboard. I have I have like this weird thing that um like on every social media platform I go, I have like a different name.

[00:02:27] Michael Chan: I noticed that, yeah.

[00:02:28] Paul Henschel: Yeah, yeah. And uh it's I don't know actually why. It's at some at some like uh sort of uh perspective, it's really stupid. So I I like bleed followers and I I start always from scratch. But I don't know, that's just the way it is.

[00:02:45] Michael Chan: I like this idea because it does get kind of harder and harder to find uh a Twitter name or you know or like a social media name that you can get everywhere. So I like this idea of just kind of going with a random one and being like, eh. It's a new thing.

[00:03:00] Paul Henschel: Yeah, I guess I did it for, uh, I don't, how do you say it, uh, for anonymity. My my English is kind of rough.

[00:03:08] Michael Chan: Anonymity, yeah.

[00:03:10] Paul Henschel: So, yeah, I, ah, this is terrible. Sometimes I want to tell people what's my Twitter handle and I don't even know myself, so.

[00:03:18] Michael Chan: I had to I had to check quite a few times as I was linking to you in in the tweets where we were asking for help. It's like, did I get the the right zeros and As and Xs?

[00:03:29] Paul Henschel: Yeah, so-

[00:03:30] Michael Chan: So you have, um, you know, if you're going for anonymity, uh, you're you're not succeeding there because you have an amazingly popular open source project in React Spring. Uh, and I want to talk with you uh about that. Uh, so first, what is your history in animation? Like what what brought you to solving the animation problem in React?

[00:03:54] Paul Henschel: Uh, actually, it's it didn't start in React. It started uh with Android. Um. I made something like a custom firmware or something like this. I got- Oh, wow. My first smartphone was a Google Nexus. And at heart, I'm something like a tinkerer. I got this device and I thought, hey, I can I can make this different. I I want to to change everything. And I started to like hack away. It was at the time was open source. It was called AOSP, Android Open Source Project. I forked this and I founded something that later was called Paranoid Android. It got re- Really, really big, like hundreds of thousands of users later, but I started with nothing. And you could do some crazy stuff and everything was like moving around. And this was the first time I I got really in touch with animation. It's uh I I got to know how hard it actually is um to do it right. And yeah, that was the first exposure that I had. And React came a little bit later, actually. I went into React and I didn't animate anything because I only knew like CSS and for me it it didn't, I don't know, it wasn't good enough. I didn't like it.

[00:05:08] Michael Chan: Yeah.

[00:05:08] Paul Henschel: I I didn't like the the schism between like my code, my view, and something like classes. I didn't like it. But eventually I had to animate something and this is how it started for me. I had no idea actually. Uh I'm I'm not like the professional on the stuff. I was just like uh uh bumping into this basically.

[00:05:31] Michael Chan: So what were you doing in Android at the time? Were you you were you working on an Android application? Um and that's what got you started in Android?

[00:05:39] Paul Henschel: No, it was um basically really a fork of the Android system. Uh and uh at this time, it was called like A ROM uh or firmware. I don't know. You install it on your phone. And you can do basically everything. So- Wow. If you want, you can look it up afterwards. It's called Paranoid Android. But I don't do this anymore, but this is how I got into it. And for instance, I changed stuff like I removed the buttons and then you have some weird pie control that you can, I don't know, navigate with your thumb. And basically everything I did was like moving around. And for this, I needed motion or animation. And this is the first time I like created a little library for myself to to abstract it a little bit better. And uh yeah, this is uh how it started for me.

[00:06:32] Michael Chan: That's awesome. So what is it that caught your attention about React um when it came out?

[00:06:38] Paul Henschel: Uh to be honest, at first I hated it. Uh you know, people talk about this uh JSX shock or something.

[00:06:45] Michael Chan: Yeah.

[00:06:46] Paul Henschel: Uh it totally hit me. Um. I mean, I didn't even know how it works. I just saw uh like a component uh on the React website and I had no idea what is this. And I I just wasn't used to it. But eventually it got so big that I couldn't uh like avoid it anymore. And I was like uh shot down. I was like, it was crazy that I studied it like 1 or 2 hours and I could do it. I I knew I can I can go and run and uh make something. It was crazy. Because uh I come from like uh native uh background and in my career, I I needed, I don't know, months to to get WPF uh some Windows framework and I don't know, Angular also took me a long time to get. So there comes this little framework and uh with an API that's it's like really small. And the coolest thing was, I the first time maybe, Uh, it's kind of, I thought at least, it fits the way I I think. Like, uh, I have some something in my mind and I can just go and prototype it really quickly. So yeah, I loved React from the get-go.

[00:08:00] Michael Chan: What would you say was the thing that that made prototyping quick? What was the biggest difference in React from other libraries that you'd used that kind of stood out to you as as making things quicker that made it easier to to to dive into or to jump into and be immediately productive?

[00:08:20] Paul Henschel: Basically, it was what everyone was saying React did wrong. Uh they said, ah, React doesn't uh separate concerns. But uh they said, yeah, you have a view and everything is like uh mixed together.

[00:08:36] Michael Chan: Uh-huh.

[00:08:36] Paul Henschel: But it was the first time where I realized, hey, uh it should be mixed together.

[00:08:41] Michael Chan: Yeah.

[00:08:42] Paul Henschel: And that that even for me, even today, like uh animation, uh styles, everything that has to do with the view belongs to the view. It's the same layer. Uh even to this day, I'm like totally opposed to CSS and animation, like even a radical way. I don't even want to to to do uh much in it. Uh for me, it just makes sense. Everything is reflective. I have state and my view is reflective of state. I think this was a genius principle.

[00:09:15] Michael Chan: Yeah, I I I couldn't agree more. So let's talk about the history then of React and animation. So there's been a long history. I think that uh we've been kind of trying to figure out this animation piece for a really long time.

[00:09:31] Paul Henschel: Yeah, yeah.

[00:09:32] Michael Chan: Um, but there's like React CSS transition group, I think, was the first uh foray into animating certain components with enter and leave states, uh which I think turned into React Transition Group. And there was React Motion in there was a was a concept for a while and animated by Christopher Chedeau. And there's been like a lot of techniques. Um could you say from your perspective kind of what we learned from each of those big kind of milestones in React animation?

[00:10:02] Paul Henschel: Yeah, I think we we made lots of progress and it's it's so cool that um there's so many different things that evolved out of this ecosystem. Um personally, the first thing I saw was React Motion and uh this immediately like spoke to me because uh there's a little background uh in the Android days. I don't know if people still remember this. Facebook released some some like app, it was called Chat Heads. Do you know what this is?

[00:10:33] Michael Chan: Oh yeah, yes, yeah, yeah. And the the the heads kind of move around in a like a with a spring type of following each other.

[00:10:41] Paul Henschel: Right, and I did something similar. It was called Halo, uh but it could uh receive like notification from any app. It wasn't like just Messenger. But the point was uh that Chatter felt so, so natural. And I know I used up like weeks trying to tweak my easings and durations and all this stuff and never even got near uh like how natural the original felt. And I basically just gave up at the time. And I knew they they were doing something like with springs. I didn't know what this was. I thought it was crazy. But uh yeah, it's passing uh past a couple of years and there's React Motion. And the primary principle is springs. And this immediately immediately made sense to me. But at the time, I couldn't handle the the render props API. It was like very new at the time.

[00:11:34] Michael Chan: Yeah, yeah.

[00:11:34] Paul Henschel: And it felt so strange. I I felt like, oh, what is this? Come on. And I couldn't bring myself uh to to actually use it. I I later on, I use it and I love it, but uh I still put it back. I like it because it has springs. I said to myself, but oh no, I I won't use RenderProps. And then I go to Animated. And Animated, even to this day, it's it's my favorite uh like piece of engineering in the React ecosystem. I think this this guy, um uh Christopher uh Tudor, he he did some some things with it that are really revolutionary uh even today. Like the way uh he treats these these animated properties. But obviously it's also uh focused on springs, which I liked. And I started using this. And uh the way it works, uh you have these little handles and you can basically just reuse them in your in your view. They are like self-updating. And basically you don't render out the animation. Uh you render or animate outside of React, which made it really performant. But the problem with this is it's a little bit imperative, right? Um, meaning you have like lots of these um loose end animation handles. Uh you have one for opacity, one for color, uh and you need to orchestrate. Uh you need to stop this and cancel that and start something else. And they're all async. And in the end, it's easy uh to end up with some salad of concerns. It's nothing against this library. It's just the approach. It's a little bit more low level. This is exactly the way I used to handle animation in Android or prior. And this was uh the problem that actually made me look for React Motion. And my goodness, I thought this is genius because animation now, it's just reflective of state. I have some config and I say, okay, opacity, if props.visible is true, it's 1. If not, it's uh 0. And it just manages all by itself. I don't need to chase behind some handles and close this and destroy that. That was really, my goodness, it was genius. But the downside of course was that it renders out everything through React. So every time you have some interpolated property, like going from 0 to 1, you have 0.1, 0.2, and so on, thousands more. Each one represents a React render pass, which uh kind of um yeah makes it not so performant, at least if you deal with bigger components. Uh so yeah, this was already the the moment where I saw that, hey, these two, they're really cool. And they have like upsides and downsides. For instance, another upside of Animated was you can feed it everything. You give it a color, say RGB or red, and you want to turn it to blue, you can just do it. React Motion is just a value interpolator. It can just interpolate values. And I found it increasingly hard to like interpolate into colors and uh box shadow and other stuff. Um yeah, so these these two, I I knew I liked them, but they weren't enough. Uh this was the moment where I decided, hey, maybe- Maybe I should uh try something.

[00:15:12] Michael Chan: This is interesting. Right in the the beginning of your documentation, you you you really do pay tribute to both of these libraries, uh React Motion and Animated. And um so is it is it safe to say that that React Motion kind of has a very declarative API and there are, you know, side effects of that, which are, you know, the it's rendering those components every single time. Uh and then Animated is more imperative, where you're you're responsible for doing a lot more of the of the actual work. Is that about right?

[00:15:45] Paul Henschel: Yes, that's about right. I mean, these are like these these two approaches uh that you normally take to animation. And uh I don't even think one is better than the other. Uh like nowadays, I think both are suitable for different problems. Like I would say, if you ask me now, that the imperative way is perhaps better for things like uh gaming or storytelling. Like we all have seen these really cool things that, I don't know, how's her name, Sarah Drasner?

[00:16:16] Michael Chan: Yes.

[00:16:17] Paul Henschel: Yeah, yeah, yeah. She she made these these cool like SVG stories uh start to move and she she really tells stories with this. And the imperative way is very flexible for this. But at the same time, it's not the best approach for UI, uh because UI is reflective of state and the declarative way, um the animation becomes part of of your uh of the um declaration. You declare the animation itself. And it makes it very comfortable because you never chase anything, no loose ends, no handles. So yes, these are the the two approaches, and I went with the declarative approach uh initially because I wanted to mostly serve UI, not not like gaming or story storytelling.

[00:17:11] Michael Chan: Would you say that right now, as the library sits today, is it still primarily declarative, or are there ways to kind of get down into a more imperative level?

[00:17:21] Paul Henschel: Yeah, this is the question. Um, you know, To to make animation declarative, uh it's great, but it has many many downsides as well. And I noticed because people come to uh my GitHub issue tracker and they complain about this or they want that, and I just couldn't solve their problems uh for them anymore. I mean, sure, there were like edge cases, but you declare an animation, you say you go from 0 to 1, and it runs because you have declared it. But how do you actually like stop it, interrupt it? How do you orchestrate? How do you make sure that this animation comes to rest and then you start something else? These were the problems I just- I couldn't solve. Only like with with some weird hacks, like there's some immediate flag and things like this. But this was awkward and I knew it, but I had no idea how to solve it. And Then came, of course, hooks, and I think this changed everything because now we're in between the two. Hooks aren't imperative and they aren't declarative. Hooks are not just functions, they are functions with state or stateful. I don't know, how does how do they actually, they say something like effects, there was a word they they were throwing.

[00:18:45] Michael Chan: Oh, uh algebraic effects. Yeah. I I I don't know what it means, but I do know that the term exists.

[00:18:52] Paul Henschel: Yeah, yeah, yeah, it sounds impressive. I mean, but it makes sense. It's not just a function, it's it's something in between. And this is so cool because uh with hooks, uh you still have the declarative aspect, you still have the view, but you don't change the view anymore. You don't accommodate for animate animation. Your view is as it was, which is beautiful. But at the same time, um you still have the configs uh which you had in React Motion. You still can say opacity this, color that, and would just go. But you're still in between. You can like stop it, interrupt it. You can catch the animation and say, you run when this one comes to rest. So right now I think we are in between these two uh aspects. And in my opinion, it's it's uh at the moment, I think it's the best way.

[00:19:45] Michael Chan: That's really interesting. I I've had a lot of- conversations with people about the ergonomics of hooks and how hooks allow you to write code in a way that- for example, you mentioned render props and how when you first approach it, there's that that shock of, you know, what is this? Because it just looks so horrifying when when paired with JSX. Uh and I I hear a lot about the ergonomics of hooks and how that allows people to write render prop type code but without the actual render props. Um, but this is interesting that that this is enabling you to to create new functionality that was incredibly difficult before. Um, what are some of the specific features that you have found to be more easily enabled through hooks uh that were were not very obvious before?

[00:20:37] Paul Henschel: Um, I mean. The the obvious things uh is the same thing you you get in the internet when people ask for this, um like mixins and higher-order components and render props. They have some downsides. And uh usually people will say, OK, these downsides are fixed and you can now group responsibilities and so on and so forth. So obviously, this uh is is very good. But in the perspective of animation, It enables something that I didn't think uh was doable before, because we are already used to accommodate our views to to our animation primitives. We say, this is my view. Like uh you have a button, you click it, and pops up some, I don't know, uh dialogue. And if you click the X, it goes away. And you say, OK, now I want to make it uh move. So how do I do it? And we are kind of used, we have this this uh mental model that we need to wrap it and uh put some magic uh things in it and whatever. And with hooks, no, you've used the same as before. You just uh put some utility function in between and it turns your statics into movable values. Like you surely have something like an opacity. And if you press the button, opacity goes 1 because now it's visible. I mean, it's very simplified, but uh let's let's picture it like this. But now all you you need to do is put a hook in between and it turns the opacity into something that uh that can move, that can animate. And the view mostly doesn't change. You just slap uh the the property into the view and boom, you have it. And to me, this is actually beautiful. Because many people ask me, how do you learn to animate? And I think the thing I learned uh now is that the best way to animate is to not animate first. Uh your application does everything what you what you needed to do. If you have this down, then to to turn it into something that moves becomes easy or easier with hooks because your view is is the same. And basically you just turn around these these values that that have been static before. And this is the the approach that I love most about hooks. And the other one has to do with uh like uh interacting with other things going on, like other libraries and the environment, things that were really hard to do with mixins. Because now it's all linear. You can say this hook gives me this result, I use it in the next hook, and so on and so forth. So you can make some some linear chain of uh responsibility. And it's really cool, to me at least.

[00:23:31] Michael Chan: Yeah, yeah. It's it's it's amazing. I I love discovering new ways that hooks have empowered uh yeah UI authoring. Uh so now with hooks, you had mentioned the the problems of that declarative model with um you know with with render props. Um do hooks help solve any of the performance problems that that we had before? Or does that uh give you new methods of solving them?

[00:23:57] Paul Henschel: No. I mean, yes or no. Uh it depends. Uh because React Spring, it inherits um the the roots, the core of Animated. It started out as a fork of the library that Christopher Chido made. So uh we always render outside of React if we can. So React isn't even even involved. Uh we directly mutate the view. So um you have a component, you render it, you could you could slap a console.log in there. You will see it just renders once, even if it animates, it doesn't matter because React Spring does this for you outside. And this remains the same uh with with hooks, but The problem is uh if you have something like events, uh like if you drag something around, then this causes uh this causes state because um you need to push state into the component again. And then uh the spring renders and so on. So previously with render props, uh it could be fast, but the moment you go into some event-driven stuff, it turns slow again because you need to render out uh event data, like where's the mouse pointer right now. Uh and with hooks, uh yes, you can uh change or mutate the animation completely outside of React, even in events. So this is, I think it's it's more performant in a way.

[00:25:25] Michael Chan: Yeah. Now I'd like to talk about how this project, uh React Animated, relates to other projects, you've been doing a couple other things that are really fascinating with really um brilliant demos. Uh you have React.useGesture, which is a a new hook for for gestures, um and then also React Three Fiber. Uh can you tell me how those are related to React Spring?

[00:25:48] Paul Henschel: Uh Gesture started- I was actually uh trying to put gestures into React Spring, um but I realized that this isn't the path I want to go. Usually I like things to be very like um yeah atomic. Do one thing and do it well. And I I already see— I saw I I'm stretching the code right now. I create uh responsibilities that maybe aren't even cross-platform anymore. So if uh I I hamper the adoption even of the library if I would do this. So I thought, how can I solve this? And I started to play around, to abstract. And I figured, hey, actually, something like a gesture isn't isn't so hard. You can abstract it pretty easily. Even even complex stuff like dragging something around and uh calculating like velocity and direction, it's not so hard. But how do I actually make it so that these two libraries now start to to mesh, uh to to work with one another? And this changed a little way, a little bit how React Spring worked. And in a way, it turned it more like open. And uh this helped me later greatly uh by incorporating other things into it. So yeah, the the Spring is just a Spring. It's just it it's a value inter- interpolator. But now it can be like it can work together with practically everything. And this was React Gesture. Uh the project is now uh handled by David Bismuth. And uh yes, I I think it's pretty cool that also it's it's totally based on hooks and uh also demonstrates how neatly hooks can work together because you have these two completely asinine uh different things that just uh they can just mesh. They can just say, ah, uh I uh use uh something from this hook. Uh if you have seen the demos, The gesture hook, for instance, it just calls like into into the Spring. It says Spring set, and then then it works. And it works outside of React, which is super cool. And Three Fiber is really special to me. This is the project I'm working now. Like it takes a little bit of my focus now. Because This goes a little bit into the performance concerns because I'm still I still think that the DOM is terribly slow and I've stopped putting like my hopes into some vendor that will come along and they make everything fast. I don't think it will ever happen. Uh they're telling us that the DOM will be fast like for 20 years and like CSS, they say, ah, it's GPU driven. But still, the thing is going to choke. I can choke CSS by, I don't know, putting 20 div boxes on screen. I actually- there was a really funny tutorial from this Google guy. It was about uh parallax scrolling. And he goes uh like through different uh things you can do to make it fast. In the end, he just concludes, ah, use WebGL. But it is like this. I think to me now it makes it makes sense because you can actually like separate concerns, do everything that has to do with visuals and stuff like this. You can do it in in GL. It can be really, really fast. And you can still mix and match it with like layouting for which the DOM is great. Uh so actually to me it's like my my dream because now I have a layout engine that I can like abuse totally just for layout. And I can just mix it with something like visual and make something really, really cool that would be impossible to do uh with the DOM. I don't even care. Uh people say, ah yeah, the next animation API would change everything, the web uh API, blah, blah, blah. And it's slow. It's I don't think it's uh it's the solution. To me, at least.

[00:30:08] Michael Chan: So so is React Three Fiber uh a different renderer for React?

[00:30:13] Paul Henschel: Yes, it's a reconciler. Um it's it's used uh React Fiber, and um there's a project called React Reconciler. And with this, you can make your own target. It's actually uh very simple to create a basic uh render target. But then you can actually mix them. Which is cool. You have like a DOM, and then you can can say, OK, now I render into Three.js. And this is pretty wild. Uh, yeah.

[00:30:41] Michael Chan: Yeah. Yeah, yeah. Now, many of these examples are just gorgeous, absolutely stunning. Uh, do you have a design uh background, or are you just interested in art?

[00:30:53] Paul Henschel: Uh, no, I don't have a design background, but most of my family They're they're all artists. Like my dad is a painter, my sister's a designer, my mom was a painter. So as a as a kid, I would like also uh make sculptures and paint and stuff like this, but I have no background. I think my my parents, uh my dad, he didn't like that I go into computing so much, but then he see the things that I'm doing and uh he's now really happy about this. But yeah, I'm like uh the black sheep in the family in a way. But but I still like uh things to be visual, but I don't have any background whatsoever.

[00:31:35] Michael Chan: So for people who are are are looking to explore this, what are some really good examples of places that you would want to get from kind of like DOM layout related stuff and try something like React Three Fiber?

[00:31:47] Paul Henschel: Uh you mean if they want to to learn?

[00:31:49] Michael Chan: Yeah, if they wanted to learn. Learn? Or, you know, where would this be like a good fit for— uh like what kind of project might be a good fit for giving React Three Fiber a try?

[00:32:00] Paul Henschel: Yeah, okay. Um, I guess most of us— I mean, if you have Twitter, uh you must have seen these crazy websites that are going around. There's this awards committee, it's called AWWAwards, something like this. I don't even know how to pronounce this. Yeah,

[00:32:19] Michael Chan: yeah, yeah. I think it's like uh-

[00:32:21] Paul Henschel: Words. Yeah, yeah, it is.

[00:32:24] Michael Chan: We'll link it, yeah.

[00:32:26] Paul Henschel: Yeah. Each and every website on this is almost impossible to do with the DOM. And then you you look into how they do it and it's like canvas, canvas, canvas, canvas, canvas with a little bit of like layout uh on top of it. And then I try to track down the people that do these sites. One of the one of them was called Artiste Binois or something like this. And he's he's like made half of these pages. And uh yeah, they're not possible. They're not possible. Give up. You you cannot do it with the DOM. The the the effects that they that they do- there was one of uh some Japanese photographer. And this site was so crazy. That I almost thought like, hey, I I throw down everything I have. I I don't even care anymore. I I do, I plant fruits now. I give up, like this. Because it was so, so far away from what I thought I could do. And I I already thought that, hey, I've acquired some little knowledge, I can animate this and that. But this was so crazy that it was impossible. I was speechless. And then I start to uh like track them down and and I talk to them and try to squeeze them into like, how the hell did you do this? And uh obviously they're like very, maybe uh yeah, a little bit like uh shy. They don't want to give the information just like this, but they give me a little bit, a couple of hints. And then I go and try to to uh Yeah, I don't know. I take Three.js and try uh to to make uh something like this. And I notice, hey, this is cool, but it's at the same time it sucks because uh it's really hard and I miss React. I miss the way that uh I can use React and manage my view. This this is how it was uh how it was born. And I think it helps for everything that has to do with with visuals. Like you can now mix the concerns. You have layout and you can have something uh like something crazy.

[00:34:39] Michael Chan: So when you're working with Three uh React Three Fiber, um I'm not too familiar with Three.js in general. Do you do everything in code or is there a way to map it to um visual tools that allow you to build animations?

[00:34:56] Paul Henschel: Uh, no, you uh do most of the stuff in code in the editor. It's uh it's a painful process sometimes, but uh it gets easier the more you do it. But uh yeah, I leave this to people that uh know Three.js. Um, for me, it was it started a little bit like a hobby project, but at the same time, I use all these libraries also at work, and we do lots of like 3D and CAD stuff. So I like to to blur the lines a little bit and also have fun at the same time.

[00:35:27] Michael Chan: Yeah.

[00:35:28] Paul Henschel: But I'm not like the super knowledgeable person about uh these matters. Uh yeah, I just I just try around a little bit and I see the potential. And uh I know there's lots of people that want to have these crazy websites. And I think now they have the possibility because previously uh this is open just to a very small subset of the JavaScript uh frontend community.

[00:35:51] Michael Chan: Yeah.

[00:35:52] Paul Henschel: They even have uh different job postings for these people. Uh they're called like the GL talent or something. And Three.js is not so hard. You can learn it. There's like— uh I've seen it recently called uh Three.js Fundamentals web page um that goes really in in depth. And uh if you're coming from some front-end perspective, like like I do, you don't need to go super deep into this. You just want, I don't know, to to have some little uh meshes and some shaders. You can steal this off ShaderToy, is uh the website is called. So with a little bit of background, you can already do some serious damage that uh will make your project like really stand out. But I'm not like the knowledgeable person when it comes to this stuff.

[00:36:43] Michael Chan: Well, I'm sure there's tons of resources uh on the Three.js site.

[00:36:48] Paul Henschel: Yeah, yeah, yeah. There is definitely.

[00:36:50] Michael Chan: Cool. Uh well, I have a bunch of questions from people on Twitter. And I wanted to get questions from people because I uh don't do a lot of animating in my in my personal work. So um I just wanted to kind of get some other people's questions and uh see their thoughts about React Spring. And um so I'm just gonna hit um set some of them up and you can knock them down. Um Hypertext asks, what's the need for the different render targets? Uh for example, React Spring 3. If I'm using a custom GL library with React, should I create a new target?

[00:37:26] Paul Henschel: Yeah, okay. Uh uh so React Spring is cross-platform, right? But each um but each platform has like specifics. Uh it has like uh its own colors or the web has like units like px and percentages, all this stuff. So you need to teach React Spring a little bit more, but you can use it also just like this. It's called uh /universal. And then it can uh it can animate everything. You could use it, I don't know, on your refrigerator. I have actually used it in the shell, like uh it was called React Blast or something. You can make shell apps and I I wanted to try and you can just boom, put React Spring in it and then you can animate and stuff. That's pretty cool. But if you want to go deeper, you you need to teach it a little bit about the platform itself. These uh targets are just very little specifics, uh not so much. So you can make your own, of course. If you have like Pixi, it's a 2D canvas renderer, and you want to animate this with React Spring, you can just look into the targets and make your own. It's really easy to do.

[00:38:39] Michael Chan: And what would someone use to to make those targets?

[00:38:43] Paul Henschel: It's all exposed. Uh there's like an object called global You can fetch it from React Spring. And it has a couple of injects. And these injects teach React Spring. So you can inject your colors, you can inject your units, you can inject your style transforms, everything that's needed for the platform. But the most important part is teaching React Spring to animate uh performantly. To it needs to know how to apply values. But that's not that's not so hard. Uh people can, if they if they're interested in this, they can just look into the repository uh src/Targets. And then they can go through a couple of them. Konva, Three, Native. They're really small if they want to make their own.

[00:39:32] Michael Chan: And these are the same primitives that you're using to kind of inject the platform into into your different platform support, right?

[00:39:40] Paul Henschel: Yes. Uh the Three renderer, uh React Spring Three, for instance, it's the same. I just teach it that Three doesn't have like div, span, h1, and so on. It has mesh, line, different native elements. And these are the things I have to teach it. Uh it's very little code to do this. And then you can just use it and animate away on any platform you you want. Basically, it's it's cross-platform.

[00:40:07] Michael Chan: Awesome. Now, Varenia90 asks, is there a way to cleanly disable animations based on which browser is being used or a particular device if they want to just turn animations off for a specific, maybe low-powered device, I'm assuming?

[00:40:22] Paul Henschel: Yes, at the moment, not. We're talking about this on GitHub right now. There's an issue for this. Uh, there will probably be something like a global config that gets merged into everything else system-wide. And then you probably could do something like immediate true and every spring will just conclude to end state. But at the moment, this is not really done. But this would also be cool for testing. People have often had these arguments. They want to test just the end state. They don't care about the animation in the test itself. But this will probably be in version 9, which is upcoming.

[00:40:58] Michael Chan: Cool. What are some common pitfalls for people who are starting to animate UI? Are there are there things that people animate that they they shouldn't? Uh is that something you kind of stay out of? You handle things more from the library level? Or do you have opinions on on what people should be animating in their UI?

[00:41:16] Paul Henschel: Yeah. Do we really want uh to go into this? I could give you some like longer answer for this because also interesting maybe. Yeah.

[00:41:27] Michael Chan: Yeah, absolutely, go for it, go for it.

[00:41:28] Paul Henschel: I think the animation problem has two sides. One is principles and one is the API. Like, one is the philosophy and the other has to do with how do I actually do it. And most of the time I see people only worry about the API. Like, on Twitter I see Ah, the future is here. The Web Animation API will change everything.

[00:41:52] Michael Chan: Mm-hmm.

[00:41:52] Paul Henschel: But they never talk about principles. And there everything for me starts. Um, because for some reason, I'm not sure what happened or how this came to be, but we think of animation in terms of duration and easing. This is a major, major pitfall. It's it's it's regrettable. I don't even know how. this came to pass. And this is not as it should be. Actually, there was something I remember now. Matt Perry, the creator of Pop Motion, he said something in the interview. What was it? Ah, right, he said, we create something and we may even like it, but then we come back to it like a week later, a month later, and we hate it. It falls apart. And I think this is, uh, everyone knows this, right? Happens to the best of us. And he concluded saying that maybe animation is not timeless. What we like now, we may not like tomorrow. Was it something like this?

[00:42:57] Michael Chan: I think so. That does, that, that does sound familiar.

[00:42:59] Paul Henschel: Yeah.

[00:43:00] Michael Chan: And that was, uh, that was episode 35?

[00:43:02] Paul Henschel: Yeah, yeah, yeah, something like that.

[00:43:04] Michael Chan: Is that right?

[00:43:04] Paul Henschel: Yeah.

[00:43:04] Michael Chan: Yeah. Yeah.

[00:43:06] Paul Henschel: And on one side, I totally agree because it happens to me so often, especially with the Android stuff. When I come back to it now, it looks it looks horrible, like really embarrassing. Like, what the hell did I think when I did this? But at the same time, there's a reason why it looks uh like crap. It's uh and I'm also not really in agreement that animation is not Timeless. And I think the there's a there's an answer for this, and it's an easy answer. Uh nothing in the world we inhabit looks like what we animate. Nothing ever does. It it just is not uh like natural. Uh and this is something which I think is super important for animation. And this actually, Christopher Chiodo, Cheng Lu, uh the people behind these libraries, Animated React Spring and Facebook overall, because uh even in the beginning they always uh used springs also uh with chat heads and so on. They recognized this immediately. Um like there's something missing. Uh why do we think of animation in terms of duration, ease? Does this make sense? Like in front of me I have a table. And I have like a like an object and I slide it over to the other side. Like, how long do you think will take to to reach the other side?

[00:44:31] Michael Chan: I yeah, I I wouldn't be able to to know.

[00:44:34] Paul Henschel: Yeah, it no, because the question is stupid, doesn't make any sense. But web developer says, I know, transition, uh all 1 second, ease in cubic, in out, I don't know what. And this is It's silly. It's it's uh it the only answer is it depends. Like depends on the friction of the table, depends on how hard I push the object, how much mass does the object have. So, and I think there's something hidden in in this. Um I actually, I once in my life I study philosophy and um there was something really interesting to me. If you ask anyone today, "Is beauty in the eye of the beholder?" I mean, what will most people answer? What do you think? Yeah,

[00:45:21] Michael Chan: probably yes.

[00:45:23] Paul Henschel: But I was shocked that in the old times, they were like in total disagreement with this. They said, "No, beauty is an objective concept. You can express beauty because beauty is guided by by laws, by mathematics, by physics." And this in in some ways is really true. Nothing that we see is accidental, even nature, like the forms uh that we see, uh the forms that in that a leaf takes, uh the form that uh the shape of our bodies is fashioned after the golden ratio and all this stuff. It's it's not accidental. And since we are like fashioned after the same principles that guide everything in nature, In us, or we have also something like an urgency or capacity to recognize beauty. And beauty and harmony is not accidental. It's a law, like in in music theory or in color theory. They all know this, but for some reason in in animation we tend to ignore. So um I think this is something that these people, they recognized immediately. And if you have some environment uh which is proper, which is uh uh guided by physics, then anything that moves will behave in a natural harmonic way. No matter, you don't need you don't need uh to think about like durations and curves and so on. Like if you have an object, like say a ball, whatever, you throw it, you don't think about it, it just flies and flies naturally. So this is my goal for animation. I want to to have an interface that you just say, okay, this turns green and this goes from left to right, and you don't you don't care, you just let it go. And I think this this is why I think uh spring is the most important aspect of animation, for me at least. So the biggest pitfall is thinking that you should think of animation uh in terms of time. And in terms of curves, uh I will never do this again, but I was so badly burned in my Android days uh that I I learned the hard way. But in the web, I see lots of people say, ah, no, you should, if it's small, you should uh do it in CSS. Yes, do it in CSS, but you will come to regret it because the moment you interact with it, it looks like shit. And there's nothing you can do about it. Uh, you don't notice it in easy animations if you have a sidebar and it just pops open. Yes, it doesn't matter if it takes 1 second or 2 seconds. But if you're bored midway, it does matter. Because what will happen, it will just naively stand still. And then it would take the same time uh like backwards, uh also 2 seconds, even if you interrupt it midway. This doesn't make sense if you have like an object and you tie it to a spring and you slide it over the table and midway you you yank it back. What will happen? It just doesn't like stand still and then it moves towards you. It will expend the rest of its energy, of its momentum, and it will move towards you. And this creates a natural fluid movement. This is why iOS looks so, so good because mostly everything they do is driven by springs. And to me, it's like the guiding principle. Of everything I do in animation. So if you want your animation to look good and timeless, like even chat heads- this is an app I haven't used maybe for 6 years or something, but I know that if I open this up today, it will look good because it behaves naturally, harmonically. And yes, this is the most important thing, I guess. I mean, this is a super long answer. Answer, but it's also super important to me.

[00:49:12] Michael Chan: No, I think that's critically important for answering the question of why this library exists and the the challenges of animating. Uh just in summary, though, so so that I understand it, this does seem to go back to your your original exploration with trying to recreate chat heads. And when you're trying to animate it um using the tools at hand, it just never quite felt right. And so each time you came back to it, it was like, ah, that's not right. It needs to be, you know, better. But it's kind of a moving target. You couldn't quite get there. And what Spring- what it sounds like Spring physics allow you to do is to think about the characteristics of that thing. Think about its weight. Think about the the friction surrounding all that. And then not think about like like like you're- Saying duration. Um, and that these actually enable you to think about animation in a more kind of like physical, natural way because you're not thinking about animation. You're thinking about the properties that that give this thing its mass and shape and character.

[00:50:17] Paul Henschel: Yeah, exactly. But maybe not even this. I think for me, it's more like thinking about the environment. You set up an environment that is physically proper and sound. And if you have an environment, environment, it could even be just the default that you get with React Spring, then everything that moves inside this environment will behave proper. You don't need to think about it at all. You just say this, this thing turns red, I don't know, whatever, it goes here, it goes there.

[00:50:48] Michael Chan: Mm-hmm.

[00:50:48] Paul Henschel: It will always look good. No matter what you do, you cannot make it look bad. Because it's, it's Harmonic, and this is the thing I really like about it. Like most of my personal stuff, I I don't use configs, I don't put a mass on this thing. I could if I wanted it to move a little bit slower, but I know that in accordance to everything else, it will always look good. And this is like, actually it's even the old way, the the old philosophers defined what is beauty. They define beauty as it's something in accordance to to the laws that surround it. It's it's the same thing in music theory. Um I I have a little music background. Uh like the diatonic scale, major scale, you cannot say it is bad because each note sounds in accordance to to the whole. They cannot cancel one one another out. They cannot. They they all sound in accordance. And this was deemed good or beautiful or harmonic. That's that's why we call it harmony. Um and the opposite is disharmony. And you cannot produce disharmony if you have an environment in which everything moves according to physical laws. And this makes a huge difference, huge difference. Um but sure, you can say uh this thing has mass, and- I know people People get a little bit hung up because they come to React Spring and uh they say, "Where's my duration?" They say, "Yeah, it's not- you can forget it." "Yeah, but what are these weird configs? Friction, mass, what is this?" But yeah, actually, you you don't need them. Uh if you like go into it a little bit deeper, you can use it. But the cool thing is, even if you change like mass for one object, It will still move in accordance with everything else because the guiding principles are the same. And this makes it- for me, it makes it nice. I mean, I don't even look at uh animation libraries that don't put that don't put uh springs as the primary interface uh to animation. If there's something comes along and springs is basically like a tack-on, uh it's duration-based, but you can maybe I don't care. I don't I don't want to look at it. I don't I don't feel to use it. Uh same goes with CSS. Yes, I could maybe it would even be easier. I could I don't know some hover and the thing gets bigger. But I know it will it will never look fluid because based on on time. And I won't use it even for for little things like uh hover and things like this. I know people go crazy about this, but

[00:53:31] Michael Chan: yeah,

[00:53:32] Paul Henschel: normally I'm like super defensive if I like something and I need to defend that, blah blah blah, in the internet and cause fights and all this. But for some reason, not about this. It's- it's- I'm so convinced by it that to me it's just natural. And yeah, if someone doesn't like this, they- they use something else.

[00:53:49] Michael Chan: Well, Paul, this is- this is amazing. This is right up my alley. I could listen to you talk about, you know, philosophy and physics and harmony in relation to to our work and animation all day. Um, but I do want to close with a few questions um just about the library itself. Um, so the I guess the final question is just, uh what does v9 look like? What should people be looking forward to? Um, and I guess related is- Is the hooks API part of v9 or is that something that people can use today?

[00:54:24] Paul Henschel: I mean, yeah, hooks is part of uh v8. So uh you can use hooks. V9 is mostly about uh bug fixes. Uh this was Alec Larson's work. Uh he's a co-author and slash uh contributor. And yeah, mostly like bug fixes, stuff like this. We want also to to merge back Render Props again because it it caused some huge like schism before. So you will be able to use the same in the same export. I'm not sure if there will be breaking changes. I hope not. Um, this was funny because you know who's uh Scott Tolinski from Level Up? And he made some some awesome- Yeah. —tutorial. And he asked me. He said, hey, Paul, is the API stable now or is it going to change? I said, yeah, sure, it's stable. You can go ahead. And then he he he gives me the link and uh I I listen to it and he says, yeah, some of these things, it's it's all super great, but some of these could be easier. And I think, okay, could be easier. Let's put it on on GitHub and Twitter and ask people how they would uh think it could be easier. Could be made easier. And then we start some some discussion and we find some API that would basically reduce complexity by half because each primitive has two API signatures right now. But I'm not sure if I want to do this to him again. So it's it would be his own fault. Maybe maybe we wait a little bit. Uh yeah, I don't know.

[00:56:02] Michael Chan: Yeah. Yeah. I mean, I guess if he asked for it, he he kind of has to, you know, take it in stride. We actually just had a— our our last chat was was with Scott. That was the the episode that just went out. And uh and uh yeah, that that course looks amazing. And that was one of the reasons I was like, I I really need to talk to Paul because he's doing some amazing stuff and a lot of people are really excited about um about seeing this API kind of come forth from what has been before. Um, it really does seem kind of like the spiritual successor to to Animated. Um, and people are really loving it.

[00:56:40] Paul Henschel: Yeah, for sure.

[00:56:41] Michael Chan: Cool. Cool. Well, is there anything that you would like to leave us with? I I feel like I got way more than I came for today, which I'm grateful for. Hearing uh hearing you talk about harmony and and and physics and philosophy. All melded together really gives me a lot more context for the spirit behind this library.

[00:57:00] Paul Henschel: Yeah, it's just my background. Uh, I guess I'm not sure. I guess I'm I'm just happy that uh this thing goes goes forward. Um, I managed to put it on its own like neutral organization so that my name isn't uh necessarily attached to it anymore. And this makes it possible for other people to get involved, which I I like. Uh, I mean, it's it's it's totally cool to me that uh they they start to improve it and they go and they hold talks like Alec Larsson, for instance, he made a talk at uh React Europe recently. So I think this is the way forward. I don't want it to just fall asleep because maybe the maintainer does something else or something. So I hope it's something that will be always uh evolving. And yeah, we always like uh taking criticism and feedback into account. People know this. And yeah, I'm I'm super happy with uh where this this whole thing uh was going, and I hope it continues uh its path.

[00:58:01] Michael Chan: Awesome. Well, it's been a delight talking with you. Thank you so much for joining us on the show.

[00:58:05] Paul Henschel: Thank you very much.

[00:58:06] Michael Chan: Thanks for listening to episode 56 of React Podcast. For links and show notes, visit reactpodcast.com/56. This week I was struck by Paul's quest for lasting beauty on the web. It's admirable, and what he says about the philosopher's definition of beauty will stick with me. Beauty is a law. It's something that lives in accordance and harmony with the laws around it. Go and add a little lasting beauty to the web with React. Thanks again to GitPrime. Start debugging your development processes today. Download 20 patterns to watch for in your engineering team by visiting gitprime.com/20patterns. This episode of React Podcast was edited by Mikael Delport. It was produced by Mikael Delport and Sarah Jackson. You can find React Podcast on Speck, a network to help designers and developers level up. Visit spec.fm to find other shows that will take you further in your career. Help us out by reviewing this show on iTunes. Your reviews help the show grow and help us ensure great guests and awesome content week to week. To join the discussion, visit reactpodcast.com/chat or follow us on Twitter @reactpodcast. I'm @chantastic. To stay out of the discussion but get updates, For the latest updates, visit reactpodcast.com/news and sign up for emails. Thanks so much for giving us your attention. We'll be in your ears again next week.