chantastic.fm

94: Matt Perry on Magic Motion and React Performance Anxiety

Episode 94 · May 14, 2020 · 00:53:54

Hosted by chantastic · With Matt Perry

Sponsored by Infinite Red

Download MP3 · Jump to transcript

This week Matt Perry tells about Magic Motion — the killer new feature for Framer Motion that makes shared element transitions easy for React developers

We talk about full-stack correction for FLIP animations, the virtuous relationship between product and open source, and how “fear-driven development” kept him from finding a Magic Motion solutions earlier…

Featuring

Links

Sponsors

Infinite Red

In over your head with a React or React Native app? Infinite Red can help. They're React Native core contributors who've been designing, building and shipping apps for over 10 years. reactpodcast.infinite.red

Transcript

[00:00:00] Michael Chan: This is React Podcast. I'm Chantastic. This week, Matt Perry tells us about Magic Motion, the killer new feature for Framer Motion that makes shared element transitions both beautiful and easy for React developers. We talk about full-stack correction for flip animations, the virtuous relationship between product and open source, and how a culture of fear-driven development kept Matt from finding a magic motion solution sooner. Before we dive in, a quick word about our sponsor, Infinite Red. It's great to have a friend who knows a lot about the technology you're using, especially when that friend understands how hard it can be to learn something for the first time. If you're building a React or React Native app, Infinite Red is that friend. They want to help you finish and fix that app that will change your life. They've compassionately taught tens of thousands of developers through open source and their annual React Native conference, Chain React. Get the help you need and 2 free tickets to Chain React in 2021 when you start a new project. Referrals count as well. Visit reactpodcast.infinite.red and with their help, build a beautiful, functional app today. Matt Perry, welcome back to React Podcast.

[00:01:26] Matt Perry: Thanks for having me back. Uh, this is the only podcast I've ever done, especially the only one I've ever done twice. So this is— it's nice to be here.

[00:01:33] Michael Chan: This is the only podcast you've ever done?

[00:01:35] Matt Perry: Yeah. Yeah.

[00:01:36] Michael Chan: Dude, how- that's, that's startling to me.

[00:01:39] Matt Perry: I did it once with you and I thought, you know what, that's not gonna be topped, so I can't do another. And I never did.

[00:01:46] Michael Chan: You know, okay. So, so we need to rectify this because I think that I, I was gonna say not only, not only was, was our chat one of my favorites, but it is still to this day, one of the most popular episodes, like I've ever published, like top 3.

[00:02:02] Matt Perry: Oh, that's amazing. That's like genuinely amazing. That's cool.

[00:02:05] Michael Chan: Yeah, like beat out only by like— uh I did, I think, at that that same React uh conf that we were we recorded at, um an interview with like the whole React core team. So it's like there's that one.

[00:02:18] Matt Perry: I can't remember what the second one is. I'm not gonna even try and compete.

[00:02:23] Michael Chan: People need to get you on if they want to make those numbers, you know?

[00:02:28] Matt Perry: Yeah, well, I'm I I obviously these days I don't have a wild amount to do. So uh

[00:02:35] Michael Chan: I love it. So, the last time we chatted, it was uh episode 35 of this show, which was forever ago. I think it was almost a year and a half ago at uh React Conf. And you gave an amazing talk with uh just the longest title. I think it was like on declarative animation for the web.

[00:02:53] Matt Perry: It definitely contained the words declarative animation. That's about as far as I can remember.

[00:03:01] Michael Chan: It was definitely- you're you're you're you're fitting all the buzzwords in there. Um, so I want to talk with you about what you've been up to since, because I think that you've— uh like a lot has happened, and uh I I think it'd just be fun to kind of catch up. So at the time, you were talking about Pop Motion and Pose, uh which were kind of your um projects owned by you personally. And pretty shortly after that, you moved to um to work with Framer. So tell me a little bit about that move.

[00:03:30] Matt Perry: Um, yeah, so basically I was making or trying to make a lot of noise on Twitter about Pose and declarative animations. And uh Koen, the CEO of Framer, got in touch with me and was like, obviously we need to talk. Because you know, that's right up their wheelhouse. Because they Framer is a prototyping tool for anyone who hasn't um uh used it. And it's based on React as well. So they wanted to make their API a little bit more friendly for uh designers to pick up. And Pose is it was made specifically to be this simple, super simple React um animation API. So yeah, so I I moved to Framer and um basically got to do my hobby as my job, which is really the- well, I mean, this is the best job I've ever had. So.

[00:04:19] Michael Chan: Awesome. Now, what did it look like before? Um, you know, were you doing- to to support the open source, were you doing contracts? Um, were you working with companies? Were you doing training? I know there's a lot of models for kind of integrating open source with with work. Um, what was your your approach at the time?

[00:04:37] Matt Perry: Yeah, so basically, uh, I try and fit some in. Like, if I was um working at a company and I had a specific uh problem, I try and like bake the solution into Pop Motion or Pose, whichever sort of worked best. Um and then when I quit, I decided to work- well, I quit to work on open source exclusively. And I thought I'd- the idea was gonna be that I'd start an open collective or, um, the Patreon as well, and I'd use that funding to- like, I try and build up that funding while alternating between purely open source and purely contract work.

[00:05:12] Michael Chan: Sure.

[00:05:13] Matt Perry: Um and to just to try and keep like a nice mix of an income of any kind and doing something that I really enjoyed. So, in the end, I never actually got around to the first round of contract work because uh I ended up at Framer.

[00:05:28] Michael Chan: Awesome, awesome. Now, you were talking about uh making a lot of noise. Like how much did that play into- I mean, there's there's this really interesting thing that happens a lot now where it's like you start doing an open source project and you're really passionate about it and you're telling people about it. And Maybe that specific project doesn't- isn't the vehicle that takes you like all the way to like open source fame and success. You know, maybe like let's use like something like React Router as an example, right? Like they've been able to build an independent business off of that specific project. But there's kind of this alternate path where it puts you in like in a space to work with and collaborate with people that are doing really amazing stuff that you want to be doing. And that sounds kind of like what you found with Framer.

[00:06:14] Matt Perry: Yeah, completely. Like I felt like we had a uniquely mutual USP, almost. Like they wanted something from me that I don't think- like I felt like I was uniquely able to give them, which is this animation library. And likewise, they had something uniquely interesting for me, which is all these like very domain-specific um problems Magic Move is a great example of that, where they need something that's hard to do, and it's a problem space that I'm super interested in. And so I've got the time and space to do that, and in a way that I can bake the solution to those problems in an animation library, but to the benefit of the company as well. Rather than like normally it was just like a nice side effect, whereas here it's like, you know, they they need these features. And that's great because like I that's so what I'm into that I I can be there to to help them with that.

[00:07:10] Michael Chan: Yeah, it's really interesting because it it seems like, you know, your previous experience, you were kind of trying to solve things in a generic way and then build those those things that you were learning into a library that was kind of like your your like side project like library. But when you found the right partner, you were able to kind of those lines changed a little bit and you're able to like invest in the product, but then also by investing in the product, like have this boundary of like a library that that comes out of that work.

[00:07:38] Matt Perry: Yeah, exactly. Like Magic Motion uh specifically is- and for those who don't know, I'll just like briefly explain that in Framer, you can um draw any two screens and like link them with a little line tool. And you can animate between them in your prototype. Um but it does some like more advanced shared layout stuff. So when you're on a an iPhone, you might get a transition between a list view and a detail view, or a gallery- you know, there's the gallery view and the image view. So it makes these sorts of animations quite trivial to make because you just draw the little line. But I, I think they would have been happy for me to just have that as the, the, you know, we've made the feature, it's in Framer. Sure. The end. But I kind of wanted to figure out, like, okay, Which parts of this can we put into Framer Motion, which is the open source library, and which parts live in Framer? And I feel like we managed to get a good amount of this into um into Framer Motion and expose it in a way that made more sense for developers. So we've got this new Animate shared layout component, which is essentially shared layout transitions. Um and all you have to do is mark up your your code with, you know, this component and maybe a few props that say, you know, this is, you know, these two things are the same and these two completely separate components. So as a designer, it's as easy as drawing this line between two screens. But then as a developer, usually you'd get some crazy animation like this and you just put your head in your hands and go, oh my God. Like, I bet- And and not only would you- it wouldn't even be like, okay, that's gonna be super difficult to make. Like if you give me 2, 3 weeks, I'll be able to make that. Are you gonna get the 2 or 3 weeks? Often not. So now it's it's kind of um it should hopefully, if we've done our job correctly, um it's as simple for the developer to implement it as it was for the designer just to draw that that line.

[00:09:37] Michael Chan: Interesting, interesting. Okay. So the library that powers this in Framer is is the same library that's available to developers

[00:09:46] Matt Perry: Yeah, exactly. It's literally the same. I mean, it is Framer Motion in running in Framer.

[00:09:51] Michael Chan: Interesting.

[00:09:52] Matt Perry: Or in your prototypes. So there's a couple of things that I've added. Um, there's a couple of extensible options that they're not public APIs yet, but maybe they will be at some point. But where I've just added a few other things that maybe you we might like in in uh in Framer, the rotation uh property is quite exposed. So you can use that very easily. Whereas People don't often use rotation in um in in design stuff. Sure. So to support rotation, there's actually an extra uh lifecycle, like an extra um read-write basically that we need to use. Um and so to prevent layout thrashing, I kind of like I suppress that. That's not the full code to support that is an in Framer motion. So we add to it with in Framer. Gotcha. So in your prototypes, you can use it. That you you there might be a way to use it when this crystallizes in Framer Motion at some point.

[00:10:49] Michael Chan: That's interesting. Well, I've always I've always thought that you've had a really good uh sense of where those boundaries should live. Uh I remember even being um kind of impressed by that when we were talking about Pose and Pop Motion and the relationship there. But I want to talk— I I want to you know since we're here, I want to dive into like the specifics of Framer Motion for developers. Because uh I've been seeing like a lot of just killer demos online. And you've been like kind of like retweeting things as people explore them and kind of as you develop them. So, tell me a little bit about uh Magic Motion. Because this is like— like my only uh kind of like exposure to this concept of like things just kind of like magically move between things is Magic Move in Keynote, which I think is maybe the coolest feature that's ever been developed on a computer.

[00:11:40] Matt Perry: And also trademarked, hence the Motion rather than the Move.

[00:11:46] Michael Chan: Did you figure that out the hard way or-

[00:11:48] Matt Perry: It was just a disappointed afternoon when we realized that uh that they had a trademark on Magic Move. It wasn't just a nice feature name, it was literally a TM.

[00:11:59] Michael Chan: That sounds very Apple.

[00:12:01] Matt Perry: Yeah, yeah, yeah.

[00:12:03] Michael Chan: So yeah, so tell me about this killer feature.

