2

I am trying to rotate my image when it's pressed using following:

this.myView.transitionTo({ rotate: '180deg' }, 200);

I get error:

Invariant Violation: Transform with key of "rotate" must be a string: {"rotate":null}

Using react-native-animatable library. Not sure what is the proper syntax to use for transform props.

Thanks.

Niko
  • 8,093
  • 5
  • 49
  • 85

2 Answers2

1

Try this one it works for me.

import * as Animatable from "react-native-animatable";

export default class App extends Component {
  constructor() {
    super();
    this.state = {
      back: false
    };
  }
  render() {
    return (
      <TouchableOpacity
        onPress={() => this.setState({ back: !this.state.back })}
      >
        <Animatable.Image
          source={require("./assets/images/nike.png")}
          style={{ width: 100, height: 100 }}
          animation={{
            from: {
              rotate: this.state.back ? "180deg" : "0deg"
            },
            to: {
              rotate: this.state.back ? "180deg" : "0deg"
            }
          }}
        />
      </TouchableOpacity>
    );
  }
}
Paras Korat
  • 2,011
  • 2
  • 18
  • 36
0

This works for me.

import * as Animatable from "react-native-animatable";

export default class App extends Component {
  constructor() {
    super();
    this.state = {
      back: false
    };
  }
  render() {
    return (
      <TouchableOpacity
        onPress={() => this.setState({ back: !this.state.back })}
      >
        <Animatable.Image 
            animation = {{
                from: {
                    transform: [{ rotate: this.state.back?'0deg': '45deg'}]
                },
                to: {
                    transform: [{ rotate: this.state.back?'45deg' : "deg0"}]
                }
            }}
            source={icon} style={{}}  resizeMode = {"contain"}/> 
      </TouchableOpacity>
    );
  }
}
osama somy
  • 385
  • 5
  • 16