-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
78 lines (69 loc) · 2.15 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import React from 'react';
import { Platform, WebView } from 'react-native';
import PropTypes from 'prop-types';
import withInterceptLink from './withInterceptLink';
import withJsBridge from './withJsBridge';
import withQuery from './withQuery';
function wrapWebView (Wrapped) {
class WebViewWithRef extends React.Component {
static propTypes = {
getWebView: PropTypes.func.isRequired,
query: PropTypes.shape({
token: PropTypes.string,
userId: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
appName: PropTypes.string.isRequired,
appVersion: PropTypes.string.isRequired,
appType: PropTypes.string,
}),
onWebRequest: PropTypes.func.isRequired,
getUtilities: PropTypes.func,
};
static defaultProps = {
getWebView: () => {},
query: {
token: '',
userId: '',
appType: Platform.select({ ios: 'iOS', android: 'Android' }),
},
};
render() {
const { url, ...passProps } = this.props;
if (url) {
console.log('should not pass url to WebView');
}
return (
<Wrapped
{...passProps}
ref={ref => this.props.getWebView(ref)}
/>
);
}
}
return WebViewWithRef;
}
const WebViewWithRef = wrapWebView(WebView);
/* eslint-disable */
const copyProps = WrappedWebView => class extends React.Component {
render() {
const { navigation } = this.props;
const { dispatch, state } = navigation || {};
const { params } = state || {};
const copiedProps = dispatch && params ? params : {};
return (
<WrappedWebView
{...this.props}
{...copiedProps}
/>
);
}
};
/* eslint-enable */
const baseHocs = [copyProps, withJsBridge, withQuery, withInterceptLink];
export const withExtra = (...hocs) => {
return baseHocs.concat(hocs).reduceRight((res, it) => it(res), WebViewWithRef);
};
export const createWebView = ({ originWebView = null, hocs = [] }) => {
const WrappedWebView = originWebView ? wrapWebView(originWebView) : WebViewWithRef;
return baseHocs.concat(hocs).reduceRight((res, it) => it(res), WrappedWebView);
};
export default withExtra();