Trying to make Box move up and down on the Y coordinate utilizing react-vr Box and Animated components.
Currently, I'm getting a
Cannot add property _tracking, object is not extensible
error.
Code below:
Component "Cube" using Animated.createAnimatedComponent(Box);
import React from 'react';
import {
Box,
Animated,
} from 'react-vr';
const AnimatedBox = Animated.createAnimatedComponent(Box);
class Cube extends React.Component {
constructor (props) {
super (props);
this.state = {
y: new Animated.Value(0)
}
this.animate = this.animate.bind(this);
}
componentDidMount () {
this.animate();
}
animate () {
Animated.sequence([
Animated.timing(
this.state.y,
{
toValue: 3,
duration: 200
}
),
Animated.timing(
this.state.y,
{
toValue: 0,
duration: 200,
}
)
]).start();
}
render() {
const { width, height, depth, x, y, z } = this.props.cube;
return (
<AnimatedBox
dimWidth={width}
dimDepth={depth}
dimHeight={height}
style={{
transform: [{translate: [x, this.state.y, z]}],
color: 'white'
}}
/>)
}
}
export default Cube;
index.vr.js render method passing in cube props to Cube Component:
render() {
const cube = {
width: 1,
height: 1,
depth: 1,
x: 0,
y: 0,
z: -5
};
return (
<View>
<Pano source={asset('chess-world.jpg')}/>
<View>
<Cube cube={{...cube}} />);
</View>
</View>
)
}
};
Thank you for your help!