[00:12:05] Matt Perry: So yeah, it it so like I say in Framer, like it it it's kind of it's a way to animate between very simple um boxes here, boxes there. It's one color here, one color there, different border radius. You know, these two sorts of screens. But also it can be as complex as um list view to item view. And then, you know, if we've got a scroll view on one page and then you open up a a modal and then that opens up another dialog, you can go back through all of these and it will keep the scroll position for all of them, which is like. So, you know, super difficult to do. You can't do it in any other prototyping tool as far as I'm aware. And yeah, so like I said, I wanted the handover to be just as simple. So there'll be a guide. Um, I kind of toyed for a while. The the API itself was literally Magic Motion. There was a magic prop if you used it just on a single component. Um, and after a while, I kind of- I think it was like the day before I wanted to publish the open beta, I was just had a Hail Mary. I was like, this is, you know, this isn't an API. You can't just have a magic prop. So I had to talk to a couple of people. I'd been way too thick into developing it that I hadn't really seen the forest and the trees. And so that's why we ended up on- there's two features, really. There's um auto in the API in Framer Motion. There's automatic animation where uh before you could tag a component with animate equals, you know, equals and your prop. So, you know, x. 100 or you know opacity 1 and things like this. Sure. Whenever those values changed, it would animate to them. But now you can just say uh motion.div.animate, and it will keep track of any changes that happens to it, whether it's you know style like opacity, background color, things like that, or it's as complicated as layout transitions. So you know you change a flexbox to a CSS grid or you do You know, you can do anything you want, like position absolute to position, you know, fixed or something. And it will detect the changes in layout and it will animate them using a transform. We're using the sort of like classic flip technique. Uh-huh. But that always incurs uh distortion. So you're because you're replicating width and height with scale X and scale Y, your border radius is gonna get squished. Your children are gonna get squashed, whereas this, with a full stack uh correction, will invert all of the— um it will automatically invert any distortion and correct for it. So it looks like a um like a real layout animation, but it's all completely using transforms, so you're way more likely to hit that 60 frames per second. And then the second part of that, this is really so the way Magic Motion and Framer works is is literally just by um the new Animate shared layout component, which, like I was saying earlier, it allows you to do this same thing where you've got the you know the um opacity's different, layout's different, this sort of thing. But you can do it between two completely different components. So it you don't even they don't even need to be you just tag them the same thing. Like oh this one's an underline or a a header or something and it will between completely different screens, it will animate one from the other. Yeah, so those two together is what Magic Motion really is under the hood. And that's how developers are going to implement it. Literally by writing the word animate and by wrapping it all in Animated shared layout, you can do anything that we do with uh Magic Motion.

[00:15:41] Michael Chan: That is the wildest thing. And this is the thing, like this, I think, you know, we've been talking about this. Ryan Florence kind of like started the- sparked this conversation on Twitter, I think, of how, you know, like 5 years ago, it felt like anything was possible in React. And then we've kind of like become really boring, I think, over the last like 5 years. And this is one of those things that is just kind of like blows my mind a little bit. Because I know what a pain in the ass it is to like try to implement any of this stuff. And honestly, like like to the point of being impossible. Like you said, like even if you could get it done in 3 weeks, like can you- will your company allow you to do it for 3 weeks? And like at the end of it, you're really just gonna have like that one feature does that cool view, not like some globalized thing that you can use everywhere.

[00:16:30] Matt Perry: Yeah.

[00:16:31] Michael Chan: So this like Magic Motion thing, just it sounds like magic to me.

[00:16:36] Matt Perry: Well, that's why, yeah, I almost named it as such. But luckily I didn't.

[00:16:40] Michael Chan: So like, I mean, how long have you been been working on this to get some type of global solution that allows you to transition literally between components.

[00:16:50] Matt Perry: So really, I started- the first like real feature that I did around this was in Pose. Um, but it was super light basic. So, uh, it only did layout and the children, it had all the distortion problems. I slowly brought that back into Framer Motion with uh position transition and then a bit more advanced of layout transition. But again, like all of this distortion was occurring. So this is the this this particular feature, I've been working on it full-time for about 8 weeks, which is kind of like— and I I I haven't finished as well. This is still an open beta. Sure. We're still working on the the feature inside of Framer as well. And so Framer is a great stress test, by the way, as well. If it can run if you can just throw prototypes at it that people have just drawn willy-nilly and and for it to to to work in any of these situations. Like it's it yeah it's a good uh bug-finding exercise.

[00:17:47] Michael Chan: Oh, for sure.

[00:17:48] Matt Perry: And a good performance, because you could have like hundreds of layers in this thing, so we need to like run this these animations at 60 frames a second and stuff, so it can be um yeah it's a good uh good optimization target as well. Uh yeah, sorry, so um yeah, so 8 weeks of full-time work, and I think that really is the key difference between- I wouldn't have had that time when I was doing this on my own.

[00:18:13] Michael Chan: Sure.

[00:18:14] Matt Perry: So this is the it shows you the sort of level of investment that a feature like this needs to have from a time point of view. And also like almost like an aspirational kind of thing. Like I don't know that I would have ever landed on the um deep the this sort of like tree scale correction stuff where we, you know, do all the reverse inversions or whatever, like to to fix all of the distortion. I'm not sure I would have ever even maybe conceived that it was possible because of my ignorance of like geometry or whatever it is. Um certainly wouldn't have embarked on an 8-week mission to implement it. But because Framer, the pro- like the app, had um certain product requirements. Like we need, we want, you know, we want a magic move. Okay, well, if you're gonna do a magic move, you need to do it using transforms because otherwise it's not gonna perform very well. And so I say this and then they say, well, yeah, is that gonna work? And I'm like, yeah. And then really what I'm thinking is, fuck, what am I doing? What am I saying? Like, I don't know. So I had to come up with a way to do it. So it's not just a time investment, it is like having to hit these sorts of uh externally produced but also perhaps semi-self-imposed restrictions or or features.

[00:19:39] Michael Chan: You just have a lot of trust in yourself, a lot of confidence in yourself.

[00:19:43] Matt Perry: It's the best way, like fear-driven development.

[00:19:46] Michael Chan: I agree. Now you touch on something that's really important to me in In that this feature was born out of product and actually made better from product. You know, because of all of the constraints of product, like you actually had to think about things at a higher level than just developing a developer API that worked. It needed to be kind of, I guess, at like user level, it had to be polished and nice and uh effective, I guess, for just, you know, when you're just drawing lines between things. Um, what have you learned through that process of kind of like coming through like a product feature, especially like a highly visible product, versus kind of, um, you know, the the mode that you were in before where you're kind of open source and work are a little bit separate?

