NATIVE COMPONENTS ANIMATIONS
PROS CONS
• maximum performance
• platform-specific
behaviour “by default”
• very little work
• very limited set of components
• often impossible to customise
LAYOUT ANIMATIONS
PROS CONS
• native performance
• very easy API
• works for layout properties
only
• non interruptible
Slide 11
Slide 11 text
ANIMATED.JS
“focuses on declarative relationships between input and outputs”
Slide 12
Slide 12 text
ANIMATED.JS (basics)
var someValue = new Animated.Value(0);
// can be kept in the component state
return (
Hello!
);
Animated.spring(
someValue,
{
toValue: 1,
friction: 0.5,
}
).start();
Slide 13
Slide 13 text
ANIMATED.JS (basics)
var anotherValue = new Animated.Value(-200);
var product = Animated.multiply(interpolatedValue, anotherValue);
var interpolatedValue = someValue.interpolate({
inputRange: [0, 100],
outputRange: [0, 1],
});
someValue:
0
anotherValue:
-200
in
requestAnimationFrame()
ANIMATED.JS (implementation)
Slide 17
Slide 17 text
someValue:
0
anotherValue:
-200
in
ANIMATED.JS (implementation)
event
handleOnScroll()
Slide 18
Slide 18 text
ANIMATED.JS
PROS CONS
• very flexible
• allows for defining
gesture interaction
• best performance when
not animating layout
properties
• difficult to express layout
animations – complementary
API is needed
• gesture reaction latency
• overloading JS thread
Slide 19
Slide 19 text
ASYNC FATE
Thread
Thread
UI
I’m free and can do whatever I want
but I won’t be blocking the UI
Render some stuff with React and then
send render commands to the UI Thread
RENDER,
RENDERRR..
Animated.spring(
someValue,
{
toValue: 1,
friction: 0.5,
useNativeDriver: true,
}
).start();
OFFLOADING ANIMATIONS
LIMITATIONS
• implemented on Android only
• only a subset of Animated.js has
been implemented
• animating layout properties is not
supported
• using value update handlers will still
require JS roundtrip
• single value cannot be used for
animating both using native driver
and using JS driver
https://github.com/facebook/react-native/pull/7884