0

I have a line on the middle of my screen, that works with Accelerometer and moves this top or bottom and also supposed to rotate. I am using LayoutAnimation, but seems like this method doesn't allow me to rotate my line smoothly, it goes well with 'top' property, but it's not working with rotation

I've tried to install react-native-canvas, but this package wrecks my app at all so I have to recreate it ;D (it pissed me off). Also I tried to make this animation with interpolate, but it seems like working for fixed degrees and looks weird

componentDidMount(){
    setUpdateIntervalForType(SensorTypes.accelerometer, 150);
    const subscription = accelerometer.subscribe(({ x, y, z }) =>{
        let d = getAngles(x,y,z);
        this.updateValues(d.roll,d.pitch);
      }
    );
  }

updateValues(roll,pitch){
    LayoutAnimation.configureNext(CustomLayoutAnimation)
    this.setState({roll,pitch})
  }

render() {

    return (
...
    {<View style={{position:"relative",top:calculateOffset(this.state.roll,this.state.screenOffset)+"%",width:"80%",height:4,backgroundColor:"orange",transform:[{rotate:`${this.state.pitch}deg`}]}} />}
...
);
  }

I'm on search for some working package to work with or way to solve this problem.

omni
  • 3
  • 5

2 Answers2

0

Try this:

<View
   style={{
      position:"relative",
      top: calculateOffset(this.state.roll,this.state.screenOffset)+"%",
      width: "80%",
      height: "80%",
      backgroundColor: "transparent",
      justifyContent: "center",
      transform:[{rotate:`${this.state.pitch}deg`}]}}
   }}
>
   <View
      style={{
         height: 4,
         backgroundColor: "orange",
         width: "100%"
      }}
   />
</View>

I hope it help you.

Muhammad Mehar
  • 1,015
  • 7
  • 10
0

I resolved this with interpolation and Animated API. It looks weird though, but works ;)

omni
  • 3
  • 5