Skip to content

Commit 62e277d

Browse files
authored
Merge pull request #54 from JonEsparaz/master
Add ref prop to type declarations
2 parents b3bd90a + 1b80436 commit 62e277d

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

doc/readme.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,25 @@ const App = () => {
9898
};
9999
```
100100

101+
Typescript usage.
102+
103+
```typescript
104+
import React, {useRef} from 'react';
105+
import { YoutubeIframeRef } from 'react-native-youtube-iframe';
106+
const App = () => {
107+
const playerRef = useRef<YoutubeIframeRef>(null);
108+
return (
109+
<YoutubePlayer height={400} width={400} ref={playerRef} videoId={'AVAc1gYLZK0'} />
110+
<Button
111+
title="get current player time"
112+
onPress={() => {
113+
playerRef?.current?.getCurrentTime().then(data => console.log({data}));
114+
}}
115+
/>
116+
);
117+
};
118+
```
119+
101120
## videoId
102121

103122
**_String_**

index.d.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,16 @@ import React from 'react';
22
import {StyleProp, ViewStyle} from 'react-native';
33
import {WebViewProps} from 'react-native-webview';
44

5+
export interface YoutubeIframeRef {
6+
getDuration: () => Promise<number>;
7+
getCurrentTime: () => Promise<number>;
8+
isMuted: () => Promise<boolean>;
9+
getVolume: () => Promise<number>;
10+
getPlaybackRate: () => Promise<number>;
11+
getAvailablePlaybackRates: () => Promise<number[]>;
12+
seekTo: (seconds: number, allowSeekAhead: boolean) => void;
13+
}
14+
515
export interface InitialPlayerParams {
616
loop?: boolean;
717
controls?: boolean;
@@ -104,6 +114,10 @@ export interface YoutubeIframeProps {
104114
* Flag to decide whether or not a user can zoom the video webview.
105115
*/
106116
allowWebViewZoom?: Boolean;
117+
/**
118+
* Set this React Ref to use ref functions such as getDuration.
119+
*/
120+
ref?: React.MutableRefObject<YoutubeIframeRef | null>;
107121
}
108122

109123
declare const YoutubeIframe: React.SFC<YoutubeIframeProps>;

0 commit comments

Comments
 (0)