React to native button blinking effect

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • lllomh
    New Member
    • Mar 2023
    • 3

    React to native button blinking effect

    Code:
    Define the method first
    
    this.state = {
    buttonBackgroundColor: 'green',
    isBlinking: false, // A new status is added to identify whether the button is blinking or not
    }
    
    
    autoStart=()=>{
    
    this.setState({ isAutoSending: true });
    let dt = setInterval(()=>{
    this.init()
    }, 5000);
    
    this.setState(
    {
    clearTime: dt,
    isBlinking: true, 
    },
    () => {
    
    this.startBlinkAnimation();
    }
    );
    
    
    }
    
    startBlinkAnimation = () => {
    if (this.state.isBlinking) {
    this.setState({ buttonBackgroundColor: 'red' });
    setTimeout(() => {
    this.setState({ buttonBackgroundColor: 'green' });
    setTimeout(this.startBlinkAnimation, 500);
    }, 500);
    }
    };
    <Button color={this.state.buttonBackgroundColor} title={'Start'} onPress={() => !this.state.isAutoSending && this.autoStart()}/>
    You can click the button to see the effect.
  • flycast
    New Member
    • Mar 2025
    • 1

    #2
    thanks for sharing the content hope this helpful i will try it.

    Comment

    Working...