Skip to content

Commit 585ac7a

Browse files
authored
fix(AndroidX support): Fixed broken import + added instructions (#583)
Hello, in order to use react-native-webview > 6.0.2 please make your android/gradle.properties contains: ``` android.useAndroidX=true android.enableJetifier=true ``` This enables AndroidX libraries which are the new standard. fixes #580 fixes #581 fixes #582
1 parent c98b5be commit 585ac7a

File tree

4 files changed

+17
-6
lines changed

4 files changed

+17
-6
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ This project follows [semantic versioning](https://semver.org/). We do not hesit
3030

3131
Current Version: ![version](https://img.shields.io/npm/v/react-native-webview.svg)
3232

33+
- [6.0.**2**](https://github.com/react-native-community/react-native-webview/releases/tag/v6.0.2) - Update to AndroidX. Make sure to enable it in your project's `android/gradle.properties`. See [Getting Started Guide](docs/Getting-Started.md).
3334
- [5.0.**1**](https://github.com/react-native-community/react-native-webview/releases/tag/v5.0.0) - Refactored the old postMessage implementation for communication from webview to native.
3435
- [4.0.0](https://github.com/react-native-community/react-native-webview/releases/tag/v4.0.0) - Added cache (enabled by default).
3536
- [3.0.0](https://github.com/react-native-community/react-native-webview/releases/tag/v3.0.0) - WKWebview: Add shared process pool so cookies and localStorage are shared across webviews in iOS (enabled by default).

android/gradle.properties

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
ReactNativeWebView_kotlinVersion=1.3.11
22
ReactNativeWebView_compileSdkVersion=28
33
ReactNativeWebView_buildToolsVersion=28.0.3
4-
ReactNativeWebView_targetSdkVersion=28
5-
android.useAndroidX=true
4+
ReactNativeWebView_targetSdkVersion=28

android/src/main/java/com/reactnativecommunity/webview/RNCWebViewManager.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import android.net.Uri;
1111
import android.os.Build;
1212
import android.os.Environment;
13-
import android.support.annotation.RequiresApi;
13+
import androidx.annotation.RequiresApi;
1414
import android.text.TextUtils;
1515
import android.view.Gravity;
1616
import android.view.View;

docs/Getting-Started.md

+14-3
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,21 @@ $ yarn add react-native-webview
1212

1313
React Native modules that include native Objective-C, Swift, Java, or Kotlin code have to be "linked" so that the compiler knows to include them in the app.
1414

15-
This module does not require any extra step after running the link command 🎉
1615
```
1716
$ react-native link react-native-webview
1817
```
18+
19+
iOS:
20+
This module does not require any extra step after running the link command 🎉
21+
22+
Android:
23+
Please make sure AndroidX is enabled in your project by editting `android/gradle.properties` and adding 2 lines:
24+
25+
```
26+
android.useAndroidX=true
27+
android.enableJetifier=true
28+
```
29+
1930
For Android manual installation, please refer to [this article](https://engineering.brigad.co/demystifying-react-native-modules-linking-964399ec731b) where you can find detailed step on how to link any react-native project.
2031

2132
For iOS, while you can manually link the old way using [react-native own tutorial](https://facebook.github.io/react-native/docs/linking-libraries-ios), we find it easier to use cocoapods.
@@ -33,8 +44,8 @@ class MyWeb extends Component {
3344
render() {
3445
return (
3546
<WebView
36-
source={{uri: 'https://infinite.red'}}
37-
style={{marginTop: 20}}
47+
source={{ uri: 'https://infinite.red' }}
48+
style={{ marginTop: 20 }}
3849
/>
3950
);
4051
}

0 commit comments

Comments
 (0)