Browse Source

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 years ago
parent
commit
f6e208be61

+ 4
- 2
android/src/main/java/com/reactnativecommunity/webview/RNCWebViewModule.java View File

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