fix(android): align device orientation degrees#3993
Conversation
|
@ludwig-pro is attempting to deploy a commit to the Margelo Team on Vercel. A member of the Team first needs to authorize it. |
mrousavy
left a comment
There was a problem hiding this comment.
Hey - thanks for your PR!
This is much appreciated if it works, but we do testing differently. We don't test with JUnit (and adding the dependency here is not the way to go) - we test via full E2E testing on a real device via react-native-harness.
Please tell your agent to remove the JUnit tests.
Then, please add react-native-harness tests (vitest syntax). We can probably not add tests for device orientation changes as the device orientation is fixed in AWS, so if that cannot be tested with Harness then I guess there's no point in adding tests for that - then just the code is fine too.
8d40536 to
f11f303
Compare
| } | ||
|
|
||
| fun CameraOrientation.Companion.fromDeviceRotationDegrees(degrees: Int): CameraOrientation { | ||
| return CameraOrientation.fromDegrees(degrees).counterRotated() |
There was a problem hiding this comment.
But is it even correct for interface orientation then? Do we also counterRotate that or no
There was a problem hiding this comment.
Yeah, device and interface are a bit counter-intuitive because they don’t describe the same thing:
devicedescribes how the phone is physically rotated, based onOrientationEventListener.interfacedescribes how the UI/display is rotated, based onDisplay.rotation/Surface.ROTATION_*.
So when the phone is physically rotated -90°, device reports left, but the UI needs to rotate +90° to stay readable, so interface reports right.
That’s why I think we should only apply counterRotated() on the device-orientation path, and leave interface orientation as-is.
There was a problem hiding this comment.
Do you think it’s worth adding a small note to the docs?
Basically: device is the physical rotation from OrientationEventListener, while interface is the UI/display rotation from Display.rotation / Surface.ROTATION_*, so they can be opposite when the UI counter-rotates to stay readable ?
f11f303 to
bf5c0ae
Compare

What
Align Android device-orientation degree mapping with the physical
CameraOrientationsemantics used by iOS.OrientationEventListenerreports physical device rotation degrees, butHybridDeviceOrientationManagerpreviously reusedCameraOrientation.fromDegrees(...), which maps 90°/270° for buffer/image orientation semantics.This caused Android
createOrientationManager('device')to reportleft/rightmirrored compared to iOS for the same physical device pose.This PR now applies the existing image/frame orientation mapper and counter-rotates it directly at the Android device-orientation callsite with
fromDegrees(degrees).counterRotated(), leaving the existingfromDegrees(...)behavior unchanged for image/frame paths.Test plan
useOrientation('device')reports the right orientationrg -n "junit|CameraOrientationDeviceRotationDegreesTest" packages/react-native-vision-camera/androidcd apps/simple-camera/android && ./gradlew :react-native-vision-camera:compileDebugKotlin --console=plainRecord
Before
After