Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Imperative repeated animation after "main" animation completes #185

Open
brownieboy opened this issue Apr 12, 2018 · 0 comments
Open

Imperative repeated animation after "main" animation completes #185

brownieboy opened this issue Apr 12, 2018 · 0 comments

Comments

@brownieboy
Copy link

brownieboy commented Apr 12, 2018

I have a heart icon from react-native-vector-icons. When tapped on, I want it to:

  1. Animate the fontSize from 35 to 50
  2. When the fontSize animation finishes animating, I want the heart to "pump" a few times. I'm using the built-in pulse animation for this.

I have it working, but it's a bit clunky. I'm using a fontSize transition to scale the icon up in size. Then I call the pulse 4 times in a row via Promise chain. Here's the code:

import * as Animatable from "react-native-animatable";
const AnimatableIcon = Animatable.createAnimatableComponent(Icon);  // Icon from Nativebase

// Inside the component
  handleFaveViewRef = ref => (this.faveView = ref);
  pulse = () =>
    this.faveView.()
      .then(() => this.faveView.())
      .then(() => this.faveView.())
      .then(() => this.faveView.())
      .catch(e => console.log(`error: ${e}`));

// Inside component's render():
  <AnimatableIcon
    ref={this.handleFaveViewRef}
    ios={favourite ? "ios-heart" : "ios-heart-outline"}
    android={favourite ? "md-heart" : "md-heart-outline"}
    transition="fontSize"
    onAnimationEnd={() => console.log("animation end")}
    style={{
      fontSize: favourite ? 50 : 35,
      color: favourite ? "red" : "grey"
    }}
    onPress={() => {
      if (!favourite) {
        setTimeout(() => {
          this.pulse();
        }, 700);
      }
      toggleFavouriteStatus();  // Sets favourite to true or false
    }}
  />

Two questions:

  1. Is there better way of calling the imperative pulse animation after the fontSize transition has completed, rather than relying on a setTimeout() (basically, a guess)?
  2. Is there a proper way of iterating the imperative pulse animation, rather than calling it with the long Promise chain?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant