Skip to content

Instantly share code, notes, and snippets.

@jamonholmgren
Last active May 30, 2023 12:14
Show Gist options
  • Save jamonholmgren/f300be30399829f38d96ad5d05e5aaa6 to your computer and use it in GitHub Desktop.
Save jamonholmgren/f300be30399829f38d96ad5d05e5aaa6 to your computer and use it in GitHub Desktop.
Example of detecting when a YouTube video goes full screen or ends full screen in React Native WebView.
const App = () => {
return (
<>
<WebView
injectedJavaScript={`
(function() {
setTimeout(() => {
const video = document.getElementsByClassName("html5-main-video")[0]
video.addEventListener('webkitbeginfullscreen', (event) => {
window.ReactNativeWebView.postMessage("Full Screen");
})
video.addEventListener('webkitendfullscreen', (event) => {
window.ReactNativeWebView.postMessage("End Full Screen");
})
}, 1000)
})();
true
`}
source={{uri: 'https://www.youtube.com/watch?v=MaahnH3ItKU'}}
onMessage={m => console.log(m.nativeEvent.data)}
/>
</>
);
};
@minhnbwork97
Copy link

Hi.
I have 1 question. How do you manage to find the video class name ("html5-main-video" in this case)?
I'm trying to detect when a Vimeo video goes fullscreen, I'm thinking of doing the same way you're doing here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment