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

Use YouTube API for videoId and playList changes #187

Merged
merged 2 commits into from
Sep 19, 2021

Conversation

hoangvvo
Copy link
Contributor

@hoangvvo hoangvvo commented Sep 10, 2021

This PR uses YouTube Iframe API for updates of the videoId and playList props.

I tested in my project using somewhat like below.

import YoutubePlayer from "react-native-youtube-iframe";

let loadCnt = 0;

export default function Test() {
  const [videoId, setVideoId] = useState("foo");

  useEffect(() => {
    console.log("videoId", videoId);
  }, [videoId]);

  return (
    <YoutubePlayer
      play
      videoId={videoId}
      webViewProps={{
        onLoad() {
          console.log(`onLoad`, ++loadCnt);
        },
      }}
      forceAndroidAutoplay
    />
  );
}

With original react-native-youtube-iframe:

 LOG  videoId 7xVUg9GmDfg
 LOG  onLoad 1
 LOG  videoId TKkcsmvYTw4
 LOG  onLoad 2
 LOG  videoId BSzSn-PRdtI
 LOG  onLoad 3

with this fork:

 LOG  onLoad 1
 LOG  videoId 7xVUg9GmDfg
 LOG  videoId TKkcsmvYTw4
 LOG  videoId BSzSn-PRdtI
 LOG  videoId 0Kx3sobEBFE
 LOG  videoId kTJczUoc26U
 LOG  videoId 0EVVKs6DQLo
Screenrecorder-2021-09-11-03-41-26-709.mp4

ref: #176 (comment)

@hoangvvo
Copy link
Contributor Author

hoangvvo commented Sep 10, 2021

I left some comments in the code but to reexplain some of the changes:

Also in the playlist change implementation, I manually do deep comparison for the sake of avoiding breaking changes because by the current doc array usage https://lonelycpp.github.io/react-native-youtube-iframe/component-props#playlist, new array identity is passed in every time causing unnecessary updates.

@hoangvvo hoangvvo changed the title Use YouTube API for videoId and playlist changes Use YouTube API for videoId and playList changes Sep 10, 2021
@hoangvvo
Copy link
Contributor Author

Also, it would be helpful to include the code used in this gif https://raw.githubusercontent.com/LonelyCpp/react-native-youtube-iframe/master/website/static/img/demo.gif inside this repo for more convenient manual testing. Thanks!

src/YoutubeIframe.js Outdated Show resolved Hide resolved
src/YoutubeIframe.js Outdated Show resolved Hide resolved
@LonelyCpp
Copy link
Owner

@hoangvvo thanks for the PR!

let me know if you can make the suggested changes.

@hoangvvo
Copy link
Contributor Author

@LonelyCpp Thanks for the review. I made the changes.

@LonelyCpp LonelyCpp merged commit f295457 into LonelyCpp:master Sep 19, 2021
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.

2 participants