React Native transforms with pivot point

后端 未结 5 729
不思量自难忘°
不思量自难忘° 2021-01-02 03:02

I want to rotate a Text component with an angle of -90deg. The component should be rotated from the left corner instead of middle. I am using below

5条回答
  •  独厮守ぢ
    2021-01-02 03:26

    This issue on GitHub has a solution.

    If you're able to use an SVG, in your render method, you can do something like this:

    const pointX = 25;
    const pointY = 25;
    
      {/* Rotate about point x y */}
      
        {/* Everything in AnimatedG gets rotated */}
        
          
            
          
        
      
    
    

    The this.state.offset is a hack for android which behaves differently. The onlayout to set that value looks like this.

    onLayout = Platform.OS === 'android'
        ? e => { this.setState({ offset: e.nativeEvent.layout.width / 2 }) }
        : null;
    

    Note: using 25 as my x and y would rotate about the center.

    The user who posted the solution included this fully-functional example

提交回复
热议问题