-
Notifications
You must be signed in to change notification settings - Fork 36
/
index.js
57 lines (51 loc) · 1.72 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
import React, { Component } from "react";
import PropTypes from 'prop-types';
import {
WebView,
requireNativeComponent,
NativeModules,
Platform
} from "react-native";
const { CustomWebViewManager } = NativeModules;
/**
* React Native's WebView on Android does not allow picture uploads. However, due to [this pull request](https://github.com/facebook/react-native/pull/15016) one can override parts of the built-in WebView to add hooks wherever necessary.
*
* This component will:
*
* 1. Use the built-in React Native WebView on iOS.
* 2. Be a drop-in replacement for the Android WebView with the additional functionality for file uploads.
*
* This requires several Java files to work: CustomWebViewManager.java, CustomWebViewModule.java, and CustomWebViewPackage.java. Additionally, the MainApplication.java file needs to be edited to include the new package.
*
* Lots of guidance from [the example project for the original PR](https://github.com/cbrevik/webview-native-config-example) and from [a sample Android webview](https://github.com/hushicai/ReactNativeAndroidWebView).
*/
export default class CustomWebView extends Component {
static propTypes = {
...WebView.propTypes,
webviewRef: PropTypes.func
};
render() {
const { webviewRef, ...props } = this.props;
return (
<WebView
ref={webviewRef}
{...props}
nativeConfig={this.getNativeConfig()}
/>
);
}
getNativeConfig() {
if (Platform.OS !== "android") {
return null;
}
return {
component: RCTCustomWebView,
viewManager: CustomWebViewManager
};
}
}
const RCTCustomWebView = requireNativeComponent(
"RCTCustomWebView",
CustomWebView,
WebView.extraNativeComponentConfig
);