From 16196196f02655924d4d46049bd9dc460f3ff906 Mon Sep 17 00:00:00 2001 From: mstach60161 Date: Fri, 21 Apr 2023 10:50:02 +0200 Subject: [PATCH] Set the opposite sensor values on android to be consistent with iOS (#4368) ## Summary The sensors on Android and iOS return opposite values, which cause inconsistencies. To fix this, I modified the Android sensor listener to return opposite values. I didn't modify rotation values, because these are the same. ## Test plan - Ran each sensor and compared the values returned by both platforms - Tested an example application to confirm that the behavior of the sensors is consistent across both platforms. --- .../swmansion/reanimated/sensor/ReanimatedSensorListener.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/android/src/main/java/com/swmansion/reanimated/sensor/ReanimatedSensorListener.java b/android/src/main/java/com/swmansion/reanimated/sensor/ReanimatedSensorListener.java index 0c536e9d0e9..97280c2c5da 100644 --- a/android/src/main/java/com/swmansion/reanimated/sensor/ReanimatedSensorListener.java +++ b/android/src/main/java/com/swmansion/reanimated/sensor/ReanimatedSensorListener.java @@ -69,7 +69,9 @@ public void onSensorChanged(SensorEvent event) { }; setter.sensorSetter(data, orientationDegrees); } else { - setter.sensorSetter(event.values, orientationDegrees); + // Set the opposite values to be consistent with iOS + float[] data = new float[] {-event.values[0], -event.values[1], -event.values[2]}; + setter.sensorSetter(data, orientationDegrees); } }