Skip to content

Commit 1481d85

Browse files
committed
docs: update documentation and add FAQs in website
1 parent f126b6f commit 1481d85

File tree

9 files changed

+142
-13
lines changed

9 files changed

+142
-13
lines changed

docs/about.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
---
22
id: about
33
title: React Native Youtube-iframe
4+
slug: /
45
---
56

67
import useBaseUrl from '@docusaurus/useBaseUrl';

docs/faq.mdx

Whitespace-only changes.

docs/play-store-compatibility.mdx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
id: play-store-compatibility
3+
title: Google Play Store
4+
---
5+
6+
Google is very strict about apps on the play store that have youtube content on it. It absolutely does not allow background play in any form. Make sure that your app complies with [youtube's terms of service](https://developers.google.com/youtube/terms/api-services-terms-of-service).
7+
8+
A few users have faced app rejections and the best way to avoid any issues is to make sure that the video stops when your app. ([#72](https://github.com/LonelyCpp/react-native-youtube-iframe/issues/72), [#105](https://github.com/LonelyCpp/react-native-youtube-iframe/issues/105)).
9+
10+
- goes to the background
11+
- the video is no longer on the screen
12+
13+
Use the [AppState](https://reactnative.dev/docs/appstate) api to stop the video when the app is not "active" and use navigational hooks to stop the video when a user navigates away from the screen.

docs/props.mdx

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,24 @@ Gives access to the player reference. This can be used to access player function
118118

119119
---
120120

121+
### `baseUrlOverride`
122+
123+
<Type>String</Type>
124+
125+
A link that serves the iframe code. If you want to host the code on your own domain, get the source from [here](https://github.com/LonelyCpp/react-native-youtube-iframe/blob/master/iframe.html).
126+
127+
Default link - https://lonelycpp.github.io/react-native-youtube-iframe/iframe.html
128+
129+
---
130+
131+
### `useLocalHTML`
132+
133+
<Type>Boolean</Type>
134+
135+
use locally generated html to render on the webview
136+
137+
---
138+
121139
### `onChangeState`
122140

123141
<Type>function(event: string)</Type>
@@ -296,13 +314,3 @@ scale factor for initial-scale and maximum-scale in `<meta />` tag on the webpag
296314
:::info zoom -
297315
enabling the `allowWebViewZoom` disabled the maximum-scale attribute in the webpage
298316
:::
299-
300-
---
301-
302-
### `baseUrlOverride`
303-
304-
<Type>String</Type>
305-
306-
A link that serves the iframe code. If you want to host the code on your own domain, get the source from [here](https://github.com/LonelyCpp/react-native-youtube-iframe/blob/master/iframe.html).
307-
308-
Default link - https://lonelycpp.github.io/react-native-youtube-iframe/iframe.html

docs/remove-context-share.mdx

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
---
2+
id: remove-context-share
3+
title: Remove Context Menu
4+
---
5+
6+
---
7+
8+
### Removing context menu on long-press:
9+
10+
Use react-native's [Pressable API](https://reactnative.dev/docs/pressable) or any of the touchables to intercept long presses.
11+
12+
example : (by [@vijay122](https://github.com/LonelyCpp/react-native-youtube-iframe/pull/111/files))
13+
14+
```jsx
15+
<Pressable
16+
onLongPress={() => {
17+
// handle or ignore
18+
}}>
19+
<YoutubePlayer (...) />
20+
</Pressable>
21+
```
22+
23+
### Removing context menu on kebab menu (prevent share):
24+
25+
It is not possible to change to UI of the player. You can however achieve this by placing an absolutely positioned view on the player (either fully covering the player or just tall enough to cover the title) to prevent the webview from receiving user touches. This will not remove the logo or three dots, but will make it un-interactable.
26+
27+
example:
28+
29+
```jsx
30+
<View>
31+
<YoutubePlayer height={300} videoId={'XSqi5s3rfqk'} />
32+
<TouchableOpacity
33+
// TouchableOpacity to "steal" taps
34+
// absolutely positioned to the top
35+
// height must be adjusted to
36+
// just cover the top 3 dots
37+
style={{
38+
top: 0,
39+
height: 50,
40+
width: '100%',
41+
position: 'absolute',
42+
}}
43+
/>
44+
</View>
45+
```

docs/show-elapsed-time.mdx

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
---
2+
id: elapsed-time
3+
title: Show elapsed time
4+
---
5+
6+
The player provides a way to fetch current time. Combining this with `setInterval` is the right way to go, since you can control the accuracy and frequency of the reading.
7+
8+
example:
9+
10+
```javascript
11+
import React, {useState, useRef, useEffect} from 'react';
12+
import {Text, View} from 'react-native';
13+
import YoutubePlayer from 'react-native-youtube-iframe';
14+
15+
const App = () => {
16+
const [elapsed, setElapsed] = useState(0);
17+
const playerRef = useRef();
18+
19+
useEffect(() => {
20+
const interval = setInterval(async () => {
21+
const elapsed_sec = await playerRef.current.getCurrentTime(); // this is a promise. dont forget to await
22+
23+
// calculations
24+
const elapsed_ms = Math.floor(elapsed_sec * 1000);
25+
const ms = elapsed_ms % 1000;
26+
const min = Math.floor(elapsed_ms / 60000);
27+
const seconds = Math.floor((elapsed_ms - min * 60000) / 1000);
28+
29+
setElapsed(
30+
min.toString().padStart(2, '0') +
31+
':' +
32+
seconds.toString().padStart(2, '0') +
33+
':' +
34+
ms.toString().padStart(3, '0'),
35+
);
36+
}, 100); // 100 ms refresh. increase it if you don't require millisecond precision
37+
38+
return () => {
39+
clearInterval(interval);
40+
};
41+
}, []);
42+
43+
return (
44+
<>
45+
<YoutubePlayer
46+
height={250}
47+
ref={playerRef}
48+
videoId={'DC471a9qrU4'}
49+
/>
50+
<View>
51+
<View style={{flexDirection: 'row'}}>
52+
<Text style={{flex: 1}}>{'elapsed time'}</Text>
53+
<Text style={{flex: 1, color: 'green'}}>{elapsed}</Text>
54+
</View>
55+
</>
56+
);
57+
};
58+
```

website/docusaurus.config.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ module.exports = {
99
organizationName: 'LonelyCpp',
1010
projectName: 'react-native-youtube-iframe',
1111
themeConfig: {
12+
sidebarCollapsible: false,
13+
colorMode: {
14+
defaultMode: 'dark',
15+
},
1216
navbar: {
1317
title: 'React Native Youtube-iframe',
1418
logo: {
@@ -34,7 +38,6 @@ module.exports = {
3438
docs: {
3539
path: '../docs',
3640
routeBasePath: '/',
37-
homePageId: 'about',
3841
sidebarPath: require.resolve('./sidebars.js'),
3942
},
4043
theme: {

website/sidebars.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
module.exports = {
2-
someSidebar: {
2+
sideBar: {
33
About: ['about', 'install', 'basic-usage'],
44
Documentation: [
55
'component-props',
66
'component-ref-methods',
77
'module-methods',
88
],
9+
FAQ: ['play-store-compatibility', 'remove-context-share', 'elapsed-time'],
910
},
1011
};

website/static/iframe.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<!doctypehtml><meta name="viewport"content="width=device-width,maximum-scale=1"><style>body{margin:0}.container{position:relative;width:100%;height:0;padding-bottom:56.25%}.video{position:absolute;top:0;left:0;width:100%;height:100%}</style><div class="container"><div class="video"id="player"></div></div><script>const parsedUrl=new URL(window.location.href),UrlQueryData=parsedUrl.searchParams.get("data"),{end:end,list:list,color:color,start:start,rel_s:rel_s,loop_s:loop_s,listType:listType,playerLang:playerLang,playlist:playlist,videoId_s:videoId_s,controls_s:controls_s,cc_lang_pref_s:cc_lang_pref_s,contentScale_s:contentScale_s,modestbranding_s:modestbranding_s,iv_load_policy:iv_load_policy,preventFullScreen_s:preventFullScreen_s,showClosedCaptions_s:showClosedCaptions_s}=JSON.parse(UrlQueryData);function sendMessageToRN(e){window.ReactNativeWebView.postMessage(JSON.stringify(e))}var tag=document.createElement("script");tag.src="https://www.youtube.com/iframe_api";var player,firstScriptTag=document.getElementsByTagName("script")[0];function onYouTubeIframeAPIReady(){player=new YT.Player("player",{width:"1000",height:"1000",videoId:videoId_s,playerVars:{end:end,rel:rel_s,list:list,color:color,loop:loop_s,start:start,playsinline:1,hl:playerLang,playlist:playlist,listType:listType,controls:controls_s,fs:preventFullScreen_s,cc_lang_pref:cc_lang_pref_s,iv_load_policy:iv_load_policy,modestbranding:modestbranding_s,cc_load_policy:showClosedCaptions_s},events:{onReady:onPlayerReady,onError:onPlayerError,onStateChange:onPlayerStateChange,onPlaybackRateChange:onPlaybackRateChange,onPlaybackQualityChange:onPlaybackQualityChange}})}function onPlayerError(e){sendMessageToRN({eventType:"playerError",data:e.data})}function onPlaybackRateChange(e){sendMessageToRN({eventType:"playbackRateChange",data:e.data})}function onPlaybackQualityChange(e){sendMessageToRN({eventType:"playerQualityChange",data:e.data})}function onPlayerReady(e){sendMessageToRN({eventType:"playerReady"})}function onPlayerStateChange(e){sendMessageToRN({eventType:"playerStateChange",data:e.data})}firstScriptTag.parentNode.insertBefore(tag,firstScriptTag);var isFullScreen=!1;function onFullScreenChange(){isFullScreen=document.fullscreenElement||document.msFullscreenElement||document.mozFullScreenElement||document.webkitFullscreenElement,sendMessageToRN({eventType:"fullScreenChange",data:Boolean(isFullScreen)})}document.addEventListener("fullscreenchange",onFullScreenChange),document.addEventListener("msfullscreenchange",onFullScreenChange),document.addEventListener("mozfullscreenchange",onFullScreenChange),document.addEventListener("webkitfullscreenchange",onFullScreenChange)</script>
1+
<!doctypehtml><meta name="viewport"content="width=device-width,"><style>body{margin:0}.container{position:relative;width:100%;height:0;padding-bottom:56.25%}.video{position:absolute;top:0;left:0;width:100%;height:100%}</style><div class="container"><div class="video"id="player"></div></div><script>const parsedUrl=new URL(window.location.href),UrlQueryData=parsedUrl.searchParams.get("data"),{end:end,list:list,color:color,start:start,rel_s:rel_s,loop_s:loop_s,listType:listType,playerLang:playerLang,playlist:playlist,videoId_s:videoId_s,controls_s:controls_s,cc_lang_pref_s:cc_lang_pref_s,contentScale_s:contentScale_s,allowWebViewZoom:allowWebViewZoom,modestbranding_s:modestbranding_s,iv_load_policy:iv_load_policy,preventFullScreen_s:preventFullScreen_s,showClosedCaptions_s:showClosedCaptions_s}=JSON.parse(UrlQueryData);function sendMessageToRN(e){window.ReactNativeWebView.postMessage(JSON.stringify(e))}let metaString="";contentScale_s&&(metaString+=`initial-scale=${contentScale_s}`),allowWebViewZoom||(metaString+=`maximum-scale=${contentScale_s}`);const viewport=document.querySelector("meta[name=viewport]");viewport.setAttribute("content","width=device-width,"+metaString);var tag=document.createElement("script");tag.src="https://www.youtube.com/iframe_api";var player,firstScriptTag=document.getElementsByTagName("script")[0];function onYouTubeIframeAPIReady(){player=new YT.Player("player",{width:"1000",height:"1000",videoId:videoId_s,playerVars:{end:end,rel:rel_s,list:list,color:color,loop:loop_s,start:start,playsinline:1,hl:playerLang,playlist:playlist,listType:listType,controls:controls_s,fs:preventFullScreen_s,cc_lang_pref:cc_lang_pref_s,iv_load_policy:iv_load_policy,modestbranding:modestbranding_s,cc_load_policy:showClosedCaptions_s},events:{onReady:onPlayerReady,onError:onPlayerError,onStateChange:onPlayerStateChange,onPlaybackRateChange:onPlaybackRateChange,onPlaybackQualityChange:onPlaybackQualityChange}})}function onPlayerError(e){sendMessageToRN({eventType:"playerError",data:e.data})}function onPlaybackRateChange(e){sendMessageToRN({eventType:"playbackRateChange",data:e.data})}function onPlaybackQualityChange(e){sendMessageToRN({eventType:"playerQualityChange",data:e.data})}function onPlayerReady(e){sendMessageToRN({eventType:"playerReady"})}function onPlayerStateChange(e){sendMessageToRN({eventType:"playerStateChange",data:e.data})}firstScriptTag.parentNode.insertBefore(tag,firstScriptTag);var isFullScreen=!1;function onFullScreenChange(){isFullScreen=document.fullscreenElement||document.msFullscreenElement||document.mozFullScreenElement||document.webkitFullscreenElement,sendMessageToRN({eventType:"fullScreenChange",data:Boolean(isFullScreen)})}document.addEventListener("fullscreenchange",onFullScreenChange),document.addEventListener("msfullscreenchange",onFullScreenChange),document.addEventListener("mozfullscreenchange",onFullScreenChange),document.addEventListener("webkitfullscreenchange",onFullScreenChange)</script>

0 commit comments

Comments
 (0)