[00:20:39] Matt Perry: Yeah, I think it comes down to the aspiration of the feature set. Um, people have like product requirements you don't even know they have, so- or they don't even know they have. But you- this is like broadened the, like, the sort of inputs into propelling me forward to going, oh, I can solve this, I can solve that, this is how you solve it for- and then, oh, that API is too complex, it's okay, well, how about this? And you know, the whole animate equals, um, x Coming from Pose, where everything was based on poses, I wanted to use essentially poses again, which we have, which variants are used to sequence animations throughout full trees. But um there was it was there was a meeting where uh Jorn, the head of product, he said— um or CPO, is that head of product? He's a head a lot. He's a head. He's a head. He's head honcho. He um said, uh, man, this is still too complicated for designers. You know, you need to come up with something like easier, basically. I was just, well, you know, almost like, for fuck's sake, you know, like this is, how could it be? Well, the easiest thing you could do is like animate equals x: 100. And that's, and as I said out loud, I was like, man, why not just do that in the first place? Like this is, this is ridiculous. But you've got, you carry so many preconceptions in your own head. It's the same with this animate, you know, just as a prop. Like, in my head, it was too expensive to query an element for um layout and styles and stuff. And then diff that against a second snapshot, especially, you know, before and after render. And we we were looking into like a performance issue earlier today. And that was like nothing. And we're talking like hundreds of layers, and we're querying all of them.

[00:22:37] Michael Chan: Yeah.

[00:22:37] Matt Perry: But because we batch them into- like, we do a whole tree batching of these lifecycle methods. And so you only ever really get- you get maybe, um, 2 writes, 2 renders sort of things, um, rather than the hundred. You know, you could be thrashing, layout thrashing, basically, if you did that once individually for every component. Um, and it was only because I've been pushed into this situation where the the feature required it. I would never- basically, like, I would never have made this feature on my own because I would have had the preconception that doing this doing it this way is too comp- uh sorry, it's too um performance intensive, or what did you say? Like, it's it's not performance-

[00:23:22] Michael Chan: Too slow. Yeah, yeah, yeah.

[00:23:24] Matt Perry: Thanks, man. Yeah. Yeah. It's also-

[00:23:27] Michael Chan: I'll just use the small word. Yeah.

[00:23:29] Matt Perry: Yeah.

[00:23:29] Michael Chan: Performance is above my pay grade.

[00:23:31] Matt Perry: Yeah. It's uh yeah, it's taken a- this magic has taken my vocabulary from me. That's the other downside to uh to working on this feature. But yeah, so yeah, it it definitely gave me that sort of, um, it did the— the not bravery, but like the— it forced me to do something, and then when I did it, I realized that actually it wasn't nearly that bad. It wasn't as bad as I thought it was gonna be.

[00:23:59] Michael Chan: This is something that truly fascinates me a lot. And like one of the- like a lot of my favorite programmers use product as a constraint for like all development for this reason, right? Because it's so easy to just get into the weeds on like, oh, well, you know, I know that that's not gonna work because of X, Y, and Z, or like the performance characteristics are gonna be off or like whatever. And then- but like so often, like when you just kind of look at it from the other side and try it from that other angle, the solution kind of like emerges and you're like, oh, man, like all of that was just nonsense, right? Or like maybe it was true in like a different situation and I just carried it over unnecessarily to this one.

[00:24:39] Matt Perry: Yeah.

[00:24:39] Michael Chan: And um I love that. I love that. I love seeing like solutions that, you know, kind of once you let yourself go towards the like the clarity of the the outermost like user-focused API, um, they just kind of like trickle down in like these really beautiful ways.

[00:24:56] Matt Perry: Yeah, it it genuinely, I find it almost terrifying that my imagination is sort of bounded so heavily in knowledge that I might have picked up up to 15 years ago. You know, this is sort of, you know, what is querying the DOM expensive? Like a little bit, but not really, not compared to XYZ. So, and so I haven't done it for, you know, the 3 years that I could have done this particular feature. With a declarative React animation library. So it makes you wonder. You're looking around like, what else is out there in the in the in the hedges waiting to- I don't know.

[00:25:33] Michael Chan: What else am I not doing out of out of fear? Now, you mentioned the uh sorry, this full stack correction. Could you like dive into that a little bit more?

[00:25:44] Matt Perry: Yeah, yeah, for sure. Like this is um When I say my ignorance of geometry, this is kind of what I mean. I think every time- so basically, when you flip, which is, um, you've got two layouts and you measure the difference between them, and say one's like 100 pixels high and the other one's 200 pixels high, well, you can lay that out as the final thing, which is 200 pixels high. Then to make it look like the old one, you can- to make it the same height, you can just make a scaleY of 0.5. So now you've got something that is 200 pixels, but it looks 100 pixels tall. But really what you've done, because you use scale, is you've squished everything inside of it. And now all of it looks like flat or flattened. Like when you've taken an aspect ratio of an old TV show and like stretched it across your 16:9 TV. It's like that sort of experience.

[00:26:40] Michael Chan: Yeah, yeah.

[00:26:40] Matt Perry: Um, and so you get this. And If you want to- and it's the same with border radius. Say you had a border radius on that component, that's gonna look squished as well.

[00:26:50] Michael Chan: This is an animation technique, right? Where you kind of like in like in memory, you're kind of like just making it the final thing and then like you said, scaling it back. But it's because it's a transform, it's not actually all of the dimensions that were like the thing that you created originally.

[00:27:07] Matt Perry: Yeah, exactly. It's not a real layout. So you're having to- if you want to make that look normal again, okay, well, now you've gotta go one child deep. You've gotta go, okay, the the scale on this um this uh child element now needs to be 2 to correct for its parent being squished. So you squish the parent by half, you need to double the-

[00:27:29] Michael Chan: Gotcha.

[00:27:30] Matt Perry: And then, I mean, you that usually only goes one level deep, but it's quite difficult to do this Basically, I wanted like a universal solution that wasn't just one child deep. It was every child. It was, you know, if what if that child's child is doing the same thing in this stack? And, you know, or you've got multiple ones of these at all sorts of places on the screen. You, I just wanted- oh, and the other thing is, if you try and animate- so this is the other complication that we needed to fix. In Framer, it's so easy to make these sorts of new layouts and animate between them. Whereas as a developer, you might not always- like, you think, oh, that's gonna fail because of the scaleX on this parent, so I'm not gonna do that. But in Framer, all you care about, you just want to move this box there and have it animate as normal. Yeah. But say you're, um, you're animating this, this half-width or half-height, um, component, and you're animating it back to its normal height, so back to scale 1, basically. If you're trying to animate a component within that, um, on the on the same axis, so say if it was width, you'd be animating this ball or icon or a person's avatar or something- Sure. —on the X scale. Well, if you're squishing and squashing the coordinate space that it wants to move through, then you're gonna get the tween is gonna— or sorry, the animation is gonna sort of speed up or slow down as the thing gets squished and squashed. Because it's like the— it's like the expansion of space, you know, like the— yeah, the space it's moving within is actually getting bigger or getting smaller. So the distance it's traveling versus the— what it thinks it's traveling is different to what the viewport actually is because you've like halved the coordinate space. Sure. Well, now if you move it x 100, it's gonna actually go visually a different amount than 100 pixels on the screen.

[00:29:25] Michael Chan: So, so, would an example of this be like, kind of like how Apple, like in the App Store, they have those cards, right? And like the cards are maybe kind of like rectangular, like uh in like they're they're wider than they are tall. But then when you expand them, they take up the whole screen. So now like the the kind of eventual size is that they're taller than they are wide.

[00:29:46] Matt Perry: Yeah, exactly.

[00:29:48] Michael Chan: When you're animating to those, like if you have a circle, it's gonna take on some weird oval type shapes when it's transformed between those two sizes.

[00:29:56] Matt Perry: Yeah, that's precisely it. Yeah, yeah.

[00:29:58] Michael Chan: Gotcha.

[00:29:58] Matt Perry: And you want that so you want that to be that circle throughout the whole thing.

[00:30:01] Michael Chan: Yeah.

[00:30:02] Matt Perry: And it's the same with every other element on that in during that transition. Um, so what we do is uh we keep a we keep track basically of for every component, we keep uh sort of like a transform stack.

[00:30:15] Michael Chan: Okay.

[00:30:16] Matt Perry: So we we apply it as sort of as normal. But it just means that every child can go up the stack and before- so we have so every component has like a shadow bounding box.

[00:30:28] Michael Chan: Okay.

[00:30:28] Matt Perry: And we animate that instead. So we animate that normally on like what we'd call what I'd call like the screen coordinate space. So the ball, you just animate that normally from x to y. A to B, sorry, X to Y is a bit confusing when you talk about axes. From A to B, and you can give it any animation that you want, but it's doing so completely independently of any transforms or anything. But because we know the transforms for everything above, what we do is apply that to the actual position of that ball, the real one, before it's taken any transforms on.

[00:31:05] Michael Chan: Wow.

[00:31:05] Matt Perry: And so we apply it to that. So, and this is, my wife had to teach me this. We were in a bar one night and she had to like teach me geometry on a- I just wanted to like figure out this once and last and just like like tween between them, but um she was like, "No, you're gonna have to do this every frame, basically." I was like, "Oh my God." I don't want to do this. Yeah, like so so we do this stack, this whole stack correction every frame. It's actually it doesn't take that much, um it's not that like much more than a normal animation, basically, in terms of uh computation. We we go through the tree, Apply the transform to the real element, and then we figure out the final delta between that and where our animated shadow bounding box is.

[00:31:50] Michael Chan: Okay.

[00:31:51] Matt Perry: And that's what we have to apply. So that's all you have to do. Once you've got that, once you've applied all the transforms, you just need to figure out that final delta every frame to where it where it's been transformed to. Like, is it an oval now? Is it, you know, whatever?

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

[00:32:08] Matt Perry: Okay, now what? After all of that, after whatever the parents are doing, what final transform do we have to apply to this element to get it to look like we want it to look on the screen? And that's it. So to get like- because I don't- I'm quite ignorant about like maths and geometry, it was a bit of a challenge like to actually implement it. But like, honestly, if you've got even a rudimentary knowledge, it's, it's kind of like a It's so embarrassing at how simple it actually is when you look into it. But yeah, that's that's that's a technique. And it just means that now, especially, I think we finally got it where you know nothing's gonna look weird. You can throw pretty much anything at it.

[00:32:50] Michael Chan: That's so wild. So so if I understand correctly, basically, because the— and I don't have that rudimentary knowledge, so I'm just kind of you know going off of of of what you you're telling me.

[00:33:02] Matt Perry: Oh, good luck then.

[00:33:04] Michael Chan: Because um the the animation is going to have uh like some some additional motion to it, right? Like it's not gonna be like a linear thing. Uh you have to like take it from like the eventual state and like calculate those as individual frames. Like the difference between individual frames for every single element that is represented in that.

[00:33:24] Matt Perry: Essentially. But and and we also have to do it once— if like we can't like pre-calculate any of this or anything like that because Um, we, the orchestration of anim- like at the moment, we impose one animation on all of the properties because-

[00:33:39] Michael Chan: Okay.

[00:33:39] Matt Perry: Um, we, well, I I've got this other thing where you can crossfade between two of these screens if you have to. So, for instance, you might have like um a text uh box that's wrapped in one layout like, you know, this. But then in the other layout, it's like slightly longer or whatever. If you're just to transform those bounding boxes, they can it can look really weird when you finally swap them out. But with the crossfade, you animate both of them in tandem and crossfade between one tree to the other.

