react-spring: [react-native] Animated transform not working
I see there’s #360 and #361, but it’s not working for me on latest version. Maybe there was a regression?
I’m using latest version with hooks (^7.2.8
).
React Native 0.57.4
with hooks enabled.
import {View } from 'react-native'
import { animated, useTransition } from 'react-spring/hooks'
const AnimatedView = animated(View) // also tried animated(Animated.View)
This doesn’t work
// ...
from: { width: 0 },
enter: { width: size },
leave: { width: 0 },
// ...
<AnimatedView style={{ transform: [{ translateX: transition.props.width }] }}>
You passed an Animated.Value to a normal component
This doesn’t work
// ...
from: { transform: [{ translateX: 0 }] },
enter: { transform: [{ translateX: size }] },
leave: { transform: [{ translateX: 0 }] },
// ...
<AnimatedView style={transition.props}>
Invariant Violation: You must specify exactly one property per transform object
Just for reference, these work:
<AnimatedView style={{ width: transition.props.width }}>
<Animated.View style={{ transform: [{ translateX: new Animated.Value(100) }] }}>
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 5
- Comments: 21 (9 by maintainers)
The following worked for me on iOS, Android and Web on a
react-native-web
app using bothreact-spring 8.0.19
and9.0.0-beta.1
. I believe it should work on areact-native
only app too:If anyone can double check this please let us know how it goes.
This has worked for me:
import from native
then
@brunolemos @drcmda @jas99 any solution??
@sebinsua Animating arrays of objects is not supported:
Animate the strings (eg:
-50%
) instead and use them like this:found a solution with interpolate, just return to whole array like so: transform: move.interpolate(m => [{ translateX: m }])
@aleclarson Thanks! This worked when I started to use
number
values.However, I have one more problem - theleave
animation is not playing (the new commit in the repository demonstrates this). I was expecting the current page to move right at the same time as the new page moves from the left as worked in the example for the web (thought opposite directions). Any ideas?position: absolute
fixed this!