Animate Rotation with React Native Interpolate
lessonDuration 1m 52s
By using the `interpolate` function, the `Animated.View` can be rotated using both degrees and radians.
Browse
Find courses, lessons, articles, talks, and podcasts.
1,542 results for "react"
Showing 1,105–1,128 · Page 47 of 65
lessonDuration 1m 52s
By using the `interpolate` function, the `Animated.View` can be rotated using both degrees and radians.
lessonDuration 2m 11s
We'll use the interpolate function from an `Animated.Value` to transition the background color of an `Animated.View`. We'll simultaneously translate the position with the same `Animated.Value`.
lessonDuration 1m 47s
In this lesson we'll use `Animated.sequence` to play multiple `Animated.timing`, and `Animated.spring` animations one after another.
lessonDuration 3m 57s
In this lesson we'll create a `PanResponder` to allow us to drag a card around the screen. We'll use `Animated.event` to automatically set the values of our `Animated.Value` and when the card is released we'll use `Animated.decay` to decelerate it to a stop.
lessonDuration 5m 28sFree
Learn to write components that render differently on iOS and Android, but present the same API. First, we'll use the Platform module to change behavior based on the platform. Then, we'll use the platform-specific file extensions, .ios.js and .android.js, to render platform-specific components.
lessonDuration 1m 33s
Passing down stores through each layer of components can be a tedious job. This lesson demonstrates how Provider can be used to automatically connect observer based components to stores, by leveraging React's context mechanism in the background.
lessonDuration 4m 52sFree
Classnames is a simple yet versatile javascript utility that joins CSS class names based on a set of conditions. We are going to build a simple toggle switch that relies on state to determine what CSS classes will be applied.
lessonDuration 1m 29sFree
React's inline styles allow components to stand on their own by not requiring any external CSS. However HTML's style attributes don't support pseudo selectors like `:hover` and `:active`. By using Radium to listen to mouse events we can restore `:hover` and `:active` selectors to inline styles.
lessonDuration 1m 52sFree
In this lesson we leverage private components to break our render function into more manageable pieces without leaking the implementation details of our component.
lessonDuration 6m 17sFree
You can easily spend hours configuring the perfect dev environment with all the latest hotness like ES6 (and beyond) support, hot reloading, and a myriad of other features. This lesson shows how to use hjs-webpack to get the same thing in a matter of minutes.
lessonDuration 7m 3sFree
In this lesson we'll use PanResponder and LayoutAnimation to create a smoothly animated Swipe Panel commonly implemented in iOS and Android applications.
lessonDuration 3m 22sFree
In this lesson we'll look at some simple ways to customize TabBarIOS, creating a scrollable tab area, and implementing custom icons in TabBarIOS.Item.
lessonDuration 4m 31sFree
Outside of providing an [express](https://egghead.io/lessons/nodejs-first-api-with-node-js-express-and-mongodb) template engine for JSX, react-engine allows us to utilize the same templates for client side interaction.
lessonDuration 4m 4sFree
An introduction on unit testing a ReactJS component using Webpack and Jasmine. Learn how to use Webpack to package and import dependencies plus take advantage of the babel-loader to write a simple Jasmine spec using the latest ES6 syntax.
lessonDuration 3m 2sFree
this.props.children allows child components to pass through, but in order to interact with or add new functionality to them React.addons provides cloneWithProps.
lessonDuration 3m 7sFree
React.addons provides CSSTransitionGroup for easily implementing basic CSS animations and transitions.
lessonDuration 3m 15sFree
React's use of the VirtualDOM can make it confusing on how to get actual elements to use in animation libraries like TweenMax. This video shows how to use this.getDOMNode() and this.refs and hook them in to TweenMax to satisfy all of your advanced animation needs.
lessonDuration 4m 7sFree
You can use React's TestUtils addon to simulate events for your components.
lessonDuration 4m 24s
Flux has four major components: Stores, Dispatchers, Views, and Actions. These components interact less like a typical MVC and more like an Event Bus. In this lesson we will start by creating our Dispatcher which queues up our Actions as Promises and executes them as they are received. We'll also create an AppDispatcher which, unlike the Dispatcher, is more specific to our application.
lessonDuration 7m 47s
Our build process during this series will utilize both gulp and browserify. In this lesson we will take a moment to setup our environment and all of the tooling required to begin developing our Flux Application. We've kept the build process very simple so porting it to grunt should be a breeze, but this also serves as a simple primer for those who may not be familiar with gulp.
lessonDuration 6m 3s
Stores are where the real work in our application is done. Dispatchers broadcast Actions to all Stores, and the Stores registered to listen for those Actions will perform any logic needed to update our Views. In this lesson we will establish our first Store and register the Actions we wish to respond to.
lessonDuration 4m 37s
Actions contain no functionality, but rather describe an event in our application. In this lesson we will describe our Actions as they relate to our application. These Actions will then be available for triggering in our Views and for execution in our Store.
article
## Animate React Apps with Framer Motion Will released a full-length course on Framer Motion. Check it out if you're interested: <CourseWidget slug="animate-react-apps-with-framer-motion" /> ## What is Framer Motion? Framer Motion is a declarative animation library for React. It makes adding animations to React apps feel simple, even magical. Framer Motion basically hides away CSS transitions from you. You just say what you want, and BOOM the library will handle the css details of the animation. The heart & soul of Framer Motion is Motion components. You can turn anything HTML or SVG element into a motion component by adding `motion.` to the beginning of the element. **Example** ```jsx <motion.div>Motion Component</motion.div> ``` Once an element becomes a motion component, it gets access to a bunch of new props like `animate`, `variants` and `transition` to name a few. ## Prerequisites You would know how to create small applications in React and use features like Hooks. You are also familiar with CSS properties like opacity, scale, and transition. While this isn't an introduction to Framer Motion from scratch. You're not expected to have any Framer Motion knowledge. You will learn Framer Motion by building with it, and I'll explain new concepts along the way. ## What You'll Be Building You'll use Framer Motion with [react-intersection-observer](https://github.com/thebuilder/react-intersection-observer#readme) to trigger squares and scale animation to grow bigger when they come into view. > react-intersection-observer is a React flavored version of the [Intersection Observer API](https://developer.mozilla.org/en-US/docs/Web/API/Intersection_Observer_API) to tell you when an element enters or leaves the viewport. You will not build this application from scratch the starter code is [here](https://codesandbox.io/s/egghead-blog-post-demo-start-z146y?file=/src/App.js) You can view the final demo [here](https://fxjve.csb.app/) ## Set Up You'll start with a React app with four `Square` components rendered on-screen vertically. **App.js** ```jsx import React from "react"; import "./styles.css"; function Square() { return <div className="square"></div>; } export default function App() { return ( <div className="App"> <h1 className="title">Scroll Down</h1> <Square /> <Square /> <Square /> <Square /> </div> ); } ``` The first thing you'll do is install Framer Motion and react-intersection-observer ```bash npm install framer-motion react-intersection-observer --save ``` Next, you'll bring in everything you need to create the animation. * import `motion` and the `useAnimation` hook from Framer motion * `useEffect` from React * `useInView` hook from react-intersection-observer **App.js** ```jsx import React, { useEffect } from "react"; import { useAnimation, motion } from "framer-motion"; import { useInView } from "react-intersection-observer"; ``` Don't worry. You will get an explanation on what each one does when it's time to use them. ## Creating the Animation with Variants To create the animation, you'll use a feature of Framer Motion call Variants (not be confused with Loki variants). Variants are objects that you use to define how you want the animation to look and reference the animation by name. **App.js** ```jsx const squareVariants = { visible: { opacity: 1, scale: 4, transition: { duration: 1 } }, hidden: { opacity: 0, scale: 0 } }; function Square() { --- } ``` Here you created a variant object called `squareVariants`. Inside the object, you have the property `visible` that you passed an object as the value. When the element is `visible` you want it to: * have opacity be 1 * scale to 4x it's size * have the transition from hidden to visible to have a duration of 1 second. And when the element is `hidden` you change `opacity` and `scale` to 0 so it's invisible. Variants are dope because they free up your motion components from being overcrowded with a whole lot of props. You can put all the details of your animation in the variants object and reference it by adding the `variants` prop and to a motion component. **App.js** ```jsx function Square() { return ( <motion.div variants={squareVariants} className="square" ></motion.div> ); } ``` Inside of the `Square` component you: * add `motion.` a the div * adding a `variants` prop * set it to the `squareVariants` object you created Just adding the variants prop won't do anything. Your motion components need to know when you want these animations to start and what state you want them to end up in when the animation is finished. For this, you need to add the `intial` and the `animate` prop. **App.js** ```jsx function Square() { return ( <motion.div animate={{ scale: 2 }} initial="hidden" variants={squareVariants} className="square" ></motion.div> ); } ``` Set the `initial` prop to `"hidden"` this tells Framer you want this div to have an opacity and scale of 0 (which is the value you define for `hidden` in the `squareVariants` object. ) when the pages loads. The `initial` prop describes what state you want the animation to begin. The `animate` prop is the final state of the animation. Framer Motion automatically takes care of how the animation looks from initial to `animate`. The `animate` prop takes objects. Temporarily you'll pass in `{ scale:2 }`. This causes Square to scale to twice its size on page loads, `animate` will be changed later. <EmailSubscribeWidget /> ## Add useAnimation and useInView to the Square Component By default, Framer Motion runs animations once the page loads. The `useAnimation` hook gives you access to the helper methods `start` and `stop` to give you more control over when the animation begins and ends. You'll use the `start` method to set what animation gets get trigged when the element is in view. Create a `controls` variable and set to `useAnimation()` and change the `animate` prop to `controls`. **App.js** ```jsx function Square() { const controls = useAnimation(); return ( <motion.div animate={{ scale: 2 }} initial="hidden" variants={squareVariants} className="square" ></motion.div> ); } ``` Next, you'll bring in the `useInView` hook from `react-intersection-observer`. Use array destructing to pull out `ref` and `inView` from `useInView` return. **App.js** ```jsx function Square() { const controls = useAnimation(); const [ref, inView] = useInView(); return ( <motion.div animate={{ scale: 2 }} initial="hidden" variants={squareVariants} className="square" ></motion.div> ); } ``` The `useInView` hook returns an array with a `ref` and a Boolean `inView` that checks if the status of an element being in view is `true` or `false`. ## Trigger Animation with useEffect Inside of the Square component `useEffect` with an if statement. If `inView` is `true` set it run the `controls.start()` method and pass it the `squareVariants` property of `"visible"`. Use `controls` and `inView` as the dependecy array. Finally, add a `ref` attribute to the `motion.div` and assign it the `ref` from `useInView` **App.js** ```jsx function Square() { const controls = useAnimation(); const [ref, inView] = useInView(); useEffect(() => { if (inView) { controls.start("visible"); } }, [controls, inView]); return ( <motion.div ref={ref} animate={controls} initial="hidden" variants={squareVariants} className="square" ></motion.div> ); } ``` When the value of `inView` changes aka when the element we referenced is in view, and `inView` changes from `false` to `true`. It will run `useEffect` to trigger `controls.start()` to run the `visible` animation. This is a look at the full code **App.js** ```jsx import React, { useEffect } from "react"; import { useAnimation, motion } from "framer-motion"; import { useInView } from "react-intersection-observer"; import "./styles.css"; const squareVariants = { visible: { opacity: 1, scale: 4, transition: { duration: 1 } }, hidden: { opacity: 0, scale: 0 } }; function Square() { const controls = useAnimation(); const [ref, inView] = useInView(); useEffect(() => { if (inView) { controls.start("visible"); } }, [controls, inView]); return ( <motion.div ref={ref} animate={controls} initial="hidden" variants={squareVariants} className="square" ></motion.div> ); } export default function App() { return ( <div className="App"> <h1 className="title">Scroll Down</h1> <Square /> <Square /> <Square /> <Square /> </div> ); } ``` ## Conclusion The demo app should have four boxes that grow to 4x their size when they are visible on the screen. You created this with minimal tweaking of the animation properties. Framer handled the annoying parts for you. You learned how to create motion components, create variants to clean up your code, add the `initial` and `animate` props to tell Framer Motion how you want animations to start and end. Also, you used the `useAnimation` hook to override Framer Motions default behavior of when the animation starts. You also used react-intersection-observer to make it a lot easier to tell when our element is in view or not. ## Next Steps Take Will's course to get a better idea of what Framer Motion has to offer: <CourseWidget slug="animate-react-apps-with-framer-motion" /> ## Resources * [useAnimation Hook](https://www.framer.com/docs/animation/#component-animation-controls) * [Variants](https://www.framer.com/docs/examples/#variants) * [Motion components](https://www.framer.com/docs/introduction/##motion-components) * [react-intersection-observer](https://github.com/thebuilder/react-intersection-observer#readme) <EmailSubscribeWidget />
case-study
Tomasz's journey with egghead began as a learner. When he had to quickly learn about React and Webpack for a new job opportunity in 2016.