Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No data returned below RN 0.65 #457

Open
Rays15 opened this issue Oct 27, 2023 · 1 comment
Open

No data returned below RN 0.65 #457

Rays15 opened this issue Oct 27, 2023 · 1 comment

Comments

@Rays15
Copy link

Rays15 commented Oct 27, 2023

Describe the bug
isBeingObserved is always false below RN 0.65, Because addListener will not execute.

public class RNSensor extends ReactContextBaseJavaModule implements SensorEventListener {
  ...

  private Boolean isBeingObserved = false;

  ...

  @Override
  public void onSensorChanged(SensorEvent sensorEvent) {
    if(!isBeingObserved) {
      return; // avoid all the computation if there are no observers
    }
    ...
  }

  ...

  // this is called by RN when the first listener is registered
  // not implementing this method will cause a warning on RN 0.65 onwards
  @ReactMethod
  public void addListener(String eventName) {
    isBeingObserved = true;
  }

  // this is called by RN when the last listener is deregistered
  // not implementing this method will cause a warning on RN 0.65 onwards
  @ReactMethod
  public void removeListeners(Integer count) {
    isBeingObserved = false;
    stopUpdates(); // maybe only calling `stopUpdates()` is enough
  }
}

To Reproduce
Steps to reproduce the behavior:

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. See error

Expected behavior
A clear and concise description of what you expected to happen.

Desktop (please complete the following information):

  • React Native Version: [e.g. 0.63.3]
  • Device [e.g. real android device]
  • Version [e.g. 7.3.6]

Additional context
Add any other context about the problem here.

@trandinhduc
Copy link

I got that too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants