I've written a progress bar code (in android and IOS) via functional component, There are three buttons, one of them starts progress bar, another one-stop it and the last button restarts it. Stop button doesn't work, It seems clearInterval doesn't work, Can you please take a look and help me to solve this problem?
const MainFunc = (props) => {
let [ProgresValue, setProgresValue] = useState(0);
let IntValue = '';
const StartProgress = () => {
IntValue = setInterval(() => {
if (ProgresValue <= 1) {
setProgresValue(ProgresValue = ProgresValue + 0.01)
}
}, 100);
}
const StopProgress = () => {
clearInterval(IntValue)
}
const RestartProgress = () => {
setProgresValue(ProgresValue = 0)
}
return (
<Fragment>
<Text>Progress Bar:{parseFloat((ProgresValue * 100).toFixed(3))}%</Text>
{
(Platform.OS === 'android')
?
(<ProgressBarAndroid
styleAttr='Horizontal'
indeterminate={false}
progress={ProgresValue}
/>)
:
(<ProgressViewIOS
progress={ProgresValue}
/>)
}
<TouchableHighlight onPress={StartProgress} style={styles.button}><Text style={{ color: 'white', textAlign: 'center' }}>Start Prgress</Text></TouchableHighlight>
<TouchableHighlight onPress={StopProgress} style={styles.button} ><Text style={{ color: 'white', textAlign: 'center' }} >Stop Progress</Text></TouchableHighlight>
<TouchableHighlight onPress={RestartProgress} style={styles.button}><Text style={{ color: 'white', textAlign: 'center' }} >Restart Progress</Text></TouchableHighlight>
</Fragment>
)
}