Преглед на файлове

fix(android): Annotate RNCWebViewModule with @ReactModule to comply with latest changes (#459)

The app was crashing with `"Could not find @ReactModule annotation in class RNCWebViewModule"` exception. Searching for this message in RN's code I found [this commit](0cd3994f1a/), introduced in React Native 0.58, which requires native modules to be annotated with @ReactModule annotation. 🤔 

After adding the annotation to the module, tapping on a file input field no longer crashes the app (in fact it shows the file browser). 🎉 

I haven't had caught it previously, testing only against React Native 0.57, sorry! 😞 

For reference see similar fix in `react-native-gesture-handler` — https://github.com/kmagiera/react-native-gesture-handler/pull/295.

Fixes https://github.com/react-native-community/react-native-webview/issues/458.
Stanisław Chmiela преди 5 години
родител
ревизия
f6e208be61
променени са 1 файла, в които са добавени 4 реда и са изтрити 2 реда
  1. 4
    2
      android/src/main/java/com/reactnativecommunity/webview/RNCWebViewModule.java

+ 4
- 2
android/src/main/java/com/reactnativecommunity/webview/RNCWebViewModule.java Целия файл

@@ -25,6 +25,7 @@ import com.facebook.react.bridge.Promise;
25 25
 import com.facebook.react.bridge.ReactApplicationContext;
26 26
 import com.facebook.react.bridge.ReactContextBaseJavaModule;
27 27
 import com.facebook.react.bridge.ReactMethod;
28
+import com.facebook.react.module.annotations.ReactModule;
28 29
 import com.facebook.react.modules.core.PermissionAwareActivity;
29 30
 import com.facebook.react.modules.core.PermissionListener;
30 31
 
@@ -34,8 +35,9 @@ import java.util.ArrayList;
34 35
 
35 36
 import static android.app.Activity.RESULT_OK;
36 37
 
38
+@ReactModule(name = RNCWebViewModule.MODULE_NAME)
37 39
 public class RNCWebViewModule extends ReactContextBaseJavaModule implements ActivityEventListener {
38
-
40
+  public static final String MODULE_NAME = "RNCWebView";
39 41
   private static final int PICKER = 1;
40 42
   private static final int PICKER_LEGACY = 3;
41 43
   private static final int FILE_DOWNLOAD_PERMISSION_REQUEST = 1;
@@ -71,7 +73,7 @@ public class RNCWebViewModule extends ReactContextBaseJavaModule implements Acti
71 73
 
72 74
   @Override
73 75
   public String getName() {
74
-    return "RNCWebView";
76
+    return MODULE_NAME;
75 77
   }
76 78
 
77 79
   @ReactMethod