maps icon indicating copy to clipboard operation
maps copied to clipboard

fix: new NativeEventEmitter() was called with a non-null argument

Open efstathiosntonas opened this issue 6 months ago • 1 comments

Description

Fixes on Android:

 WARN  new NativeEventEmitter() was called with a non-null argument without the required addListener method.
 WARN  new NativeEventEmitter() was called with a non-null argument without the required removeListeners method.

introduced in this PR: https://github.com/rnmapbox/maps/pull/3789

Checklist

  • [x] I've read CONTRIBUTING.md
  • [ ] I updated the doc/other generated code with running yarn generate in the root folder
  • [ ] I have tested the new feature on /example app.
    • [ ] In V11 mode/ios
    • [ ] In New Architecture mode/ios
    • [ ] In V11 mode/android
    • [ ] In New Architecture mode/android
  • [ ] I added/updated a sample - if a new feature was implemented (/example)

efstathiosntonas avatar Jun 11 '25 10:06 efstathiosntonas

patch:

@rnmapbox+maps+10.1.39.patch

diff --git a/node_modules/@rnmapbox/maps/android/src/main/java/com/rnmapbox/rnmbx/modules/RNMBXLocationModule.kt b/node_modules/@rnmapbox/maps/android/src/main/java/com/rnmapbox/rnmbx/modules/RNMBXLocationModule.kt
index 7c87fc2..5d78df7 100644
--- a/node_modules/@rnmapbox/maps/android/src/main/java/com/rnmapbox/rnmbx/modules/RNMBXLocationModule.kt
+++ b/node_modules/@rnmapbox/maps/android/src/main/java/com/rnmapbox/rnmbx/modules/RNMBXLocationModule.kt
@@ -132,12 +132,12 @@ class RNMBXLocationModule(reactContext: ReactApplicationContext) :
     }
 
     @ReactMethod
-    fun addListener(eventName: String?) {
+    override fun addListener(eventName: String?) {
         // Required for rn built in EventEmitter Calls.
     }
 
     @ReactMethod
-    fun removeListeners(count: Int?) {
+    override fun removeListeners(count: Int?) {
         // Required for rn built in EventEmitter Calls.
     }
 
diff --git a/node_modules/@rnmapbox/maps/android/src/main/old-arch/com/rnmapbox/rnmbx/NativeRNMBXLocationModuleSpec.java b/node_modules/@rnmapbox/maps/android/src/main/old-arch/com/rnmapbox/rnmbx/NativeRNMBXLocationModuleSpec.java
index e5db5cb..cf854f7 100644
--- a/node_modules/@rnmapbox/maps/android/src/main/old-arch/com/rnmapbox/rnmbx/NativeRNMBXLocationModuleSpec.java
+++ b/node_modules/@rnmapbox/maps/android/src/main/old-arch/com/rnmapbox/rnmbx/NativeRNMBXLocationModuleSpec.java
@@ -65,4 +65,12 @@ public abstract class NativeRNMBXLocationModuleSpec extends ReactContextBaseJava
   @ReactMethod
   @DoNotStrip
   public abstract void setLocationEventThrottle(double throttle);
+
+  @ReactMethod
+  @DoNotStrip
+  public abstract void addListener(String eventName);
+
+  @ReactMethod
+  @DoNotStrip
+  public abstract void removeListeners(Integer count);
 }

efstathiosntonas avatar Jun 11 '25 10:06 efstathiosntonas

Nice one, Hopefully someone take a look on this

javier-sauma-rocketlab avatar Jun 19 '25 01:06 javier-sauma-rocketlab

+1

DavidAmyot avatar Jun 20 '25 15:06 DavidAmyot

@fresnel-bruno it’s a common pattern with the event emitters, if you search for the keywords on github you will find out that this is how they are handled on other packages too.

efstathiosntonas avatar Jul 22 '25 16:07 efstathiosntonas

patch:

@rnmapbox+maps+10.1.39.patch

diff --git a/node_modules/@rnmapbox/maps/android/src/main/java/com/rnmapbox/rnmbx/modules/RNMBXLocationModule.kt b/node_modules/@rnmapbox/maps/android/src/main/java/com/rnmapbox/rnmbx/modules/RNMBXLocationModule.kt
index 7c87fc2..5d78df7 100644
--- a/node_modules/@rnmapbox/maps/android/src/main/java/com/rnmapbox/rnmbx/modules/RNMBXLocationModule.kt
+++ b/node_modules/@rnmapbox/maps/android/src/main/java/com/rnmapbox/rnmbx/modules/RNMBXLocationModule.kt
@@ -132,12 +132,12 @@ class RNMBXLocationModule(reactContext: ReactApplicationContext) :
     }
 
     @ReactMethod
