From e4360cf298fd7f0ff2c58835fdb1430f9a43293d Mon Sep 17 00:00:00 2001 From: Thibault Malbranche Date: Mon, 18 Mar 2019 15:44:19 +0000 Subject: [PATCH] fixed types --- .eslintignore | 1 + index.d.ts | 7 ++++--- src/WebView.android.tsx | 5 +++-- src/WebView.ios.tsx | 5 +++-- src/WebViewTypes.ts | 17 ++++++++--------- 5 files changed, 19 insertions(+), 16 deletions(-) create mode 100644 .eslintignore diff --git a/.eslintignore b/.eslintignore new file mode 100644 index 0000000..f1ff06d --- /dev/null +++ b/.eslintignore @@ -0,0 +1 @@ +lib/ \ No newline at end of file diff --git a/index.d.ts b/index.d.ts index a41662f..9eaf91e 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1,7 +1,8 @@ -import WebViewIOS from './lib/WebView.ios'; -import WebViewAndroid from './lib/WebView.android'; +import { ComponentType } from 'react'; +// eslint-disable-next-line +import { IOSWebViewProps, AndroidWebViewProps } from './lib/WebViewTypes'; -declare const WebView: WebViewIOS | WebViewAndroid; +declare const WebView: ComponentType; export { WebView }; export default WebView; diff --git a/src/WebView.android.tsx b/src/WebView.android.tsx index 003bf99..b011a67 100644 --- a/src/WebView.android.tsx +++ b/src/WebView.android.tsx @@ -273,7 +273,8 @@ class WebView extends React.Component { const onShouldStartLoadWithRequest = createOnShouldStartLoadWithRequest( this.onShouldStartLoadWithRequestCallback, - originWhitelist, + // casting cause it's in the default props + originWhitelist as ReadonlyArray, onShouldStartLoadWithRequestProp, ); @@ -305,4 +306,4 @@ class WebView extends React.Component { } } -module.exports = WebView; +export default WebView; diff --git a/src/WebView.ios.tsx b/src/WebView.ios.tsx index 496e27f..5c8a14a 100644 --- a/src/WebView.ios.tsx +++ b/src/WebView.ios.tsx @@ -382,7 +382,8 @@ class WebView extends React.Component { const onShouldStartLoadWithRequest = createOnShouldStartLoadWithRequest( this.onShouldStartLoadWithRequestCallback, - originWhitelist, + // casting cause it's in the default props + originWhitelist as ReadonlyArray, onShouldStartLoadWithRequestProp, ); @@ -426,4 +427,4 @@ class WebView extends React.Component { } } -module.exports = WebView; +export default WebView; diff --git a/src/WebViewTypes.ts b/src/WebViewTypes.ts index 18f5dc4..5024ec4 100644 --- a/src/WebViewTypes.ts +++ b/src/WebViewTypes.ts @@ -8,7 +8,7 @@ /* eslint-disable react/no-multi-comp */ -import { ReactNode, ReactElement, Component } from 'react'; +import { ReactElement, Component } from 'react'; import { NativeSyntheticEvent, ViewStyle, @@ -512,7 +512,7 @@ export interface WebViewSharedProps extends ViewProps { /** * Function that returns a view to show if there's an error. */ - renderError: ( + renderError?: ( errorDomain: string | undefined, errorCode: number, errorDesc: string, @@ -521,27 +521,27 @@ export interface WebViewSharedProps extends ViewProps { /** * Function that returns a loading indicator. */ - renderLoading: () => ReactElement; + renderLoading?: () => ReactElement; /** * Function that is invoked when the `WebView` has finished loading. */ - onLoad: (event: WebViewNavigationEvent) => void; + onLoad?: (event: WebViewNavigationEvent) => void; /** * Function that is invoked when the `WebView` load succeeds or fails. */ - onLoadEnd: (event: WebViewNavigationEvent | WebViewErrorEvent) => void; + onLoadEnd?: (event: WebViewNavigationEvent | WebViewErrorEvent) => void; /** * Function that is invoked when the `WebView` starts loading. */ - onLoadStart: (event: WebViewNavigationEvent) => void; + onLoadStart?: (event: WebViewNavigationEvent) => void; /** * Function that is invoked when the `WebView` load fails. */ - onError: (event: WebViewErrorEvent) => void; + onError?: (event: WebViewErrorEvent) => void; /** * Function that is invoked when the `WebView` loading starts or ends. @@ -608,7 +608,7 @@ export interface WebViewSharedProps extends ViewProps { * this whitelist, we will open the URL in Safari. * The default whitelisted origins are "http://*" and "https://*". */ - originWhitelist: ReadonlyArray; + originWhitelist?: ReadonlyArray; /** * Function that allows custom handling of any web view requests. Return @@ -629,5 +629,4 @@ export interface WebViewSharedProps extends ViewProps { cacheEnabled?: boolean; style?: StyleProp; - children: ReactNode; }