npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

mf-react-native-webview-jsbridge

v1.0.0

Published

React Native WebView component for iOS, Android

Downloads

8

Readme

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

React Native WebView jsbridge 是在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:
...
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')
  1. 在你的工程下的android/app/build.gradle:
...
dependencies {
  ...
  implementation project(':mf-react-native-webview-jsbridge')
}
  1. 添加 import com.airbnb.android.react.maps.MapsPackage;new MapsPackage() 在你的 MainApplication.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:

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

故障排除

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

License

MIT