Open rubek-joshi opened 4 years ago
me too :(
@rubek-joshi @QuangChien-NTQ-NS6 can you console log what are the props in componentWillReceiveProps? in the node_modules/react-native-countdown-component/index.js
try change updateTimer on node_modules/react-native-countdown-component/index.js with this... updateTimer = () => { // Don't fetch these values here, because their value might be changed // in another thread // const {lastUntil, until} = this.state;
if (this.state.until === 1 || (this.state.until === 0 && this.state.lastUntil !== 1)) {
if (this.state.lastUntil === this.state.until || !this.props.running) {
return;
}
if (this.props.onFinish) {
this.props.onFinish();
}
if (this.props.onChange) {
this.props.onChange(this.state.until);
}
}
if (this.state.until === 0) {
this.setState({lastUntil: 0, until: 0});
} else {
if (this.props.onChange) {
this.props.onChange(this.state.until);
}
this.setState({
lastUntil: this.state.until,
until: Math.max(0, this.state.until - 1)
});
}
if (this.state.lastUntil === this.state.until || !this.props.running) {
return;
}
};
@rubek-joshi I found how to reset the counter, Replace "++this.state.id" to "Math.random()".
Math.random() worked for me, hope that works for you!!
@rubek-jhoshi Hi, I am also facing the same issue but now it's resolved. See the below code:
const OTPScreen = (props) => { const [count, setCount] = useState(60*5);
const generateOTP = async () => { setCount(60*5); } useEffect(() => { //////////optional generateOTP(); })
return <View style={{ flex: 1 }}> <TouchableOpacity style={styles.label2}
<CountDown
style={styles.timestyle}
until={count}
size={15}
onFinish={finishCount}
digitStyle={{backgroundColor: '#FFF'}}
digitTxtStyle={{color: '#1ABC9D'}}
timeToShow={['M', 'S']}
showSeparator={true}
timeLabels={{m: null, s: null}}
/>
}
const styles = StyleSheet.create({
//////style code
}
``
To reset time with new time just hide component and show after new time set Eg. if (isTimeExtended && secondCounter > 0) { setCountdownVisible(false); setCounter(secondCounter + userQuizData.setting.extend_time); setTimeout(() => { setCountdownVisible(true); }) setTimeExtend(false); }
{countdownVisible ? ( <CountDown until={counter} onFinish={() => setModalVisible(true)} onChange={(seconds) => { setSecondCounter(seconds) }} size={16} timeToShow={['S']} digitStyle={{backgroundColor: '#FFF'}} timeLabels={{s: null}} /> ):(
)}
I think there should be an example of resetting the timer on state or props change because I am trying and it's just not working at the moment. My code is as follows: State:
Render method:
componentDidMount:
_someAxiosRequest: