Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(hooks): useProgress & usePlayback hooks #1723

Merged
merged 2 commits into from
Sep 14, 2022

Conversation

puckey
Copy link
Collaborator

@puckey puckey commented Sep 13, 2022

  • (breaking) fix: usePlaybackState was incorrectly returning State.None by default. Now it returns undefined while it is waiting on the async call to TrackPlayer to resolve. This also fixes the following issue where duration was incorrectly being reported as 0: Duration value is always '0' in useProgress hooks  #1709
  • optimization: avoid unnecessarily reevaluating the useEffect on every player state change by moving the playerState === State.None outside of the effect and including it as a dependency instead

@puckey puckey requested a review from dcvz as a code owner September 13, 2022 09:26
@jspizziri jspizziri changed the title Fix useProgress & usePlayback hooks fix(hooks): useProgress & usePlayback hooks Sep 14, 2022
@jspizziri
Copy link
Collaborator

jspizziri commented Sep 14, 2022

@puckey is there a way of accomplishing this that doesn't introduce a breaking change?

@@ -131,7 +131,7 @@ export function useProgress(updateInterval = 1000) {
return () => {
mounted = false;
};
}, [playerState, updateInterval]);
}, [isNone, updateInterval]);

return state;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@puckey would doing a:

return state || State.None;

Allow us to avoid the breaking change here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not in this way, but there is slightly more convoluted way to fix this.. Will take a look at it later

Copy link
Collaborator

@jspizziri jspizziri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@puckey please see the comment I left. I'd like to find a way to do this without a breaking change. As we'd need to hold off until the next major version if not.

@gavrichards
Copy link
Contributor

I'm keen to see this fixed asap, so I'll share that @puckey and I were discussing this in the discord yesterday, and the initial fix proposed which worked without any breaking changes is mentioned here:
https://discord.com/channels/567636850513018880/600714011318681610/1019166051461779467

- (breaking) fix: usePlaybackState was incorrectly returning State.None by default. Now it returns undefined while it is waiting on the async call to TrackPlayer to resolve. This also fixes the following issue where duration was incorrectly being reported as `0`: doublesymmetry#1709
- optimization: avoid unnecessarily reevaluating the useEffect on every player state change by moving the `playerState === State.None` outside of the effect and including it as a dependency instead
@puckey
Copy link
Collaborator Author

puckey commented Sep 14, 2022

How about something like this @jspizziri: b895b9c

Copy link
Collaborator

@jspizziri jspizziri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@dcvz do you want to do a final approval on this one?

@jspizziri jspizziri merged commit 31fa40a into doublesymmetry:main Sep 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants