How to create a glow animation with React Native

Viewed 7044

I want to create a glowing animation for my button and my image. I want to know is there a react native animation I can use to achieve this glowing effect. I have this css style, but I don't think it would work with react native. Any thoughts on how I can do this for a button or image in react-native or react.js?

.glow {
  font-size: 80px;
  color: #fff;
  text-align: center;
  -webkit-animation: glow 1s ease-in-out infinite alternate;
  -moz-animation: glow 1s ease-in-out infinite alternate;
  animation: glow 1s ease-in-out infinite alternate;
}

@-webkit-keyframes glow {
  from {
    text-shadow: 0 0 10px #fff, 0 0 20px #fff, 0 0 30px #e60073, 0 0 40px #e60073, 0 0 50px #e60073, 0 0 60px #e60073, 0 0 70px #e60073;
  }
  to {
    text-shadow: 0 0 20px #fff, 0 0 30px #ff4da6, 0 0 40px #ff4da6, 0 0 50px #ff4da6, 0 0 60px #ff4da6, 0 0 70px #ff4da6, 0 0 80px #ff4da6;
  }
}
1 Answers

I think that using keyframes in react native is not available, so I implemented my own solution:

this.state = {
      isBlinking: false
    };
this.blinkingInterval = false;

componentWillUnmount() {
    clearInterval(this.blinkingInterval);
    this.blinkingInterval = false;
  }

 componentDidMount() {
   if (!this.blinkingInterval) {
      this.blinkingInterval = setInterval(() => {
       this.setState({
          isBlinking: !this.state.isBlinking
         });
       }, 800);
    }
  }

In Render:

 <Text style={this.state.isBlinking && styles.textGlowing}>Hello World</Text>

In the css file:

textGlowing: {
    textShadowColor: 'rgba(0, 0, 0, 0.75)',
    textShadowOffset: {width: -1, height: 1},
    textShadowRadius: 15
  }
Related