Skip to content

Commit

Permalink
Bugfix/crash app (#2)
Browse files Browse the repository at this point in the history
* fixes

* include react-dom

* remove peer dependencies

* wip

* path resolver

* add resolutions

* test
  • Loading branch information
Marcoo09 authored Jun 5, 2021
1 parent 19e52a1 commit 1e0d48a
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 44 deletions.
11 changes: 3 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-native-vimeo-iframe",
"version": "1.0.0",
"version": "1.0.1",
"description": "",
"homepage": "https://github.com/MetaLabs-inc/react-native-vimeo-iframe#readme",
"main": "src/index.tsx",
Expand All @@ -16,11 +16,6 @@
"prepare": "yarn compile",
"test": "jest"
},
"dependencies": {
"react": "^17.0.1",
"react-native": "^0.63.4",
"react-native-webview": "11.2.3"
},
"devDependencies": {
"@babel/core": "^7.12.10",
"@babel/runtime": "^7.12.5",
Expand All @@ -39,8 +34,8 @@
"typescript": "^4.1.3"
},
"peerDependencies": {
"react": "*",
"react-native": "*"
"react-native": "^0.63.4",
"react-native-webview": "11.2.3"
},
"jest": {
"preset": "react-native",
Expand Down
69 changes: 35 additions & 34 deletions src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import React, {useCallback, useEffect, useState} from 'react';
import {TouchableWithoutFeedback} from 'react-native';
import {WebView} from 'react-native-webview';
import webplayer from './template';
import {LayoutProps} from './types';
import React from 'react'
import { TouchableWithoutFeedback } from 'react-native'
import { WebView } from 'react-native-webview'

import webplayer from './template'
import { LayoutProps } from './types'

export const Vimeo: React.FC<LayoutProps> = ({
videoId,
Expand All @@ -18,49 +19,49 @@ export const Vimeo: React.FC<LayoutProps> = ({
speed = false,
style,
}) => {
const [isReady, setReady] = useState<boolean>();
const [isReady, setReady] = React.useState<boolean>()

const [autoPlayValue, setAutoPlay] = useState<boolean>(autoPlay);
const toggleAutoPlay = useCallback(() => setAutoPlay(!autoPlayValue), [
const [autoPlayValue, setAutoPlay] = React.useState<boolean>(autoPlay)
const toggleAutoPlay = React.useCallback(() => setAutoPlay(!autoPlayValue), [
autoPlayValue,
]);
])

const handlers: any = {};
const handlers: any = {}
const registerHandlers = () => {
registerBridgeEventHandler('ready', onReady ?? onReadyDefault);
registerBridgeEventHandler('play', onPlay);
registerBridgeEventHandler('playProgress', onPlayProgress);
registerBridgeEventHandler('pause', onPause);
registerBridgeEventHandler('finish', onFinish);
};
registerBridgeEventHandler('ready', onReady ?? onReadyDefault)
registerBridgeEventHandler('play', onPlay)
registerBridgeEventHandler('playProgress', onPlayProgress)
registerBridgeEventHandler('pause', onPause)
registerBridgeEventHandler('finish', onFinish)
}

const registerBridgeEventHandler = (eventName: string, handler: any) => {
handlers[eventName] = handler;
};
handlers[eventName] = handler
}

useEffect(() => {
registerHandlers();
}, [videoId, scalesPageToFit]);
React.useEffect(() => {
registerHandlers()
}, [videoId, scalesPageToFit])

const onBridgeMessage = (event: any) => {
const message = event.nativeEvent.data;
let payload;
const message = event.nativeEvent.data
let payload
try {
payload = JSON.parse(message);
payload = JSON.parse(message)
if (payload?.name === 'finish') {
toggleAutoPlay();
toggleAutoPlay()
}
} catch (err) {
return;
return
}
let handler = handlers[payload.name];
if (handler) handler(payload.data);
};
let handler = handlers[payload.name]
if (handler) handler(payload.data)
}

const onReadyDefault = () => {
setReady(true);
if (onReady) setTimeout(onReady);
};
setReady(true)
if (onReady) setTimeout(onReady)
}

return (
<TouchableWithoutFeedback onPress={toggleAutoPlay}>
Expand All @@ -82,5 +83,5 @@ export const Vimeo: React.FC<LayoutProps> = ({
]}
/>
</TouchableWithoutFeedback>
);
};
)
}
4 changes: 2 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@
"strict": true,
"target": "ESNext"
},
"exclude": ["**/__tests__/*"],
"include": ["src"]
"exclude": [],
"include": ["src/index.tsx", "src/template", "src/types.ts"]
}

0 comments on commit 1e0d48a

Please sign in to comment.