[00:34:09] Michael Chan: Gotcha.

[00:34:10] Matt Perry: So it kind of masks any of that weirdness that you might- you probably won't, it depends on what your design is. But, um, and so because of that, you need them to animate at the same time.

[00:34:21] Michael Chan: Yep.

[00:34:21] Matt Perry: But at some point, I want to make it that you can animate these things individually So even as the parent's squishing and squashing, you can animate the you know the child as if it's completely independent of that. Uh so this is something currently that we have to do once a frame, take into account all the parents, blah, blah.

[00:34:42] Michael Chan: Interesting. Yeah, I know that that's kind of like a a a a staple of magic move in in um what's the name of that app?

[00:34:51] Matt Perry: It's Keynote, isn't it?

[00:34:52] Michael Chan: Keynote, yeah, yeah, yeah, Keynote. Um sorry, in Keynote is that Magic Move is like its own animation. There's like there's no controls into Magic Move. It's like, you know, we decide like when, you know, an element can be transitioned, how it's gonna be transitioned, and like which ones kind of default back to crossfade.

[00:35:10] Matt Perry: Yeah. So, at the moment, you can go in and like change the the nature of the of that. So, you can use a spring, you can use a duration-based uh animation. And you can do all that in Framer or in code. But I want to make it so that you'll be able to um go into every component. And the same way that currently you can have variants, and like with a variant, you can say, okay, when I change to this variant and my child changes to this variant, I want all of those children to stagger, you know, after 10 milliseconds, do the next one, do the next one. So you can start orchestrating things in a in a React component-like way.

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

[00:35:49] Matt Perry: Um, very modular. So you can say, you know, if you put that child somewhere else, it'd be- it wouldn't have a delay. It wouldn't define its own delay. The parent does it. So you can stagger over these children. Um, staggering's like a parent thing. So I want the same thing here where you can go to a parent and you can say, if I do a shared layout transition and you're a bunch of items and you come in, I want you to come in one by one after 20 milliseconds or something. Um, so, yeah, so to do that, to support that at some point, like that really now is just an API problem. Like I just haven't figured out the best way to do that. But when I do, like it should be- I'm hoping there won't be any unforeseen consequences. I think it'll be fine.

[00:36:31] Michael Chan: Oh, it'll definitely be fine. I have full confidence in you. You've gotten this far. I'm pretty sure you can take it the rest of the way.

[00:36:37] Matt Perry: Yeah, I've gotten this far by making bold claims. And then like- Getting a hot flush, as you can see, while I figure out how to- I don't even know how to start solving these problems.

[00:36:49] Michael Chan: So one thing I'm curious about is, I know that with Pose and Pop Motion, the relationship was such that you were able to easily transport it to Vue, or that's what something you were working on at the time. How much do these new features depend directly on React?

[00:37:07] Matt Perry: Yeah, well, because I wrote this um from the ground up for React, a lot, like it it really does depend on and in spite of and because of. So I've I've worked with and against these life cycles. Um, but it's it's pretty baked in a lot of this. Uh there's some things that are completely portable, like the drag controls, for instance. All of the logic's contained in the class. So with the right abstraction, you could probably just like hook into this. And use it in Vue or whatever you wanted to use it in. But I think on the whole, it's very much React first. And kind of, yeah, by design, I think. I quite like the idea that I'd be able to think completely in terms of React and what that would mean for the maintainability of the project going forward.

[00:37:53] Michael Chan: Sure.

[00:37:53] Matt Perry: With Vue and Pose, it kind of just got quickly dropped because I didn't know a lot about Vue. Yep. And, you know, you build- it's hard to detect where the bugs are. And it was just- it became a bit of a nightmare supporting all these different platforms.

[00:38:08] Michael Chan: That's really interesting. Now, I know that, um, to kind of back up kind of like a lot, uh, Framer is specifically like a React tool. Like to such a degree that you can actually kind of, um, build up like a component library that you would use in Framer and whatnot. Um, so It seems like kind of Framer has already made like a like a decision to really just be like a React project.

[00:38:34] Matt Perry: Yeah, for sure. I think that was somewhat like made quite early on. The the component thing is like a super big part of it. Like when you have a design system or a design— um like a design uh a style guide back in the day.

[00:38:49] Michael Chan: Yeah.

[00:38:50] Matt Perry: It's a component, you know, it's a storybook, it's a it's a list of components. That's all it is. Like but now we can make those live and publish and share them, have a single source of truth. We're not there in all these aspects, but I think that was the real draw for React.

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

[00:39:06] Matt Perry: And it's it's interesting, it's like imperative ways of coding are actually in some ways more natural to us. I think when we just start out hacking, um we think of it in an imperative way. Uh so a lot of designers and developers have had difficulty making that mental leap to the declarative model. But I think when you get there, it becomes a lot easier. We had like a lot of complaints when Framer Motion was first released that people couldn't make things like this shared layout stuff. Like you literally just couldn't, you know, you couldn't make it or they didn't know how to make it. I didn't know how to make it. But there was always like this underlying belief that when we do fix it, It'll be fixed and you'll be able to do it and it'll be way simpler. Because if you look at it, because you say, like, also, how did you solve this in in a previous- because the old Framer was, it was on CoffeeScript. So you had to, it really was like every, in the very original Framer. So it was like, okay, so how did you, you know, how did you actually solve this in the old in the old Framer? And they'd show you the code and you're like, fuck me, like, this is, this is insane. This isn't how to, this is like 5 1,000 lines of code. No one should be put through this ever. And now, like, it is, you know, there's the GUI experience, which is the draw the line thing, but there's the declarative experience for the developers as well, which is literally your intention. Okay, this is a layout ID. So on this screen, it's here. On that screen, it's there. I'm gonna swap them now. And you figure that out. And that's, you know, that's the declarative way. And now I don't think there'd be any arguments that simpler than what you would have had to have done with that imperative um thing. And I think so I think that in that respect, the component um based the the choice to go for components basically has has is paying off.

