Skip to content

Commit 6720f7b

Browse files
committed
fix: landscape mode check not accounting for pitch
1 parent d227d05 commit 6720f7b

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

  • android/src/main/java/com/orientationdirector/implementation

android/src/main/java/com/orientationdirector/implementation/Utils.kt

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,13 @@ class Utils(private val context: ReactContext) {
3838
//
3939
//////////////////////////////////////
4040

41+
val isPitchInLandscapeModeRange = checkIfPitchIsInLandscapeModeRange(pitchDegrees)
42+
4143
return when {
4244
rollDegrees.equals(-0f) && (pitchDegrees.equals(0f) || pitchDegrees.equals(-0f)) -> Orientation.FACE_UP
4345
rollDegrees.equals(-180f) && (pitchDegrees.equals(0f) || pitchDegrees.equals(-0f)) -> Orientation.FACE_DOWN
44-
rollDegrees in tolerance..landscapeRightLimit - tolerance -> Orientation.LANDSCAPE_RIGHT
45-
rollDegrees in landscapeLeftLimit + tolerance..-tolerance -> Orientation.LANDSCAPE_LEFT
46+
rollDegrees in tolerance..landscapeRightLimit - tolerance && isPitchInLandscapeModeRange -> Orientation.LANDSCAPE_RIGHT
47+
rollDegrees in landscapeLeftLimit + tolerance..-tolerance && isPitchInLandscapeModeRange -> Orientation.LANDSCAPE_LEFT
4648
pitchDegrees in portraitLimit..-0f -> Orientation.PORTRAIT
4749
else -> Orientation.PORTRAIT_UPSIDE_DOWN
4850
}
@@ -94,4 +96,9 @@ class Utils(private val context: ReactContext) {
9496

9597
return context.currentActivity!!.requestedOrientation;
9698
}
99+
100+
private fun checkIfPitchIsInLandscapeModeRange(pitchDegrees: Float): Boolean {
101+
val tolerance = 5f
102+
return pitchDegrees > -tolerance && pitchDegrees < tolerance
103+
}
97104
}

0 commit comments

Comments
 (0)