Skip to content

Commit 1258e2d

Browse files
authored
Merge pull request #58 from LonelyCpp/docusaurus
Better documentation with Docusaurus
2 parents 56c771a + 424e4a5 commit 1258e2d

23 files changed

+10765
-508
lines changed

.npmignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
doc/*
1+
docs/*
2+
website/*

doc/readme.md

Lines changed: 0 additions & 404 deletions
This file was deleted.

docs/about.mdx

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
---
2+
id: about
3+
title: React Native Youtube-iframe
4+
---
5+
6+
import useBaseUrl from '@docusaurus/useBaseUrl';
7+
8+
![npm](https://img.shields.io/npm/v/react-native-youtube-iframe?style=for-the-badge) ![npm](https://img.shields.io/npm/dm/react-native-youtube-iframe?style=for-the-badge)
9+
10+
A wrapper of the **Youtube-iframe API** built for react native.
11+
12+
- ✅ Works seamlessly on both ios and android platforms
13+
- ✅ Does not rely on the native youtube service on android (prevents unexpected crashes, works on phones without the youtube app)
14+
- ✅ Uses the webview player which is known to be more stable compared to the native youtube app
15+
- ✅ Access to a vast API provided through the iframe youtube API
16+
- ✅ Supports multiple youtube player instances in a single page
17+
- ✅ Fetch basic video metadata without API keys (uses oEmbed)
18+
- ✅ Works on modals and overlay components
19+
- ✅ Expo support
20+
21+
<img alt="Docusaurus with Keytar" src={useBaseUrl('img/demo.gif')} />

docs/basic_usage.mdx

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
---
2+
id: basic-usage
3+
title: Basic Usage
4+
---
5+
6+
This snippet renders a Youtube video with a button that can play or pause the video. When the player has finished playing it, an alert is triggered.
7+
8+
```jsx
9+
import React, { useState, useCallback, useRef } from "react";
10+
import { Button, View, Alert } from "react-native";
11+
import YoutubePlayer from "react-native-youtube-iframe";
12+
13+
export default function App() {
14+
const [playing, setPlaying] = useState(false);
15+
16+
const onStateChange = useCallback((state) => {
17+
if (state === "ended") {
18+
setPlaying(false);
19+
Alert.alert("video has finished playing!");
20+
}
21+
}, []);
22+
23+
const togglePlaying = useCallback(() => {
24+
setPlaying((prev) => !prev);
25+
}, []);
26+
27+
return (
28+
<View>
29+
<YoutubePlayer
30+
height={300}
31+
play={playing}
32+
videoId={"iee2TATGMyI"}
33+
onChangeState={onStateChange}
34+
/>
35+
<Button title={playing ? "pause" : "play"} onPress={togglePlaying} />
36+
</View>
37+
);
38+
}
39+
```
File renamed without changes.

docs/install.mdx

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
---
2+
id: install
3+
title: Installation
4+
---
5+
6+
:::note
7+
This package uses react-hooks and therefore will need
8+
9+
**react-native 0.59 or above**
10+
(recommended - 0.60 or above)
11+
:::
12+
13+
1. First install `react-native-webview`.
14+
15+
- React Native CLI app - [Instructions](https://github.com/react-native-community/react-native-webview/blob/master/docs/Getting-Started.md)
16+
17+
- React Native **`0.60` and above**, install the latest version of react-native-webview.
18+
- React Native **below `0.60`**, react-native-webview version `6.11.1` is the last version that supports it.
19+
20+
- Expo App - [Instructions](https://docs.expo.io/versions/latest/sdk/webview/)
21+
22+
2. Run - `npm install react-native-youtube-iframe`

docs/module_methods.mdx

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
---
2+
id: module-methods
3+
title: Module Methods
4+
---
5+
6+
export const Type = ({children, color}) => (
7+
<span
8+
style={{
9+
backgroundColor: '#25c2a0',
10+
borderRadius: '20px',
11+
color: '#fff',
12+
padding: '0.2em 0.4em 0.2em 0.4em',
13+
fontSize: '0.8em',
14+
}}>
15+
{children}
16+
</span>
17+
);
18+
19+
### `getYoutubeMeta`
20+
21+
<Type>getYoutubeMeta(videoId: String): Promise[youtubeMeta]</Type>
22+
23+
Fetch metadata of a youtube video using the oEmbed Spec - https://oembed.com/#section7
24+
25+
metadata returned -
26+
27+
| field | type | explanation |
28+
| ---------------- | ------ | -------------------------------------------------- |
29+
| author_name | String | The name of the author/owner of the video. |
30+
| author_url | String | youtube channel link of the video. |
31+
| height | Number | The height in pixels required to display the HTML. |
32+
| html | String | The HTML required to embed a video player. |
33+
| provider_name | String | The name of the resource provider. |
34+
| provider_url | String | The url of the resource provider. |
35+
| thumbnail_height | Number | The height of the video thumbnail. |
36+
| thumbnail_url | String | The url of the resource provider. |
37+
| thumbnail_width | Number | The width of the video thumbnail. |
38+
| title | String | youtube video title. |
39+
| type | String | The oEmbed version number. |
40+
| version | String | The resource type. |
41+
| width | Number | The width in pixels required to display the HTML. |
42+
43+
example -
44+
45+
```javascript
46+
import {Alert} from 'react-native';
47+
import {getYoutubeMeta} from 'react-native-youtube-iframe';
48+
49+
getYoutubeMeta('sNhhvQGsMEc').then(meta => {
50+
Alert.alert('title of the video : ' + meta.title);
51+
});
52+
```

0 commit comments

Comments
 (0)