[00:40:59] Michael Chan: Yeah, yeah, yeah. Yeah, it seems like a lot of times you need to— we've talked about this on this show a lot, like the need for constraints, like to decide in advance like what your constraints are gonna be and just target that. Because you can't You can't do everything. And um especially in domains that you're not too familiar with, right? Like so like you know trying to support Vue, uh it it's just kind of like a distraction almost from the work that you really enjoy and feel most capable to do.

[00:41:28] Matt Perry: Yeah, for sure. Um and you know this even thing the choices in this another good example in Framer especially is uh we use the DOM on the canvas. Which could be a you know could be a controversial choice. You might think, oh, well, actually, I prefer to use uh Canvas.

[00:41:44] Michael Chan: Sure.

[00:41:45] Matt Perry: You know, because that's a you know you conceivably that could be a a more performant experience. But because we didn't, because it's just using normal React, um now you're getting frame motion. If you design something, you can export it straight away. It's gonna look the same. It's gonna work the same. You want to import something from another library, you know, you can do so. So, you know, it's a constraint in some respects.

[00:42:11] Michael Chan: Sure.

[00:42:11] Matt Perry: As someone who's like looked into performance issues before, like the DOM isn't always like the nicest thing to go mucking around in. But at the same time, the benefits that you get out of that is also- and then they can then further influence the product direction.

[00:42:29] Michael Chan: Yeah.

[00:42:30] Matt Perry: Like once you set your parameters, you you sort of get funneled down a path.

[00:42:33] Michael Chan: Yeah, yeah, yeah. Now I know that React has kind of historically been unfriendly to the like the notion of a shared element transition. I'm curious, uh from your perspective, having done this work now, are there things that you think could be improved in React to make this kind of more like built in from the framework?

[00:42:56] Matt Perry: Yeah, it's tough to say what I'd want out of them. Maybe lower level access to um the lifecycle events. So at the moment, the the the wrapping component, AnimatedSharedLayout, it isn't actually something that we- I think if the lifecycles were different, we wouldn't actually need it. And we could actually do all a lot of this without any um wrapping component.

[00:43:21] Michael Chan: Interesting.

[00:43:22] Matt Perry: And it's the same with- so we use um for a lot of our demos, like the App Store demo and stuff, we use we mix in animatePresence, which allows you to animate unmounting elements as well, unmounting components.

[00:43:35] Michael Chan: Sure.

[00:43:35] Matt Perry: So the two together work really nicely. But if but the animatePresence as well, like that does that need to be there, or is that a limitation of the of the lifecycle methods that we get from React? So In those sorts of respects, I would say a couple of wrapping components, you know, it's not gonna kill anyone, but it is it's it's almost like a shame when it's so it's already so lightweight from what you have to write as a developer. It's like, oh, I just I'd love to, you know, because you can't like the the shared layout stuff and the automatic animation stuff. They both use the majority of the same code. So it is possible to do loads without a wrapping component.

[00:44:17] Michael Chan: Interesting.

[00:44:17] Matt Perry: But apart from that, like, you know, I'm a big, big, big React fan, and I think it's a paradigm. I don't buy- I've never really bought that it's just another jQuery. Obviously it's gonna have its day one day.

[00:44:30] Michael Chan: Sure.

[00:44:30] Matt Perry: But I do think that the model and the- it's more than a set of utility functions, which is essentially- that's all jQuery ever was. This is like- this is a- it's a different way of thinking about Your app and how it you know how it works, how it's put together, how it's shared. And just that expressiveness where really reducing the API down to you know a div, motion.div, animate. Like that's so reductive. Like I you know I could never have written. And as someone I'm looking at Pop Motion's API again, um as now probably its only user, uh where I can I use it in Framer Motion. I'm trying to potentially rewrite it so that it's a bit more like low level. Sure. And for people who really need that flexibility. Um and it already was, so that's really saying something. But like I want to make it really gritty now, really unlikable. And uh it's um yeah, I I don't know. I think it's uh it it's easy. Like there's a lot there's so many assumptions that you can bake into a React API. For instance, the fact that it's like a component that has a a mounted ref and all of this sort of stuff. That when you when you're building something from scratch, where it has no idea of hierarchy or children, you know, parents, context, life cycles, and all of this has to be done imperatively, the APIs can become so much like dirtier. Yeah. And and and that's you know, that's way more than like a couple of wrapping functions here or there, you know.

[00:46:01] Michael Chan: Interesting. Man, I could talk to you all day about this stuff, but we are kind of uh coming to a close. I think we're kind of like closing in on an hour. And I know you have some super important work to do. Um but I have just two things that I want to kind of like wrap up with. Um the first is just kind of like now that you're working with a company that prizes open source or the like export of open source solutions, um like how do you feel about that kind of coming from from your previous experience?

[00:46:29] Matt Perry: Yeah, I mean, I love it. It's amazing to- yeah, to, um, to do- well, it's amazing to do what I wanted to do as a hobby as a job. And it's great to- when you get like a new feature like Magic Motion, it's kind of- I'm super excited to see all of- like you say, you know, people are sharing stuff on Twitter and I'm retweeting them because I'm genuinely like excited to see what people are coming up with. Probably more so with this than perhaps Framer Motion the first time. Like, last year's release was amazing. But now seeing what people are actually coming up with with this one in Framer and in, you know, code on CodeSandbox or whatever, um, it's it's awesome. And I'm hoping to see, you know, because it's open source, like, I want to see this in production. I want to see, you know, people making some real stuff of it.

