@@ -26,6 +26,7 @@ class Utils(private val context: ReactContext) {
2626 val rollDegrees = Math .toDegrees(rollRadians.toDouble()).toFloat()
2727
2828 // This is needed to account for inaccuracy due to subtle movements such as tilting
29+ val pitchTolerance = 5f
2930 val tolerance = 20f
3031
3132 // ////////////////////////////////////
@@ -38,14 +39,14 @@ class Utils(private val context: ReactContext) {
3839 //
3940 // ////////////////////////////////////
4041
41- val isPitchInLandscapeModeRange = checkIfPitchIsInLandscapeModeRange(pitchDegrees)
42+ val isPitchInLandscapeModeRange = checkIfPitchIsInLandscapeModeRange(pitchDegrees, pitchTolerance )
4243
4344 return when {
4445 rollDegrees.equals(- 0f ) && (pitchDegrees.equals(0f ) || pitchDegrees.equals(- 0f )) -> Orientation .FACE_UP
4546 rollDegrees.equals(- 180f ) && (pitchDegrees.equals(0f ) || pitchDegrees.equals(- 0f )) -> Orientation .FACE_DOWN
4647 rollDegrees in tolerance.. landscapeRightLimit - tolerance && isPitchInLandscapeModeRange -> Orientation .LANDSCAPE_RIGHT
4748 rollDegrees in landscapeLeftLimit + tolerance.. - tolerance && isPitchInLandscapeModeRange -> Orientation .LANDSCAPE_LEFT
48- pitchDegrees in portraitLimit.. - 0f -> Orientation .PORTRAIT
49+ pitchDegrees in portraitLimit.. pitchTolerance -> Orientation .PORTRAIT
4950 else -> Orientation .PORTRAIT_UPSIDE_DOWN
5051 }
5152 }
@@ -97,8 +98,7 @@ class Utils(private val context: ReactContext) {
9798 return context.currentActivity!! .requestedOrientation;
9899 }
99100
100- private fun checkIfPitchIsInLandscapeModeRange (pitchDegrees : Float ): Boolean {
101- val tolerance = 5f
101+ private fun checkIfPitchIsInLandscapeModeRange (pitchDegrees : Float , tolerance : Float ): Boolean {
102102 return pitchDegrees > - tolerance && pitchDegrees < tolerance
103103 }
104104}
0 commit comments