From 9c38527e3d0670cb557477cc78072f8c4a9b2f26 Mon Sep 17 00:00:00 2001 From: Cristiano Coelho Date: Mon, 20 Dec 2021 14:18:49 -0300 Subject: [PATCH 01/13] code cleanup and remove deprecated method --- .../compassheading/CompassHeadingModule.java | 45 +++++++++---------- 1 file changed, 22 insertions(+), 23 deletions(-) diff --git a/android/src/main/java/com/reactlibrary/compassheading/CompassHeadingModule.java b/android/src/main/java/com/reactlibrary/compassheading/CompassHeadingModule.java index 710130c..85e7cb5 100644 --- a/android/src/main/java/com/reactlibrary/compassheading/CompassHeadingModule.java +++ b/android/src/main/java/com/reactlibrary/compassheading/CompassHeadingModule.java @@ -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; @@ -18,13 +18,13 @@ 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 @@ -32,22 +32,18 @@ public class CompassHeadingModule extends ReactContextBaseJavaModule implements 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"; @@ -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); @@ -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){ @@ -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) {} } From 1e40b61b46b72593b4d1a087bfb46555552913ea Mon Sep 17 00:00:00 2001 From: Cristiano Coelho Date: Mon, 20 Dec 2021 14:20:55 -0300 Subject: [PATCH 02/13] bump deps versions --- package.json | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index b6747a6..2dbcd8b 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "react-native-compass-heading", "title": "React Native Compass Heading", - "version": "1.2.1", + "version": "1.2.2", "description": "Listener to device's compass information.", "main": "index.js", "scripts": { @@ -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" } } From 54cdae38d720bf244ceb2945d753c7e5212050f1 Mon Sep 17 00:00:00 2001 From: Firoz Ahmed Date: Thu, 6 Jan 2022 17:48:15 +0530 Subject: [PATCH 03/13] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index c6b5447..088d168 100644 --- a/README.md +++ b/README.md @@ -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 From d0c3731b2d48f8b32dd3142bef9db935fba444b6 Mon Sep 17 00:00:00 2001 From: Firoz Ahmed Date: Thu, 6 Jan 2022 18:44:43 +0530 Subject: [PATCH 04/13] Create npm-publish.yml --- .github/workflows/npm-publish.yml | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 .github/workflows/npm-publish.yml diff --git a/.github/workflows/npm-publish.yml b/.github/workflows/npm-publish.yml new file mode 100644 index 0000000..7725047 --- /dev/null +++ b/.github/workflows/npm-publish.yml @@ -0,0 +1,22 @@ +# 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: + release: + types: [created] + +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 ci + - run: npm publish + env: + NODE_AUTH_TOKEN: ${{secrets.NODE_AUTH_TOKEN}} From adb7c378eaf7ee8ef0c25fd69950d64c447f0fc6 Mon Sep 17 00:00:00 2001 From: Firoz Ahmed Date: Thu, 6 Jan 2022 18:45:11 +0530 Subject: [PATCH 05/13] Update package.json --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 2dbcd8b..bf463c7 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "react-native-compass-heading", "title": "React Native Compass Heading", - "version": "1.2.2", + "version": "1.2.3", "description": "Listener to device's compass information.", "main": "index.js", "scripts": { From d83f7a6c3e002a4049da6c4e3e0862f8966f928c Mon Sep 17 00:00:00 2001 From: Firoz Ahmed Date: Thu, 6 Jan 2022 18:46:15 +0530 Subject: [PATCH 06/13] Update package.json --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index bf463c7..dcde63a 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "react-native-compass-heading", "title": "React Native Compass Heading", - "version": "1.2.3", + "version": "1.3.1", "description": "Listener to device's compass information.", "main": "index.js", "scripts": { From 545dc9c427da9f246c9219c44e16069a427b6c81 Mon Sep 17 00:00:00 2001 From: Firoz Ahmed Date: Thu, 6 Jan 2022 18:53:06 +0530 Subject: [PATCH 07/13] Update npm-publish.yml --- .github/workflows/npm-publish.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/npm-publish.yml b/.github/workflows/npm-publish.yml index 7725047..1d96e64 100644 --- a/.github/workflows/npm-publish.yml +++ b/.github/workflows/npm-publish.yml @@ -4,8 +4,7 @@ name: Node.js Package on: - release: - types: [created] + workflow_dispatch: jobs: publish-npm: From 41bfbe728179362cab4adb36c1dba65581a0a969 Mon Sep 17 00:00:00 2001 From: Firoz Ahmed Date: Thu, 6 Jan 2022 18:56:38 +0530 Subject: [PATCH 08/13] Update npm-publish.yml --- .github/workflows/npm-publish.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/npm-publish.yml b/.github/workflows/npm-publish.yml index 1d96e64..98a2418 100644 --- a/.github/workflows/npm-publish.yml +++ b/.github/workflows/npm-publish.yml @@ -15,7 +15,6 @@ jobs: with: node-version: 16 registry-url: https://registry.npmjs.org/ - - run: npm ci - run: npm publish env: NODE_AUTH_TOKEN: ${{secrets.NODE_AUTH_TOKEN}} From c1acd1b01e63796ee8be52be5e7209a8e5ba4d1a Mon Sep 17 00:00:00 2001 From: Firoz Ahmed Date: Thu, 6 Jan 2022 19:09:50 +0530 Subject: [PATCH 09/13] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 088d168..9514505 100644 --- a/README.md +++ b/README.md @@ -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); }); From b44543199cc8e66cc847e5743330f9e7395e372e Mon Sep 17 00:00:00 2001 From: Firoz Ahmed Date: Mon, 24 Jan 2022 19:23:38 +0530 Subject: [PATCH 10/13] Update build.gradle --- android/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/android/build.gradle b/android/build.gradle index 42faff9..07de33f 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -14,7 +14,7 @@ def safeExtGet(prop, fallback) { } apply plugin: 'com.android.library' -apply plugin: 'maven' +apply plugin: 'maven-publish' buildscript { // The Android Gradle plugin is only required when opening the android folder stand-alone. From 3c73b73413fd403a3c222f9950b25742e81987ec Mon Sep 17 00:00:00 2001 From: Firoz Ahmed Date: Mon, 24 Jan 2022 19:24:00 +0530 Subject: [PATCH 11/13] Update package.json --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index dcde63a..b68c2da 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "react-native-compass-heading", "title": "React Native Compass Heading", - "version": "1.3.1", + "version": "1.3.2", "description": "Listener to device's compass information.", "main": "index.js", "scripts": { From 0952a56efa1b4fc4d150c1c6c1446a78c5765057 Mon Sep 17 00:00:00 2001 From: Firoz Ahmed Date: Mon, 24 Jan 2022 19:40:16 +0530 Subject: [PATCH 12/13] Update build.gradle --- android/build.gradle | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/android/build.gradle b/android/build.gradle index 07de33f..7c372f0 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -129,12 +129,12 @@ afterEvaluate { project -> archives androidJavadocJar } - task installArchives(type: Upload) { - configuration = configurations.archives - repositories.mavenDeployer { - // Deploy to react-native-event-bridge/maven, ready to publish to npm - repository url: "file://${projectDir}/../android/maven" - configureReactNativePom pom - } - } +// task installArchives(type: Upload) { +// configuration = configurations.archives +// repositories.maven { +// // Deploy to react-native-event-bridge/maven, ready to publish to npm +// repository url: "file://${projectDir}/../android/maven" +// configureReactNativePom pom +// } +// } } From ce36e96259a73f6c25f93cf27b4227fe8f45ecee Mon Sep 17 00:00:00 2001 From: Firoz Ahmed Date: Mon, 24 Jan 2022 19:40:41 +0530 Subject: [PATCH 13/13] Update package.json --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index b68c2da..82fd37b 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "react-native-compass-heading", "title": "React Native Compass Heading", - "version": "1.3.2", + "version": "1.3.3", "description": "Listener to device's compass information.", "main": "index.js", "scripts": {