I am trying to animated a circle to expand and shrink in a loop for a breathing app for people with panic attacks. I am trying to make the text change in time with the animation. breathe in state is the text variable which is shown in the circle - it can either be 'inhale', 'hold' or 'exhale'. The animation makes the circle go from 60% to fullsize in the duration of breatheTimings.in, then it should change to saying 'hold' then pause for breatheTimings.hold, then shrink back to 60% whilst saying 'exhale'.
class BreatheCircle extends React.Component {
state = {
animated:new Animated.Value(0.6),
breathe: 'Inhale',
}
componentDidMount(){
this.state.animated.setValue(0.6)
this.animateCircle();
}
componentWillUnmount(){
Animated.timing(this.state.animated).stop();
}
sleep(milliseconds) {
var start = new Date().getTime();
for (var i = 0; i < 1e7; i++) {
if ((new Date().getTime() - start) > milliseconds){
break;
}
}
}
animateCircle(){
this.setState({breathe: 'Inhale'})
Animated.timing(this.state.animated, {toValue: 1, duration:breatheTimings.in*1000}).start()
this.sleep(breatheTimings.in*1000)
this.setState({breathe: 'Hold'})
this.sleep(breatheTimings.hold*1000)
this.setState({breathe: 'Exhale'})
Animated.timing(this.state.animated, {toValue: 0.6, duration:breatheTimings.out*1000}).start()
this.sleep(breatheTimings.out*1000)
this.animateCircle()
}
This isn't working at the moment (testing it with expo) Please could someone give me advice on where to go with this. Thanks