-    fun addListener(eventName: String?) {
+    override fun addListener(eventName: String?) {
         // Required for rn built in EventEmitter Calls.
     }
 
     @ReactMethod
-    fun removeListeners(count: Int?) {
+    override fun removeListeners(count: Int?) {
         // Required for rn built in EventEmitter Calls.
     }
 
diff --git a/node_modules/@rnmapbox/maps/android/src/main/old-arch/com/rnmapbox/rnmbx/NativeRNMBXLocationModuleSpec.java b/node_modules/@rnmapbox/maps/android/src/main/old-arch/com/rnmapbox/rnmbx/NativeRNMBXLocationModuleSpec.java
index e5db5cb..cf854f7 100644
--- a/node_modules/@rnmapbox/maps/android/src/main/old-arch/com/rnmapbox/rnmbx/NativeRNMBXLocationModuleSpec.java
+++ b/node_modules/@rnmapbox/maps/android/src/main/old-arch/com/rnmapbox/rnmbx/NativeRNMBXLocationModuleSpec.java
@@ -65,4 +65,12 @@ public abstract class NativeRNMBXLocationModuleSpec extends ReactContextBaseJava
   @ReactMethod
   @DoNotStrip
   public abstract void setLocationEventThrottle(double throttle);
+
+  @ReactMethod
+  @DoNotStrip
+  public abstract void addListener(String eventName);
+
+  @ReactMethod
+  @DoNotStrip
+  public abstract void removeListeners(Integer count);
 }

Using this patch gives compilation error

/node_modules/@rnmapbox/maps/android/src/main/java/com/rnmapbox/rnmbx/modules/RNMBXLocationModule.kt:140:5 'removeListeners' overrides nothing. FAILURE: Build failed with an exception. * What went wrong:
Execution failed for task ':rnmapbox_maps:compileDebugKotlin'.

allthetime avatar Aug 06 '25 02:08 allthetime

@allthetime which react-native version? fabric or paper?

efstathiosntonas avatar Aug 06 '25 03:08 efstathiosntonas

@efstathiosntonas thanks much for the PR, looks good to me

Can you please rebase, so CI can run? Also can you add instruction on how to reproduce the issue?

mfazekas avatar Aug 08 '25 06:08 mfazekas

Hi @mfazekas, will rebase in a while.

Just booting the app showed the warnings in the console, nothing special.

efstathiosntonas avatar Aug 08 '25 06:08 efstathiosntonas

@mfazekas just rebased

to add some context on the previous comment about reproducing, I use [email protected] on Paper

efstathiosntonas avatar Aug 08 '25 09:08 efstathiosntonas

Using this patch gives compilation error

/node_modules/@rnmapbox/maps/android/src/main/java/com/rnmapbox/rnmbx/modules/RNMBXLocationModule.kt:140:5 'removeListeners' overrides nothing. FAILURE: Build failed with an exception. * What went wrong:
Execution failed for task ':rnmapbox_maps:compileDebugKotlin'.

Experiencing this too, main difference is that I'm on fabric (RN 0.79).

[RUN_GRADLEW] e: file:///private/var/folders/ch/719g3dfj2mz6cwrnzcx6mg500000gp/T/eas-build-local-nodejs/f77ff0f1-b5a2-4a65-b59b-5a3bbd982a6a/build/fronts/app-mobile/ui/node_modules/@rnmapbox/maps/android/src/main/java/com/rnmapbox/rnmbx/modules/RNMBXLocationModule.kt:19:1 Class 'RNMBXLocationModule' is not abstract and does not implement abstract base class member 'removeListeners'.                                                 
[RUN_GRADLEW] e: file:///private/var/folders/ch/719g3dfj2mz6cwrnzcx6mg500000gp/T/eas-build-local-nodejs/f77ff0f1-b5a2-4a65-b59b-5a3bbd982a6a/build/fronts/app-mobile/ui/node_modules/@rnmapbox/maps/android/src/main/java/com/rnmapbox/rnmbx/modules/RNMBXLocationModule.kt:142:5 'removeListeners' overrides nothing.    

mcastets avatar Aug 13 '25 13:08 mcastets

Any updates here? @efstathiosntonas @mcastets

Also facing the compilation error

regalstreak avatar Sep 01 '25 16:09 regalstreak

Any updates here? @efstathiosntonas @mcastets

Also facing the compilation error

I haven't applied the patch and I just live with the original warning. I don't think it's harmful.

mcastets avatar Sep 01 '25 19:09 mcastets

@efstathiosntonas I think most of this PR is already merged?

mfazekas avatar Oct 12 '25 05:10 mfazekas

@mfazekas I think so yeah, feel free to close it

efstathiosntonas avatar Oct 12 '25 05:10 efstathiosntonas