Last active
May 30, 2023 12:14
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)} | |
/> | |
</> | |
); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.