{"id":4635,"url":"https://github.com/lucasferreira/react-native-webview-android","last_synced_at":"2025-12-29T23:50:38.743Z","repository":{"id":57341451,"uuid":"45624559","full_name":"lucasferreira/react-native-webview-android","owner":"lucasferreira","description":"Simple React Native Android module to use Android's WebView inside your app","archived":false,"fork":false,"pushed_at":"2020-06-05T07:44:58.000Z","size":81,"stargazers_count":355,"open_issues_count":31,"forks_count":159,"subscribers_count":12,"default_branch":"master","last_synced_at":"2025-07-05T09:42:14.842Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lucasferreira.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-11-05T16:37:46.000Z","updated_at":"2024-11-02T04:47:08.000Z","dependencies_parsed_at":"2022-09-08T03:00:39.054Z","dependency_job_id":null,"html_url":"https://github.com/lucasferreira/react-native-webview-android","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/lucasferreira/react-native-webview-android","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lucasferreira%2Freact-native-webview-android","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lucasferreira%2Freact-native-webview-android/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lucasferreira%2Freact-native-webview-android/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lucasferreira%2Freact-native-webview-android/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lucasferreira","download_url":"https://codeload.github.com/lucasferreira/react-native-webview-android/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lucasferreira%2Freact-native-webview-android/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":268636476,"owners_count":24282094,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-03T02:00:12.545Z","response_time":2577,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-01-05T20:17:18.596Z","updated_at":"2025-12-29T23:50:38.707Z","avatar_url":"https://github.com/lucasferreira.png","language":"Java","funding_links":[],"categories":["Components","组件","Libraries"],"sub_categories":["Web","Web相关"],"readme":"# react-native-webview-android\nSimple React Native Android module to use Android's WebView inside your app (with experimental html file input support to handle file uploads in forms).\n\n[![npm version](http://img.shields.io/npm/v/react-native-webview-android.svg?style=flat-square)](https://npmjs.org/package/react-native-webview-android \"View this project on npm\")\n[![npm downloads](http://img.shields.io/npm/dm/react-native-webview-android.svg?style=flat-square)](https://npmjs.org/package/react-native-webview-android \"View this project on npm\")\n[![npm licence](http://img.shields.io/npm/l/react-native-webview-android.svg?style=flat-square)](https://npmjs.org/package/react-native-webview-android \"View this project on npm\")\n\n### Installation\n\n```bash\nnpm install react-native-webview-android --save\n```\n\n### Add it to your android project\n\n* In `android/setting.gradle`\n\n```gradle\n...\ninclude ':RNWebView', ':app'\nproject(':RNWebView').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-webview-android/android')\n```\n\n* In `android/app/build.gradle`\n\n```gradle\n...\ndependencies {\n  ...\n  compile project(':RNWebView')\n}\n```\n\n* Register Module - RN \u003e= 0.29 (in MainApplication.java)\n\n```java\nimport com.burnweb.rnwebview.RNWebViewPackage;  // \u003c--- import\n\npublic class MainApplication extends Application implements ReactApplication {\n  ......\n\n  @Override\n  protected List\u003cReactPackage\u003e getPackages() {\n    return Arrays.\u003cReactPackage\u003easList(\n        new MainReactPackage(),\n        new RNWebViewPackage()); // \u003c------ add this line to your MainApplication class\n  }\n\n  ......\n\n}\n```\n\nIf you need to see the install instructions for older React Native versions [look here](https://github.com/lucasferreira/react-native-webview-android/blob/react-native-older/README.md).\n\n\n## Example\n```javascript\nvar React = require('react-native');\nvar { StyleSheet } = React;\n\nvar WebViewAndroid = require('react-native-webview-android');\n\nvar SITE_URL = \"https://www.google.com\";\n\nvar WebViewAndroidExample = React.createClass({\n    getInitialState: function() {\n      return {\n        url: SITE_URL,\n        // OR\n        // you can use a source object like React Native Webview.\n        // source {uri: string, method: string, headers: object, body: string}, {html: string, baseUrl: string}\n        // Loads static html or a uri (with optional headers) in the WebView. \u003cJust like React Native's version\u003e\n        // source: {\n        //   uri: SITE_URL,\n        //   headers: {\n        //     ...\n        //   },\n        // },\n        status: 'No Page Loaded',\n        backButtonEnabled: false,\n        forwardButtonEnabled: false,\n        loading: true,\n        messageFromWebView: null\n      };\n    },\n    goBack: function() {\n      // you can use this callback to control web view\n      this.refs.webViewAndroidSample.goBack();\n    },\n    goForward: function() {\n      this.refs.webViewAndroidSample.goForward();\n    },\n    reload: function() {\n      this.refs.webViewAndroidSample.reload();\n    },\n    stopLoading: function() {\n      // stops the current load\n      this.refs.webViewAndroidSample.stopLoading();\n    },\n    postMessage: function(data) {\n      // posts a message to web view\n      this.refs.webViewAndroidSample.postMessage(data);\n    },\n    evaluateJavascript: function(data) {\n      // evaluates javascript directly on the webview instance\n      this.refs.webViewAndroidSample.evaluateJavascript(data);\n    },\n    injectJavaScript: function(script) {\n      // executes JavaScript immediately in web view\n      this.refs.webViewAndroidSample.injectJavaScript(script);\n    },\n    onShouldStartLoadWithRequest: function(event) {\n      // currently only url \u0026 navigationState are returned in the event.\n      console.log(event.url);\n      console.log(event.navigationState);\n\n      if (event.url === 'https://www.mywebsiteexample.com/') {\n        return true;\n      } else {\n        return false;\n      }\n    },\n    onNavigationStateChange: function(event) {\n      console.log(event);\n\n      this.setState({\n        backButtonEnabled: event.canGoBack,\n        forwardButtonEnabled: event.canGoForward,\n        url: event.url,\n        status: event.title,\n        loading: event.loading\n      });\n    },\n    onMessage: function(event) {\n      this.setState({\n        messageFromWebView: event.message\n      });\n    },\n    javascriptToInject: function () {\n      return `\n        $(document).ready(function() {\n          $('a').click(function(event) {\n            if ($(this).attr('href')) {\n              var href = $(this).attr('href');\n              window.webView.postMessage('Link tapped: ' + href);\n            }\n          })\n        })\n      `\n    },\n    render: function() {\n      return (\n        \u003cWebViewAndroid\n          ref=\"webViewAndroidSample\"\n          javaScriptEnabled={true}\n          geolocationEnabled={false}\n          builtInZoomControls={false}\n          injectedJavaScript={this.javascriptToInject()}\n          onShouldStartLoadWithRequest={this.onShouldStartLoadWithRequest}\n          onNavigationStateChange={this.onNavigationStateChange}\n          onMessage={this.onMessage}\n          url={SITE_URL} // or use the source(object) attribute...\n          style={styles.containerWebView} /\u003e\n      );\n\n      // other attributes: source(object), html(string), htmlCharset(string), baseUrl(string), injectedJavaScript(string), disableCookies(bool), disablePlugins(bool), userAgent(string)\n    }\n});\n\nvar styles = StyleSheet.create({\n  containerWebView: {\n    flex: 1,\n  }\n});\n```\n\n## Note about onShouldStartLoadWithRequest\n\nThis module has a working implementation of onShouldStartLoadWithRequest. However, the event it returns currently only includes `url` and `navigationState`.\n\n## Note about HTML file input (files upload)\n\nThis module implements an experimental support to handle file input in HTML forms for upload files. It was tested in some Android versions 4.1+, but it's possible that some device won't work OK with that *new* feature.\n\n![File input demo](http://i.imgur.com/5Fbaxfn.gif)\n\n## Tips for Video (HTML5) inside WebView\n\nTo work with some html5 video player inside your Webview, I recommend you to set the android:hardwareAccelerated=\"true\" in your AndroidManifest.xml file.\n\nMore info here: http://stackoverflow.com/questions/17259636/enabling-html5-video-playback-in-android-webview\n\n## License\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flucasferreira%2Freact-native-webview-android","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flucasferreira%2Freact-native-webview-android","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flucasferreira%2Freact-native-webview-android/lists"}