talalmajali / react-native-countdown-component

React Native CountDown
MIT License
266 stars 233 forks source link

Component not updating #74

Open thedavidpeterson opened 4 years ago

thedavidpeterson commented 4 years ago

Hi! Thanks for a great component!

I'm having an issue with the counter showing the right value (until) after setting it on the emulator (Android Studio - Pixel XL2) but when I do the same thing after building the app (Expo, React Native) and installing it on my phone (Pixel xl2) the component does not update the displayed value after setting it. Only when the value is changed again it shows the OLD previous value (which is not right anymore).

Here's my code:

            <Timer 
                isrunning ={isRunning} 
                time={time}.      //Time is connected to the until prop in the timer
                onPress={() => this.TimePicker.open()}
                finishHandler = {onFinishHandler}
            />

        <TimePicker
            ref={ref => {
                this.TimePicker = ref;
            }}
            onCancel={onCancel}
            onConfirm={(hour, minute) => onConfirm(hour, minute)}
            maxHour = {59}
            hourUnit = {' Min'}
            maxMinute = {59}
            minuteUnit = {' Sec'}
            />

const onConfirm = (hour, minute) => { this.TimePicker.close(); setTime(parseInt(minute) + parseInt(hour)*60) }

TLDR: Component is updating in emulator but is not updating on built app (expo, react native) on phone (Google Pixel xl2)

thedavidpeterson commented 4 years ago

Solution: I went pack one version and uncommented "componentWIllReceiveProps" and commented away "componentDidUpdate".

Now it works again =)

ruslan-hontar commented 4 years ago

version 2.6.0 works fine. so problem is on update the deprecated react lifecycle.

arthedza commented 4 years ago

@talalmajali are any updates?

mukhtarkv commented 3 years ago

I had similar problem, but when running on iOS simulator. Solution: I opened index.js inside react-native-countdown-component folder and searched for "componentDidUpdate" function. Inside this function, I replaced prevState.until with 0 and replaced prevProps.until with this.props.until.

Edit: it turns out that the timer does not count down when you set prevState.until to this.state.until if previous states until is not timed out. Hence, to make the timer countdown whenever you change your state, you should make prevState.until to equal 0.

Now it behaves as I expect it to behave. Whenever I change value of until, it will update the component accordingly.

mikeportanova commented 3 years ago

@mukhtarkussaiynbekov I did this, and YES it finally updates the time correctly, but now the timer doesn't count down! Did you find a fix?

mukhtarkv commented 3 years ago

@mikeportanova The timer counts down in my application. I am attaching screen shot of my code.

Screen Shot 2021-03-18 at 09 52 55
mikeportanova commented 3 years ago

@mikeportanova The timer counts down in my application. I am attaching screen shot of my code.

Screen Shot 2021-03-18 at 09 52 55

Thanks! I had left multiple lifecycle methods uncommented.

anisurrahman072 commented 1 year ago

Hi, @thedavidpeterson, @mukhtarkussaiynbekov could you please let me know how can i achieve your solution in functional component?

mukhtarkv commented 1 year ago

Hi @anisurrahman072 I haven't coded in React Native in a while, but at that time I was only using functional component in my application. But because this package was written using class components, I had to change some parts of it to make it work. Please check my package, I haven't touched it since 2021.