[00:47:21] Michael Chan: Well, I think it's really interesting because it feels like, you know, as a as a company, like it's a very virtuous way of working because as a company, it seems like they're getting the best of you, like kind of having your excitement and your your like your full mind on this on this problem. Um, but then also, like, you know, you're not trying to figure out like how you're gonna support yourself while you do the thing that you're passionate about. And that seems awesome to me.

[00:47:46] Matt Perry: Yeah, no, it totally is. Yeah. And it's like, I'm not having to think about like the next- like, for me, like you say, this is easily the best way to get the most out of me. But obviously that isn't necessarily what's best for the company or for the product. But I personally believe, and so far they agree, I think it is also the best way to get stuff out of their products, which is, you know, such a great, um, mashup basically.

[00:48:13] Michael Chan: Yeah.

[00:48:13] Matt Perry: Um, and I do think I think it adds a lot of value to Framer as well. I think it's uh I think it used to annoy me like in Photoshop when I'd make something that looks super cool and I'd be like, right, time to make that in CSS. And back then, obviously, you had you know you had nothing. Um, you know, you didn't have border radius or anything. So you had to make that with images. Like really, like it was the pits.

[00:48:34] Michael Chan: Yeah, 9 images.

[00:48:36] Matt Perry: Yeah, exactly, exactly. And so now. Yeah, box box shadows, I mean, my God. But now to know that like you can make something super like the the shared layout stuff and then it's relatively trivial to go and implement that. Like that's I think that's a a a big boon like to have that in a because now when I mess around in Framer, like I know that I can go and grab that somewhere else as well.

[00:49:01] Michael Chan: Yeah, yeah, I love that.

[00:49:03] Matt Perry: In in production.

[00:49:05] Michael Chan: So you've been like super bullish about um animation on the web. I mean, for for as long as I've known you, you've been kind of like carrying this torch of like, hey, we can get there. We can make the web like an awesome platform that's that's that's beautiful and feels, I guess, natural or like real in the same way that that native platforms do. I'm curious, kind of as you look into like the next, you know, uh maybe 2 to 5 years, Are you still excited about that same goal or has that shifted a little bit?

[00:49:38] Matt Perry: I think uh with like Magic Motion, like way more than before, I'm hoping that this sort of erases- like anything that's left now is performance related. And I think we can get that out the way. Like we'll figure that out. Um I I I'm hoping maybe a few gestural stuff as well. But I think we're really getting to a point where there's probably no excuse now for the web to be shoddier than a native app. Like we and in in some respects, like I was looking at how they do these shared layout transitions in iOS. There's no excuse. Like they it's not pretty. Um so in that respect, like I'm I'm super excited to see when you know when we've got this in in master and it's a proper release. Because it's only an open beta at the moment and there's some things to figure out. But I'm excited to see what people come up with. And then looking ahead, I kind of want to take this in a more abstracted way to, you know, 3D mediums. See, I'm hoping that they- the form factors of the headsets and or devices or displays, whatever, um, sort of come not down in price because I think they're probably quite a nice- but I hope they increase in capability.

[00:50:51] Michael Chan: Sure.

[00:50:51] Matt Perry: And I hope they decrease in, in, uh, in weight. Quick enough that I'm not waiting another decade for my promised virtual reality future. But I'm I'm hoping that when it does, like, it doesn't take quite as long next time to for the web to be able to offer the same fidelity of experiences. Like, what you're seeing on the iPad now, the new iPad Pro, the LiDAR sensor, is like- they're clearly making a play to nail AR. Yeah. Before this even glasses out, like, no one's gonna use it still. Sure. But they'll know how to make it when the headsets get here.

[00:51:29] Michael Chan: Yeah, interesting.

[00:51:30] Matt Perry: Yeah. And so I want to see stuff like- I want to see those APIs. I want to see, like, um, React Three Fiber is such a, like, great project.

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

[00:51:40] Matt Perry: That I think it's gonna take stuff like that that makes 3D way more accessible to not just React developers, but like the in the concept of declarative 3D UIs. Um, I think that's what excites me at the moment. Like I'm I'm hoping we get to play around with that a bit more, a bit quicker.

[00:51:59] Michael Chan: I love it. I love it. You've always you've always been like a step ahead on all this like animation stuff. And and maybe even more so just in the belief that it is possible and should be easy. Um, and so I really appreciate your uh commitment to that and uh just vision for that. And uh yeah, so thanks for being on again.

[00:52:20] Matt Perry: My pleasure, my pleasure.

[00:52:21] Michael Chan: It's been-

[00:52:22] Matt Perry: Yeah, thanks for having me.

[00:52:23] Michael Chan: It's been amazing. I I I always love chatting with you, and I'm sure that everyone's gonna love hearing um all the cool stuff you've been at.

[00:52:31] Matt Perry: Thanks, man. Yeah, cool. Well, stay safe.

[00:52:34] Michael Chan: You too. This has been episode 94 of React Podcast with Chantastic and Matt Perry. Find the people and projects mentioned in this episode episode at reactpodcast.com/94. Thanks to our sponsor, Infinite Red. They're ready to come alongside you to help fix and finish that app you've been dreaming of, built with great patterns and practices for the long haul. Visit reactpodcast.infinite.red to get expert help, 2 tickets to Chain React Conf in 2021, and a beautiful functional app today. If you like this show, there's a fast, free way to demonstrate your support. Leave us a review on iTunes. It's the best way for you to let me know what you think we're doing right and what we can improve. 2 to 3 minutes of your time helps us make the best show we possibly can. As always, links and show notes for all episodes are available at reactpodcast.com. This episode was edited by Mikael Delport. It was produced by Mikael Delport and Sarah Jackson at Speck. A network to help you level up in design and development. Check out spec.fm for other shows that are sure to fast-track your career. I'm your friend, Chantastic. Thanks for listening. We'll be in your ears again next week.