解决React Native的WebView的文件上传问题

React Native:0.34.0

解决方案:https://github.com/Oblongmana/react-native-webview-file-upload-android

package.json

"react-native-webview-file-upload-android": "^1.1.2",

按照ReadMe弄下来以后,原生这边有点问题:

com.oblongmana.webviewfileuploadandroid的AndroidWebViewPackage修改为

public class AndroidWebViewPackage implements ReactPackage {
    private AndroidWebViewManager manager;
    private AndroidWebViewModule module;

    @Override public List<ViewManager> createViewManagers(ReactApplicationContext reactContext) {
        manager = new AndroidWebViewManager();
        manager.setPackage(this);
        return Arrays.<ViewManager>asList(manager);
    }

    @Override public List<NativeModule> createNativeModules( ReactApplicationContext reactContext) {
        List<NativeModule> modules = new ArrayList<>();
        module = new AndroidWebViewModule(reactContext);
        module.setPackage(this);
        modules.add(module);
        return modules;
    }

    +@Override
    +public List<Class<? extends JavaScriptModule>> createJSModules() {
    +    return Collections.emptyList();
    +}

    public AndroidWebViewManager getManager(){
        return manager;
    }

    public AndroidWebViewModule getModule(){
        return module;
    }
}

node_modules里面要修改为
AndroidWebView.js

import React, {
  Component,
    PropTypes
} from 'react';
import ReactNative, {
  EdgeInsetsPropType,
  ActivityIndicator,
  StyleSheet,
  UIManager,
  View,
  requireNativeComponent,
} from 'react-native';
import WebViewShared from './WebViewShared';
import warning from 'warning';
import keyMirror from 'keymirror';
import resolveAssetSource from 'react-native/Libraries/Image/resolveAssetSource';
// import PropTypes from 'prop-types';

...

static propTypes = {
    // ...View.PropTypes,
    renderError: PropTypes.func,
    renderLoading: PropTypes.func,
    onLoad: PropTypes.func,
    onLoadEnd: PropTypes.func,
    onLoadStart: PropTypes.func,
    onError: PropTypes.func,
    automaticallyAdjustContentInsets: PropTypes.bool,
    contentInset: EdgeInsetsPropType,
    onNavigationStateChange: PropTypes.func,
    onMessage: PropTypes.func,
    onContentSizeChange: PropTypes.func,
    startInLoadingState: PropTypes.bool, // force WebView to show loadingView on first load
    style: View.propTypes.style,


...

否则会出现 ‘style’ of undefined

发表评论

电子邮件地址不会被公开。 必填项已用*标注