Skip to content

Commit

Permalink
Merge branch 'master' into gradle-cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
cristianoccazinsp authored Jan 28, 2022
2 parents eb8a15a + ce36e96 commit cbb9695
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 30 deletions.
20 changes: 20 additions & 0 deletions .github/workflows/npm-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# This workflow will run tests using node and then publish a package to GitHub Packages when a release is created
# For more information see: https://help.github.com/actions/language-and-framework-guides/publishing-nodejs-packages

name: Node.js Package

on:
workflow_dispatch:

jobs:
publish-npm:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: 16
registry-url: https://registry.npmjs.org/
- run: npm publish
env:
NODE_AUTH_TOKEN: ${{secrets.NODE_AUTH_TOKEN}}
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ credits - https://github.com/vnil/react-native-simple-compass

`$ yarn add react-native-compass-heading`

`$ cd ios/ && pod install && cd ..`
`$ npx pod-install`

## Usage
```javascript
Expand All @@ -25,7 +25,7 @@ const App = () => {
// accuracy on android will be hardcoded to 1
// since the value is not available.
// For iOS, it is in degrees
CompassHeading.start(degree_update_rate, {heading, accuracy} => {
CompassHeading.start(degree_update_rate, ({heading, accuracy}) => {
setCompassHeading(heading);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;
import com.facebook.react.bridge.Callback;
import com.facebook.react.bridge.Promise;
import com.facebook.react.bridge.Arguments;
import com.facebook.react.bridge.WritableMap;

import android.app.Activity;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
Expand All @@ -18,36 +18,32 @@

import android.content.Context;

import androidx.annotation.NonNull;

import com.facebook.react.modules.core.DeviceEventManagerModule;


public class CompassHeadingModule extends ReactContextBaseJavaModule implements SensorEventListener {

private final ReactApplicationContext reactContext;

private static Context mApplicationContext;

private int mAzimuth = 0; // degree
private int mFilter = 1;

private SensorManager sensorManager;

private Sensor gsensor;
private Sensor msensor;

private float[] mGravity = new float[3];
private float[] mGeomagnetic = new float[3];
private final float[] mGravity = new float[3];
private final float[] mGeomagnetic = new float[3];

private float[] R = new float[9];
private float[] I = new float[9];
private final float[] R = new float[9];
private final float[] I = new float[9];

public CompassHeadingModule(ReactApplicationContext reactContext) {
super(reactContext);
this.reactContext = reactContext;

mApplicationContext = reactContext.getApplicationContext();
}

@NonNull
@Override
public String getName() {
return "CompassHeading";
Expand All @@ -69,8 +65,8 @@ public void start(int filter, Promise promise) {
try{
sensorManager = (SensorManager) mApplicationContext.getSystemService(Context.SENSOR_SERVICE);

gsensor = sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
msensor = sensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD);
Sensor gsensor = sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
Sensor msensor = sensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD);

sensorManager.registerListener(this, gsensor, SensorManager.SENSOR_DELAY_GAME);
sensorManager.registerListener(this, msensor, SensorManager.SENSOR_DELAY_GAME);
Expand Down Expand Up @@ -137,15 +133,23 @@ public void onSensorChanged(SensorEvent event) {

if (success) {

float orientation[] = new float[3];
float[] orientation = new float[3];
SensorManager.getOrientation(R, orientation);

int newAzimuth = (int) Math.toDegrees(orientation[0]);
newAzimuth = (newAzimuth + 360) % 360;

Display disp = (((WindowManager) mApplicationContext.getSystemService(Context.WINDOW_SERVICE))).getDefaultDisplay();
Display disp = null;
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.R) {
Activity activity = getReactApplicationContext().getCurrentActivity();
if (activity != null) {
disp = activity.getDisplay();
}
} else {
disp = (((WindowManager) mApplicationContext.getSystemService(Context.WINDOW_SERVICE))).getDefaultDisplay();
}

if(disp != null){
if (disp != null) {
int rotation = disp.getRotation();

if(rotation == Surface.ROTATION_90){
Expand Down Expand Up @@ -173,13 +177,8 @@ else if(rotation == Surface.ROTATION_180){
}
}
}


}


@Override
public void onAccuracyChanged(Sensor sensor, int accuracy) {

}
public void onAccuracyChanged(Sensor sensor, int accuracy) {}
}
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "react-native-compass-heading",
"title": "React Native Compass Heading",
"version": "1.2.1",
"version": "1.3.3",
"description": "Listener to device's compass information.",
"main": "index.js",
"scripts": {
Expand All @@ -23,11 +23,11 @@
"licenseFilename": "LICENSE",
"readmeFilename": "README.md",
"peerDependencies": {
"react": "^16.8.1",
"react-native": ">=0.60.0-rc.0 <1.0.x"
"react": "^17.0.2",
"react-native": ">=0.60.0 <1.0.x"
},
"devDependencies": {
"react": "^16.9.0",
"react-native": "^0.61.5"
"react": "^17.0.2",
"react-native": "^0.66.0"
}
}

0 comments on commit cbb9695

Please sign in to comment.