Skip to content

Commit 1e0d48a

Browse files
authored
Bugfix/crash app (#2)
* fixes * include react-dom * remove peer dependencies * wip * path resolver * add resolutions * test
1 parent 19e52a1 commit 1e0d48a

File tree

3 files changed

+40
-44
lines changed

3 files changed

+40
-44
lines changed

package.json

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-native-vimeo-iframe",
3-
"version": "1.0.0",
3+
"version": "1.0.1",
44
"description": "",
55
"homepage": "https://github.com/MetaLabs-inc/react-native-vimeo-iframe#readme",
66
"main": "src/index.tsx",
@@ -16,11 +16,6 @@
1616
"prepare": "yarn compile",
1717
"test": "jest"
1818
},
19-
"dependencies": {
20-
"react": "^17.0.1",
21-
"react-native": "^0.63.4",
22-
"react-native-webview": "11.2.3"
23-
},
2419
"devDependencies": {
2520
"@babel/core": "^7.12.10",
2621
"@babel/runtime": "^7.12.5",
@@ -39,8 +34,8 @@
3934
"typescript": "^4.1.3"
4035
},
4136
"peerDependencies": {
42-
"react": "*",
43-
"react-native": "*"
37+
"react-native": "^0.63.4",
38+
"react-native-webview": "11.2.3"
4439
},
4540
"jest": {
4641
"preset": "react-native",

src/index.tsx

Lines changed: 35 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
import React, {useCallback, useEffect, useState} from 'react';
2-
import {TouchableWithoutFeedback} from 'react-native';
3-
import {WebView} from 'react-native-webview';
4-
import webplayer from './template';
5-
import {LayoutProps} from './types';
1+
import React from 'react'
2+
import { TouchableWithoutFeedback } from 'react-native'
3+
import { WebView } from 'react-native-webview'
4+
5+
import webplayer from './template'
6+
import { LayoutProps } from './types'
67

78
export const Vimeo: React.FC<LayoutProps> = ({
89
videoId,
@@ -18,49 +19,49 @@ export const Vimeo: React.FC<LayoutProps> = ({
1819
speed = false,
1920
style,
2021
}) => {
21-
const [isReady, setReady] = useState<boolean>();
22+
const [isReady, setReady] = React.useState<boolean>()
2223

23-
const [autoPlayValue, setAutoPlay] = useState<boolean>(autoPlay);
24-
const toggleAutoPlay = useCallback(() => setAutoPlay(!autoPlayValue), [
24+
const [autoPlayValue, setAutoPlay] = React.useState<boolean>(autoPlay)
25+
const toggleAutoPlay = React.useCallback(() => setAutoPlay(!autoPlayValue), [
2526
autoPlayValue,
26-
]);
27+
])
2728

28-
const handlers: any = {};
29+
const handlers: any = {}
2930
const registerHandlers = () => {
30-
registerBridgeEventHandler('ready', onReady ?? onReadyDefault);
31-
registerBridgeEventHandler('play', onPlay);
32-
registerBridgeEventHandler('playProgress', onPlayProgress);
33-
registerBridgeEventHandler('pause', onPause);
34-
registerBridgeEventHandler('finish', onFinish);
35-
};
31+
registerBridgeEventHandler('ready', onReady ?? onReadyDefault)
32+
registerBridgeEventHandler('play', onPlay)
33+
registerBridgeEventHandler('playProgress', onPlayProgress)
34+
registerBridgeEventHandler('pause', onPause)
35+
registerBridgeEventHandler('finish', onFinish)
36+
}
3637

3738
const registerBridgeEventHandler = (eventName: string, handler: any) => {
38-
handlers[eventName] = handler;
39-
};
39+
handlers[eventName] = handler
40+
}
4041

41-
useEffect(() => {
42-
registerHandlers();
43-
}, [videoId, scalesPageToFit]);
42+
React.useEffect(() => {
43+
registerHandlers()
44+
}, [videoId, scalesPageToFit])
4445

4546
const onBridgeMessage = (event: any) => {
46-
const message = event.nativeEvent.data;
47-
let payload;
47+
const message = event.nativeEvent.data
48+
let payload
4849
try {
49-
payload = JSON.parse(message);
50+
payload = JSON.parse(message)
5051
if (payload?.name === 'finish') {
51-
toggleAutoPlay();
52+
toggleAutoPlay()
5253
}
5354
} catch (err) {
54-
return;
55+
return
5556
}
56-
let handler = handlers[payload.name];
57-
if (handler) handler(payload.data);
58-
};
57+
let handler = handlers[payload.name]
58+
if (handler) handler(payload.data)
59+
}
5960

6061
const onReadyDefault = () => {
61-
setReady(true);
62-
if (onReady) setTimeout(onReady);
63-
};
62+
setReady(true)
63+
if (onReady) setTimeout(onReady)
64+
}
6465

6566
return (
6667
<TouchableWithoutFeedback onPress={toggleAutoPlay}>
@@ -82,5 +83,5 @@ export const Vimeo: React.FC<LayoutProps> = ({
8283
]}
8384
/>
8485
</TouchableWithoutFeedback>
85-
);
86-
};
86+
)
87+
}

tsconfig.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@
1212
"strict": true,
1313
"target": "ESNext"
1414
},
15-
"exclude": ["**/__tests__/*"],
16-
"include": ["src"]
15+
"exclude": [],
16+
"include": ["src/index.tsx", "src/template", "src/types.ts"]
1717
}

0 commit comments

Comments
 (0)