React-native-animatable: How can I initialize render without animation starts

Created on 21 Jun 2017  路  2Comments  路  Source: oblador/react-native-animatable

Hi!
I have a doubt, is there a way to initialize my render method without start the animation? In my case, i have a menu icon inside a toolbar. This icon should rotate only the user touches it, But when this screen's rendered the icon rotate. How can i rotate the menu icon only the user interact with it? I Know about startAnimation() and stopAnimation() methods and i tried put the animation in state, but without success yet.

My App is for both platforms - Android and IOs
Thanks! and pardon about my bad English.

Most helpful comment

Define your Animatable without the duration and animation props (you can still use others like easing), set a reference to it and trigger the animation programmatically with the animation and duration of your choice.

Example:

render() {
  return (
    <TouchableWithoutFeedback onPress={() => this.onPress()}>
      <Animatable.View ref={ref => { this.animatable = ref }}>
        <YourComponentHere />
      </Animatable.View>
    </TouchableWithoutFeedback>
  );
}

Then in onPress():

onPress() {
  this.animatable.rotate(800);
}

All 2 comments

I'm in the same boat here, also looking for a good way to execute animation on a component (that might use 'ref' , the refs things in React)

Define your Animatable without the duration and animation props (you can still use others like easing), set a reference to it and trigger the animation programmatically with the animation and duration of your choice.

Example:

render() {
  return (
    <TouchableWithoutFeedback onPress={() => this.onPress()}>
      <Animatable.View ref={ref => { this.animatable = ref }}>
        <YourComponentHere />
      </Animatable.View>
    </TouchableWithoutFeedback>
  );
}

Then in onPress():

onPress() {
  this.animatable.rotate(800);
}
Was this page helpful?
0 / 5 - 0 ratings

Related issues

dantman picture dantman  路  3Comments

Aspirationtocode picture Aspirationtocode  路  7Comments

matheuscastroweb picture matheuscastroweb  路  6Comments

zr0n picture zr0n  路  6Comments

ssomnoremac picture ssomnoremac  路  5Comments