# mf-react-native-webview-jsbridge

> React Native WebView component for iOS, Android

Latest version **1.0.0** (published 2019-06-03) · MIT license · 0 weekly downloads

## Install

```sh
npm install mf-react-native-webview-jsbridge
pnpm add mf-react-native-webview-jsbridge
yarn add mf-react-native-webview-jsbridge
bun add mf-react-native-webview-jsbridge
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2019-06-03 |
| First published | 2019-05-28 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 992.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 8 |
| Author | open@23mofang.com |
| Maintainers | 23mofang |

## Links

- npm: https://www.npmjs.com/package/mf-react-native-webview-jsbridge
- Repository: https://github.com/23mf/mf-react-native-webview-jsbridge
- Homepage: https://github.com/23mf/mf-react-native-webview-jsbridge.git#readme
- Issues: https://github.com/23mf/mf-react-native-webview-jsbridge/issues
- npm.io page: https://npm.io/package/mf-react-native-webview-jsbridge

## Dependencies (2)

- [fbjs](https://npm.io/package/fbjs.md) ^0.8.17
- [escape-string-regexp](https://npm.io/package/escape-string-regexp.md) ^1.0.5

## Recent versions

- 1.0.0 (latest) — 2019-06-03
- 0.1.6 — 2019-05-31
- 0.1.5 — 2019-05-31
- 0.1.4 — 2019-05-29
- 0.1.3 — 2019-05-29
- 0.1.2 — 2019-05-29
- 0.1.1 — 2019-05-28
- 0.1.0 — 2019-05-28

## README

# React Native WebView jsbridge - Complete the Correspondence between web and Native

**React Native WebView jsbridge** 是在[react-native-community/react-native-webview](https://github.com/react-native-community/react-native-webview)基础上开发的实现的native与web的通信。

## 支持的平台

- [x] iOS (支持 UIWebView，WKWebView)
- [x] Android (使用腾讯X5内核)


## 自动安装

使用npm
```
$ npm install mf-react-native-webview-jsbridge -save
```
或使用yarn
```
$ yarn add mf-react-native-webview-jsbridge
```
然后
```
$ react-native link mf-react-native-webview-jsbridge
```


##手动安装
###iOS
1. `Libraries`文件下右键`Add Files to 'xxx'...`,添加`RNCWebView.xcodeproj`.
2. 在`Linked Frameworks and Libraries`添加`libRNCWebView.a`

###Android
1. 在你的工程下的`android/settings.gradle`:

```java
...
include ':mf-react-native-webview-jsbridge'
project(':mf-react-native-webview-jsbridge').projectDir = new File(rootProject.projectDir, '../node_modules/mf-react-native-webview-jsbridge/lib/android')
```
2. 在你的工程下的`android/app/build.gradle`:

```java
...
dependencies {
  ...
  implementation project(':mf-react-native-webview-jsbridge')
}
```
3. 添加 import `com.airbnb.android.react.maps.MapsPackage;`，`new MapsPackage()` 在你的 `MainApplication.java`

```java
import com.reactnativemf.webview.ReactNativeWebViewPackage;
...
    @Override
    protected List<ReactPackage> getPackages() {
        return Arrays.<ReactPackage>asList(
                new MainReactPackage(),
                new ReactNativeWebViewPackage()
        );
    }
```

## 使用

Import the `WebView` component from `react-native-webview` and use it like so:

```jsx
import React, { Component } from "react";
import { StyleSheet, Text, View, Dimensions, TouchableOpacity } from "react-native";
import { WebView } from "react-native-webview";

// ...
class MyWebComponent extends Component {
  componentDidMount() {
    /**
     * 参数1：名称
     * 参数2： 传递给js的参数
     * 参数3： 回调函数，获取js返回的参数
     */
    this.webviewRef && this.webviewRef.registerHandler('getJsInfo', 'oc传给了js一条信息', (res)=> {
      Alert.alert(res.msg);
    });
  }
  render() {
    const size = Dimensions.get('window');
    return (
      <View style={styles.container}>
        <TouchableOpacity
          style={{ marginTop: 20 }}
          onPress={this.handPress}
        >
          <Text>App调用Web端提供的方法</Text>
        </TouchableOpacity>
        <WebView
          ref={refs => (this.webviewRef = refs)}
          useWebKit
          style={{ width: size.width, height: size.height }}
          source={{ uri: '' }}
        />
      </View>
    );
  }
  handPress = () => {
    /**
     * 参数1：名称
     * 参数2： 传递给js的参数
     * 参数3： 回调函数，获取js返回的参数
     */
    this.webviewRef.callHandler('getJsMethod', '', (data) => {
      Alert.alert(data);
    });
  }
}
```

关于webview的[API Reference](./docs/Reference.md)


## 故障排除

- 如果你遇到 `Invariant Violation: Native component for "RNCWKWebView does not exist"` 你可以使用 `react-native link` 或者手动链接
- `'config.h' file not found`或`replace glog-0.3.X`：
```
cd node_modules/react-native/third-party/glog-0.3.4
./configure
```


## License

MIT

---
_Source: https://npm.io/package/mf-react-native-webview-jsbridge · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
