Translate animation
See original GitHub issueI have drawn two rects and use rotateX:70deg to make them look three-dimentional, like the picture below.
Now I want to animate the rects and make them move vertically.
Here is the question, since there is no translateZ for Svg, if I use {translate:[0, 0, this.state.zAnim]}
in Svg
, it cames out an error Attempted to assign to readonly property
.
Else if I wrapped each rect within a View component and use the translateY
in View
, the rect behind and be partially overlapped won’t respond the onPress event.
Here is my code.
export default class App extends Component {
constructor(){
super();
this.state = {
currentAlpha: 1.0,
zAnim: new Animated.Value(-300),
}
}
moveV = ()=>{
Animated.timing(this.state.zAnim, {
toValue: 0,
}).start();
};
render() {
return (
<View style={styles.container}>
//<View style={{transform:[{translateY: this.state.fadeAnim}]}}>
<AnimateSvg style = {{transform: [{rotateX: '70deg'},{rotateZ:'-45deg'},{translate:[0, 0, this.state.zAnim]}]}} width="400" height="400">
<G onPressIn={() => this.moveV()}>
<Rect
x="5%"
y="5%"
width="90%"
height="90%"
fill="rgb(0,0,255)"
strokeWidth="3"
stroke="rgb(0,0,0)"
/>
</G>
</AnimateSvg>
//</View>
<Svg style = {{transform: [{rotateX: '70deg'},{rotateZ:'-45deg'},{translate:[0, 0, 200]}]}} width="400" height="400">
<G onPressIn={() => alert(1)}>
<Rect
x="5%"
y="5%"
width="90%"
height="90%"
fill="rgb(0,255,255)"
strokeWidth="3"
stroke="rgb(0,0,0)"
/>
</G>
</Svg>
</View>
);
}
}
Issue Analytics
- State:
- Created 6 years ago
- Comments:10 (1 by maintainers)
Top Results From Across the Web
TranslateAnimation - Android Developers
Constructor used when a TranslateAnimation is loaded from a resource. ... Constructor to use when building a TranslateAnimation from code.
Read more >translate animation - android - Stack Overflow
Translate Animation can change the visual appearance of an object, but they cannot change the objects themselves. That is, if you apply a...
Read more >translate() - CSS: Cascading Style Sheets - MDN Web Docs
The translate() CSS function repositions an element in the horizontal and/or vertical directions. Its result is a data type.
Read more >Animation Using CSS Transforms - The Art of Web
How to scale, rotate, translate and transform elements using new CSS hover effects that work now in Safari, Webkit and Chrome.
Read more >Translate "animation" from French to English - Interglot Mobile
French to English translation results for 'animation' designed for tablets and mobile devices. Possible languages include English, Dutch, German, French, ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@NinjaXY Here is an example of animating 2.5d(getting quite different results on android and ios, but something to start working/investigating from at least) and correct press handlers:
Actually, for 3d content and transforms, opengl will be a much better match. https://www.npmjs.com/package/react-native-gl-model-view https://github.com/gre/gl-react-native-v2 Or, if you only need to rotate rectangles, then you can just use plain react-native views with a background color and the normal 3d transforms.