react-native-orientation-director 2.5.0 → 2.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (136) hide show
  1. package/android/src/main/java/com/orientationdirector/implementation/OrientationSensorsEventListener.kt +69 -19
  2. package/android/src/main/java/com/orientationdirector/implementation/Utils.kt +33 -6
  3. package/ios/implementation/OrientationDirectorImpl.swift +18 -2
  4. package/ios/implementation/Utils.swift +15 -0
  5. package/lib/commonjs/EventEmitter.js +48 -0
  6. package/lib/commonjs/NativeOrientationDirector.js +8 -0
  7. package/lib/commonjs/RNOrientationDirector.js +126 -0
  8. package/lib/commonjs/hooks/useDeviceOrientation.hook.js +37 -0
  9. package/lib/commonjs/hooks/useInterfaceOrientation.hook.js +37 -0
  10. package/lib/commonjs/hooks/useIsInterfaceOrientationLocked.hook.js +27 -0
  11. package/lib/commonjs/index.js +51 -0
  12. package/lib/commonjs/module.js +22 -0
  13. package/lib/commonjs/package.json +1 -0
  14. package/lib/commonjs/types/AutoRotation.enum.js +12 -0
  15. package/lib/commonjs/types/Event.enum.js +13 -0
  16. package/lib/commonjs/types/HumanReadableAutoRotationsResource.type.js +5 -0
  17. package/lib/commonjs/types/HumanReadableOrientationsResource.type.js +5 -0
  18. package/lib/commonjs/types/LockableOrientation.type.js +5 -0
  19. package/lib/commonjs/types/LockedEvent.interface.js +1 -0
  20. package/lib/commonjs/types/Orientation.enum.js +17 -0
  21. package/lib/commonjs/types/OrientationEvent.interface.js +5 -0
  22. package/lib/commonjs/types/OrientationType.enum.js +11 -0
  23. package/lib/typescript/commonjs/example/src/App.d.ts +2 -0
  24. package/lib/typescript/commonjs/example/src/App.d.ts.map +1 -0
  25. package/lib/typescript/commonjs/example/src/AppNavigationContainer.d.ts +3 -0
  26. package/lib/typescript/commonjs/example/src/AppNavigationContainer.d.ts.map +1 -0
  27. package/lib/typescript/commonjs/example/src/screens/Explore.d.ts +3 -0
  28. package/lib/typescript/commonjs/example/src/screens/Explore.d.ts.map +1 -0
  29. package/lib/typescript/commonjs/example/src/screens/Home.d.ts +3 -0
  30. package/lib/typescript/commonjs/example/src/screens/Home.d.ts.map +1 -0
  31. package/lib/typescript/commonjs/example/src/screens/InnerExplore.d.ts +3 -0
  32. package/lib/typescript/commonjs/example/src/screens/InnerExplore.d.ts.map +1 -0
  33. package/lib/typescript/commonjs/example/src/screens/styles.d.ts +51 -0
  34. package/lib/typescript/commonjs/example/src/screens/styles.d.ts.map +1 -0
  35. package/lib/typescript/commonjs/package.json +1 -0
  36. package/lib/typescript/commonjs/src/EventEmitter.d.ts.map +1 -0
  37. package/lib/typescript/commonjs/src/NativeOrientationDirector.d.ts.map +1 -0
  38. package/lib/typescript/commonjs/src/RNOrientationDirector.d.ts.map +1 -0
  39. package/lib/typescript/commonjs/src/hooks/useDeviceOrientation.hook.d.ts.map +1 -0
  40. package/lib/typescript/commonjs/src/hooks/useInterfaceOrientation.hook.d.ts.map +1 -0
  41. package/lib/typescript/commonjs/src/hooks/useIsInterfaceOrientationLocked.hook.d.ts.map +1 -0
  42. package/lib/typescript/commonjs/src/index.d.ts.map +1 -0
  43. package/lib/typescript/commonjs/src/module.d.ts.map +1 -0
  44. package/lib/typescript/commonjs/src/types/AutoRotation.enum.d.ts.map +1 -0
  45. package/lib/typescript/commonjs/src/types/Event.enum.d.ts.map +1 -0
  46. package/lib/typescript/commonjs/src/types/HumanReadableAutoRotationsResource.type.d.ts.map +1 -0
  47. package/lib/typescript/commonjs/src/types/HumanReadableOrientationsResource.type.d.ts.map +1 -0
  48. package/lib/typescript/commonjs/src/types/LockableOrientation.type.d.ts.map +1 -0
  49. package/lib/typescript/commonjs/src/types/LockedEvent.interface.d.ts.map +1 -0
  50. package/lib/typescript/commonjs/src/types/Orientation.enum.d.ts.map +1 -0
  51. package/lib/typescript/commonjs/src/types/OrientationEvent.interface.d.ts.map +1 -0
  52. package/lib/typescript/commonjs/src/types/OrientationType.enum.d.ts.map +1 -0
  53. package/lib/typescript/module/example/src/App.d.ts +2 -0
  54. package/lib/typescript/module/example/src/App.d.ts.map +1 -0
  55. package/lib/typescript/module/example/src/AppNavigationContainer.d.ts +3 -0
  56. package/lib/typescript/module/example/src/AppNavigationContainer.d.ts.map +1 -0
  57. package/lib/typescript/module/example/src/screens/Explore.d.ts +3 -0
  58. package/lib/typescript/module/example/src/screens/Explore.d.ts.map +1 -0
  59. package/lib/typescript/module/example/src/screens/Home.d.ts +3 -0
  60. package/lib/typescript/module/example/src/screens/Home.d.ts.map +1 -0
  61. package/lib/typescript/module/example/src/screens/InnerExplore.d.ts +3 -0
  62. package/lib/typescript/module/example/src/screens/InnerExplore.d.ts.map +1 -0
  63. package/lib/typescript/module/example/src/screens/styles.d.ts +51 -0
  64. package/lib/typescript/module/example/src/screens/styles.d.ts.map +1 -0
  65. package/lib/typescript/module/src/EventEmitter.d.ts +11 -0
  66. package/lib/typescript/module/src/EventEmitter.d.ts.map +1 -0
  67. package/lib/typescript/module/src/NativeOrientationDirector.d.ts +17 -0
  68. package/lib/typescript/module/src/NativeOrientationDirector.d.ts.map +1 -0
  69. package/lib/typescript/module/src/RNOrientationDirector.d.ts +62 -0
  70. package/lib/typescript/module/src/RNOrientationDirector.d.ts.map +1 -0
  71. package/lib/typescript/module/src/hooks/useDeviceOrientation.hook.d.ts +8 -0
  72. package/lib/typescript/module/src/hooks/useDeviceOrientation.hook.d.ts.map +1 -0
  73. package/lib/typescript/module/src/hooks/useInterfaceOrientation.hook.d.ts +8 -0
  74. package/lib/typescript/module/src/hooks/useInterfaceOrientation.hook.d.ts.map +1 -0
  75. package/lib/typescript/module/src/hooks/useIsInterfaceOrientationLocked.hook.d.ts +7 -0
  76. package/lib/typescript/module/src/hooks/useIsInterfaceOrientationLocked.hook.d.ts.map +1 -0
  77. package/lib/typescript/module/src/index.d.ts +12 -0
  78. package/lib/typescript/module/src/index.d.ts.map +1 -0
  79. package/lib/typescript/module/src/module.d.ts +6 -0
  80. package/lib/typescript/module/src/module.d.ts.map +1 -0
  81. package/lib/typescript/module/src/types/AutoRotation.enum.d.ts +6 -0
  82. package/lib/typescript/module/src/types/AutoRotation.enum.d.ts.map +1 -0
  83. package/lib/typescript/module/src/types/Event.enum.d.ts +7 -0
  84. package/lib/typescript/module/src/types/Event.enum.d.ts.map +1 -0
  85. package/lib/typescript/module/src/types/HumanReadableAutoRotationsResource.type.d.ts +3 -0
  86. package/lib/typescript/module/src/types/HumanReadableAutoRotationsResource.type.d.ts.map +1 -0
  87. package/lib/typescript/module/src/types/HumanReadableOrientationsResource.type.d.ts +3 -0
  88. package/lib/typescript/module/src/types/HumanReadableOrientationsResource.type.d.ts.map +1 -0
  89. package/lib/typescript/module/src/types/LockableOrientation.type.d.ts +3 -0
  90. package/lib/typescript/module/src/types/LockableOrientation.type.d.ts.map +1 -0
  91. package/lib/typescript/module/src/types/LockedEvent.interface.d.ts +4 -0
  92. package/lib/typescript/module/src/types/LockedEvent.interface.d.ts.map +1 -0
  93. package/lib/typescript/module/src/types/Orientation.enum.d.ts +11 -0
  94. package/lib/typescript/module/src/types/Orientation.enum.d.ts.map +1 -0
  95. package/lib/typescript/module/src/types/OrientationEvent.interface.d.ts +5 -0
  96. package/lib/typescript/module/src/types/OrientationEvent.interface.d.ts.map +1 -0
  97. package/lib/typescript/module/src/types/OrientationType.enum.d.ts +5 -0
  98. package/lib/typescript/module/src/types/OrientationType.enum.d.ts.map +1 -0
  99. package/package.json +32 -13
  100. package/plugin/build/withRNOrientationAppDelegate.d.ts +1 -1
  101. package/plugin/build/withRNOrientationAppDelegate.js +20 -6
  102. package/lib/typescript/src/EventEmitter.d.ts.map +0 -1
  103. package/lib/typescript/src/NativeOrientationDirector.d.ts.map +0 -1
  104. package/lib/typescript/src/RNOrientationDirector.d.ts.map +0 -1
  105. package/lib/typescript/src/hooks/useDeviceOrientation.hook.d.ts.map +0 -1
  106. package/lib/typescript/src/hooks/useInterfaceOrientation.hook.d.ts.map +0 -1
  107. package/lib/typescript/src/hooks/useIsInterfaceOrientationLocked.hook.d.ts.map +0 -1
  108. package/lib/typescript/src/index.d.ts.map +0 -1
  109. package/lib/typescript/src/module.d.ts.map +0 -1
  110. package/lib/typescript/src/types/AutoRotation.enum.d.ts.map +0 -1
  111. package/lib/typescript/src/types/Event.enum.d.ts.map +0 -1
  112. package/lib/typescript/src/types/HumanReadableAutoRotationsResource.type.d.ts.map +0 -1
  113. package/lib/typescript/src/types/HumanReadableOrientationsResource.type.d.ts.map +0 -1
  114. package/lib/typescript/src/types/LockableOrientation.type.d.ts.map +0 -1
  115. package/lib/typescript/src/types/LockedEvent.interface.d.ts.map +0 -1
  116. package/lib/typescript/src/types/Orientation.enum.d.ts.map +0 -1
  117. package/lib/typescript/src/types/OrientationEvent.interface.d.ts.map +0 -1
  118. package/lib/typescript/src/types/OrientationType.enum.d.ts.map +0 -1
  119. /package/lib/typescript/{src → commonjs/src}/EventEmitter.d.ts +0 -0
  120. /package/lib/typescript/{src → commonjs/src}/NativeOrientationDirector.d.ts +0 -0
  121. /package/lib/typescript/{src → commonjs/src}/RNOrientationDirector.d.ts +0 -0
  122. /package/lib/typescript/{src → commonjs/src}/hooks/useDeviceOrientation.hook.d.ts +0 -0
  123. /package/lib/typescript/{src → commonjs/src}/hooks/useInterfaceOrientation.hook.d.ts +0 -0
  124. /package/lib/typescript/{src → commonjs/src}/hooks/useIsInterfaceOrientationLocked.hook.d.ts +0 -0
  125. /package/lib/typescript/{src → commonjs/src}/index.d.ts +0 -0
  126. /package/lib/typescript/{src → commonjs/src}/module.d.ts +0 -0
  127. /package/lib/typescript/{src → commonjs/src}/types/AutoRotation.enum.d.ts +0 -0
  128. /package/lib/typescript/{src → commonjs/src}/types/Event.enum.d.ts +0 -0
  129. /package/lib/typescript/{src → commonjs/src}/types/HumanReadableAutoRotationsResource.type.d.ts +0 -0
  130. /package/lib/typescript/{src → commonjs/src}/types/HumanReadableOrientationsResource.type.d.ts +0 -0
  131. /package/lib/typescript/{src → commonjs/src}/types/LockableOrientation.type.d.ts +0 -0
  132. /package/lib/typescript/{src → commonjs/src}/types/LockedEvent.interface.d.ts +0 -0
  133. /package/lib/typescript/{src → commonjs/src}/types/Orientation.enum.d.ts +0 -0
  134. /package/lib/typescript/{src → commonjs/src}/types/OrientationEvent.interface.d.ts +0 -0
  135. /package/lib/typescript/{src → commonjs/src}/types/OrientationType.enum.d.ts +0 -0
  136. /package/lib/typescript/{package.json → module/package.json} +0 -0
@@ -10,12 +10,20 @@ import com.facebook.react.bridge.ReactApplicationContext
10
10
  class OrientationSensorsEventListener(
11
11
  context: ReactApplicationContext,
12
12
  ) : SensorEventListener {
13
- private var mSensorManager: SensorManager = context.getSystemService(SENSOR_SERVICE) as SensorManager
13
+ private var mSensorManager: SensorManager =
14
+ context.getSystemService(SENSOR_SERVICE) as SensorManager
14
15
 
15
- private var mAccelerometerSensor: Sensor? = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER)
16
- private var mMagneticFieldSensor: Sensor? = mSensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD)
16
+ private var mRotationSensor: Sensor? =
17
+ mSensorManager.getDefaultSensor(Sensor.TYPE_ROTATION_VECTOR)
18
+ private var mAccelerometerSensor: Sensor? =
19
+ mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER)
20
+ private var mMagneticFieldSensor: Sensor? =
21
+ mSensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD)
17
22
 
18
- private var hasRequiredSensors: Boolean = mAccelerometerSensor != null && mMagneticFieldSensor != null
23
+ private var hasRotationSensor: Boolean =
24
+ mRotationSensor != null
25
+ private var hasAccelerometerAndMagneticFieldSensors: Boolean =
26
+ mAccelerometerSensor != null && mMagneticFieldSensor != null
19
27
 
20
28
  private val accelerometerReading = FloatArray(3)
21
29
  private val magnetometerReading = FloatArray(3)
@@ -32,6 +40,59 @@ class OrientationSensorsEventListener(
32
40
  return
33
41
  }
34
42
 
43
+ if (event.sensor.type == Sensor.TYPE_ROTATION_VECTOR) {
44
+ computeOrientationFromRotationSensor(event.values);
45
+ return
46
+ }
47
+
48
+ computeOrientationFromOtherSensors(event)
49
+ }
50
+
51
+ override fun onAccuracyChanged(sensor: Sensor?, accuracy: Int) {}
52
+
53
+ fun enable() {
54
+ if (hasRotationSensor) {
55
+ mSensorManager.registerListener(
56
+ this,
57
+ mRotationSensor,
58
+ SensorManager.SENSOR_DELAY_NORMAL,
59
+ SensorManager.SENSOR_DELAY_UI
60
+ )
61
+ return
62
+ }
63
+
64
+ if (hasAccelerometerAndMagneticFieldSensors) {
65
+ mSensorManager.registerListener(
66
+ this,
67
+ mAccelerometerSensor,
68
+ SensorManager.SENSOR_DELAY_NORMAL,
69
+ SensorManager.SENSOR_DELAY_UI
70
+ )
71
+ mSensorManager.registerListener(
72
+ this,
73
+ mMagneticFieldSensor,
74
+ SensorManager.SENSOR_DELAY_NORMAL,
75
+ SensorManager.SENSOR_DELAY_UI
76
+ )
77
+ return
78
+ }
79
+ }
80
+
81
+ fun disable() {
82
+ mSensorManager.unregisterListener(this)
83
+ }
84
+
85
+ private fun computeOrientationFromRotationSensor(values: FloatArray) {
86
+ val rotationMatrix = FloatArray(9)
87
+ SensorManager.getRotationMatrixFromVector(rotationMatrix, values)
88
+
89
+ val orientationAngles = FloatArray(3)
90
+ SensorManager.getOrientation(rotationMatrix, orientationAngles)
91
+
92
+ notifyOrientationAnglesChanged(orientationAngles)
93
+ }
94
+
95
+ private fun computeOrientationFromOtherSensors(event: SensorEvent) {
35
96
  if (event.sensor.type == Sensor.TYPE_ACCELEROMETER) {
36
97
  System.arraycopy(event.values, 0, accelerometerReading, 0, accelerometerReading.size)
37
98
  }
@@ -54,6 +115,10 @@ class OrientationSensorsEventListener(
54
115
  val orientationAngles = FloatArray(3)
55
116
  SensorManager.getOrientation(rotationMatrix, orientationAngles)
56
117
 
118
+ notifyOrientationAnglesChanged(orientationAngles)
119
+ }
120
+
121
+ private fun notifyOrientationAnglesChanged(orientationAngles: FloatArray) {
57
122
  if (lastComputedOrientationAngles.contentEquals(orientationAngles)) {
58
123
  return
59
124
  }
@@ -61,19 +126,4 @@ class OrientationSensorsEventListener(
61
126
  onOrientationAnglesChangedCallback?.invoke(orientationAngles)
62
127
  lastComputedOrientationAngles = orientationAngles
63
128
  }
64
-
65
- override fun onAccuracyChanged(sensor: Sensor?, accuracy: Int) {}
66
-
67
- fun enable() {
68
- if (!hasRequiredSensors) {
69
- return
70
- }
71
-
72
- mSensorManager.registerListener(this, mAccelerometerSensor, SensorManager.SENSOR_DELAY_NORMAL)
73
- mSensorManager.registerListener(this, mMagneticFieldSensor, SensorManager.SENSOR_DELAY_NORMAL)
74
- }
75
-
76
- fun disable() {
77
- mSensorManager.unregisterListener(this)
78
- }
79
129
  }
@@ -26,7 +26,9 @@ class Utils(private val context: ReactContext) {
26
26
  val rollDegrees = Math.toDegrees(rollRadians.toDouble()).toFloat()
27
27
 
28
28
  // This is needed to account for inaccuracy due to subtle movements such as tilting
29
- val tolerance = 20f
29
+ val pitchToleranceDefault = 5f
30
+ val rollTolerance = 0f
31
+ val toleranceForFaceUpOrDown = 5f;
30
32
 
31
33
  //////////////////////////////////////
32
34
  // These limits are set based on SensorManager.getOrientation reference
@@ -38,12 +40,17 @@ class Utils(private val context: ReactContext) {
38
40
  //
39
41
  //////////////////////////////////////
40
42
 
43
+ val isPitchInLandscapeModeRange =
44
+ checkIfValueIsBetweenTolerance(pitchDegrees, pitchToleranceDefault)
45
+ val isPitchCloseToFaceUpOrDown =
46
+ checkIfValueIsBetweenTolerance(pitchDegrees, toleranceForFaceUpOrDown)
47
+
41
48
  return when {
42
- rollDegrees.equals(-0f) && (pitchDegrees.equals(0f) || pitchDegrees.equals(-0f)) -> Orientation.FACE_UP
43
- 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
- pitchDegrees in portraitLimit..-0f -> Orientation.PORTRAIT
49
+ checkIfRollIsCloseToFaceUp(rollDegrees) && isPitchCloseToFaceUpOrDown -> Orientation.FACE_UP
50
+ checkIfRollIsCloseToFaceDown(rollDegrees) && isPitchCloseToFaceUpOrDown -> Orientation.FACE_DOWN
51
+ rollDegrees in rollTolerance..landscapeRightLimit - rollTolerance && isPitchInLandscapeModeRange -> Orientation.LANDSCAPE_RIGHT
52
+ rollDegrees in landscapeLeftLimit + rollTolerance..-rollTolerance && isPitchInLandscapeModeRange -> Orientation.LANDSCAPE_LEFT
53
+ pitchDegrees in portraitLimit..pitchToleranceDefault -> Orientation.PORTRAIT
47
54
  else -> Orientation.PORTRAIT_UPSIDE_DOWN
48
55
  }
49
56
  }
@@ -94,4 +101,24 @@ class Utils(private val context: ReactContext) {
94
101
 
95
102
  return context.currentActivity!!.requestedOrientation;
96
103
  }
104
+
105
+ private fun checkIfValueIsBetweenTolerance(value: Float, tolerance: Float): Boolean {
106
+ return value > -tolerance && value < tolerance
107
+ }
108
+
109
+ private fun checkIfRollIsCloseToFaceDown(value: Float): Boolean {
110
+ val landscapeLimit = 180f
111
+ val faceDownLimit = 170f
112
+
113
+ return value in faceDownLimit..landscapeLimit ||
114
+ value in -landscapeLimit..-faceDownLimit;
115
+ }
116
+
117
+ private fun checkIfRollIsCloseToFaceUp(value: Float): Boolean {
118
+ val landscapeLimit = 0f
119
+ val faceUpLimit = 10f
120
+
121
+ return value in landscapeLimit..faceUpLimit ||
122
+ value in -faceUpLimit..-landscapeLimit
123
+ }
97
124
  }
@@ -19,6 +19,13 @@ import UIKit
19
19
  private var lastInterfaceOrientation = Orientation.UNKNOWN
20
20
  private var lastDeviceOrientation = Orientation.UNKNOWN
21
21
  private var isLocked = false
22
+
23
+ /// # Only on iOS < 16
24
+ /// This variable is needed to prevent a loop where
25
+ /// we lock the interface to a specific orientation
26
+ /// and the sensor picks it up, therefore triggering
27
+ /// the orientation did change event.
28
+ private var isLocking = false
22
29
 
23
30
  @objc public var supportedInterfaceOrientations: UIInterfaceOrientationMask = UIInterfaceOrientationMask.all
24
31
 
@@ -56,6 +63,7 @@ import UIKit
56
63
  }
57
64
 
58
65
  @objc public func lockTo(jsValue: NSNumber) {
66
+ self.isLocking = true;
59
67
  let jsOrientation = utils.convertToOrientationFrom(jsValue: jsValue)
60
68
  let mask = utils.convertToMaskFrom(jsOrientation: jsOrientation)
61
69
  self.requestInterfaceUpdateTo(mask: mask)
@@ -65,17 +73,20 @@ import UIKit
65
73
  let orientationCanBeUpdatedDirectly = jsOrientation != Orientation.LANDSCAPE
66
74
  if orientationCanBeUpdatedDirectly {
67
75
  updateLastInterfaceOrientationTo(value: jsOrientation)
76
+ self.isLocking = false;
68
77
  return
69
78
  }
70
79
 
71
80
  let lastInterfaceOrientationIsAlreadyInLandscape = lastInterfaceOrientation == Orientation.LANDSCAPE_RIGHT || lastInterfaceOrientation == Orientation.LANDSCAPE_LEFT
72
81
  if lastInterfaceOrientationIsAlreadyInLandscape {
73
82
  updateLastInterfaceOrientationTo(value: lastInterfaceOrientation)
83
+ self.isLocking = false;
74
84
  return
75
85
  }
76
86
 
77
87
  let systemDefaultLandscapeOrientation = Orientation.LANDSCAPE_RIGHT
78
88
  updateLastInterfaceOrientationTo(value: systemDefaultLandscapeOrientation)
89
+ self.isLocking = false;
79
90
  }
80
91
 
81
92
  @objc public func unlock() {
@@ -155,14 +166,19 @@ import UIKit
155
166
  print("\(OrientationDirectorImpl.TAG) - requestGeometryUpdate error", error)
156
167
  }
157
168
  } else {
158
- UIDevice.current.setValue(mask.rawValue, forKey: "orientation")
169
+ let interfaceOrientation = self.utils.convertToInterfaceOrientationFrom(mask: mask)
170
+ UIDevice.current.setValue(interfaceOrientation.rawValue, forKey: "orientation")
159
171
  UIViewController.attemptRotationToDeviceOrientation()
160
172
  }
161
173
  }
162
174
 
163
175
  private func onOrientationChanged(uiDeviceOrientation: UIDeviceOrientation) {
164
176
  let deviceOrientation = utils.convertToOrientationFrom(deviceOrientation: uiDeviceOrientation)
165
- self.eventManager.sendDeviceOrientationDidChange(orientationValue: deviceOrientation.rawValue)
177
+
178
+ if (!self.isLocking) {
179
+ self.eventManager.sendDeviceOrientationDidChange(orientationValue: deviceOrientation.rawValue)
180
+ }
181
+
166
182
  lastDeviceOrientation = deviceOrientation
167
183
  adaptInterfaceTo(deviceOrientation: deviceOrientation)
168
184
  }
@@ -78,6 +78,21 @@ class Utils {
78
78
  }
79
79
  }
80
80
 
81
+ public func convertToInterfaceOrientationFrom(mask: UIInterfaceOrientationMask) -> UIInterfaceOrientation {
82
+ switch mask {
83
+ case .portrait:
84
+ return .portrait
85
+ case .landscapeRight:
86
+ return .landscapeRight
87
+ case .portraitUpsideDown:
88
+ return .portraitUpsideDown
89
+ case .landscapeLeft:
90
+ return .landscapeLeft
91
+ default:
92
+ return .unknown
93
+ }
94
+ }
95
+
81
96
  public func getInterfaceOrientation() -> UIInterfaceOrientation {
82
97
  guard let windowScene = self.getCurrentWindow()?.windowScene else {
83
98
  return UIInterfaceOrientation.unknown
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var _reactNative = require("react-native");
8
+ var _module = _interopRequireWildcard(require("./module.js"));
9
+ var _EventEnum = _interopRequireDefault(require("./types/Event.enum.js"));
10
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
11
+ function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
12
+ class EventEmitter {
13
+ static addDeviceOrientationDidChangeListener(callback) {
14
+ let listener = _module.ModuleEventEmitter.addListener(_EventEnum.default.DeviceOrientationDidChange, callback);
15
+ if (_reactNative.Platform.OS !== 'android') {
16
+ return listener;
17
+ }
18
+ const listenerCount = _module.ModuleEventEmitter.listenerCount(_EventEnum.default.DeviceOrientationDidChange);
19
+ if (listenerCount === 1) {
20
+ _module.default.enableOrientationSensors();
21
+ }
22
+ return EventEmitter.createDeviceOrientationListenerProxy(listener);
23
+ }
24
+ static addInterfaceOrientationDidChangeListener(callback) {
25
+ return _module.ModuleEventEmitter.addListener(_EventEnum.default.InterfaceOrientationDidChange, callback);
26
+ }
27
+ static addLockDidChangeListener(callback) {
28
+ return _module.ModuleEventEmitter.addListener(_EventEnum.default.LockDidChange, callback);
29
+ }
30
+ static createDeviceOrientationListenerProxy(listener) {
31
+ const handler = {
32
+ get(target, propertyKey, receiver) {
33
+ if (propertyKey === 'remove') {
34
+ disableOrientationSensorsIfLastListener();
35
+ }
36
+ return Reflect.get(target, propertyKey, receiver);
37
+ }
38
+ };
39
+ return new Proxy(listener, handler);
40
+ function disableOrientationSensorsIfLastListener() {
41
+ const listenerCount = _module.ModuleEventEmitter.listenerCount(_EventEnum.default.DeviceOrientationDidChange);
42
+ if (listenerCount === 1) {
43
+ _module.default.disableOrientationSensors();
44
+ }
45
+ }
46
+ }
47
+ }
48
+ var _default = exports.default = EventEmitter;
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var _reactNative = require("react-native");
8
+ var _default = exports.default = _reactNative.TurboModuleRegistry.getEnforcing('OrientationDirector');
@@ -0,0 +1,126 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var _reactNative = require("react-native");
8
+ var _module = _interopRequireDefault(require("./module.js"));
9
+ var _OrientationEnum = require("./types/Orientation.enum.js");
10
+ var _AutoRotationEnum = require("./types/AutoRotation.enum.js");
11
+ var _OrientationTypeEnum = require("./types/OrientationType.enum.js");
12
+ var _EventEmitter = _interopRequireDefault(require("./EventEmitter.js"));
13
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
14
+ class RNOrientationDirector {
15
+ static _humanReadableOrientationsResource = {
16
+ [_OrientationEnum.Orientation.unknown]: 'Unknown',
17
+ [_OrientationEnum.Orientation.portrait]: 'Portrait',
18
+ [_OrientationEnum.Orientation.portraitUpsideDown]: 'Portrait Upside Down',
19
+ [_OrientationEnum.Orientation.landscapeLeft]: 'Landscape Left',
20
+ [_OrientationEnum.Orientation.landscapeRight]: 'Landscape Right',
21
+ [_OrientationEnum.Orientation.landscape]: 'Landscape',
22
+ [_OrientationEnum.Orientation.faceUp]: 'Face Up',
23
+ [_OrientationEnum.Orientation.faceDown]: 'Face Down'
24
+ };
25
+ static _humanReadableAutoRotationsResource = {
26
+ [_AutoRotationEnum.AutoRotation.unknown]: 'Unknown',
27
+ [_AutoRotationEnum.AutoRotation.enabled]: 'Enabled',
28
+ [_AutoRotationEnum.AutoRotation.disabled]: 'Disabled'
29
+ };
30
+ setHumanReadableOrientations(resource) {
31
+ RNOrientationDirector._humanReadableOrientationsResource = resource;
32
+ }
33
+ setHumanReadableAutoRotations(resource) {
34
+ RNOrientationDirector._humanReadableAutoRotationsResource = resource;
35
+ }
36
+ static getInterfaceOrientation() {
37
+ return _module.default.getInterfaceOrientation();
38
+ }
39
+ static getDeviceOrientation() {
40
+ return _module.default.getDeviceOrientation();
41
+ }
42
+
43
+ /**
44
+ * Please be aware that device orientation is not the
45
+ * same as interface orientation.
46
+ *
47
+ * Specifically, landscape left and right are inverted:
48
+ *
49
+ * - landscapeLeft in device orientation is landscapeRight in interface orientation
50
+ * - landscapeRight in device orientation is landscapeLeft in interface orientation
51
+ *
52
+ * This is a behavior of the native API.
53
+ *
54
+ * When you pass an orientation value, do provide orientationType
55
+ * as well if the orientation value is not an interface orientation.
56
+ * Example: when using listenForDeviceOrientationChanges.
57
+ *
58
+ * @param orientation any lockable orientation enum value
59
+ * @param orientationType any orientation type enum value
60
+ */
61
+ static lockTo(orientation, orientationType = _OrientationTypeEnum.OrientationType.interface) {
62
+ if (orientationType === _OrientationTypeEnum.OrientationType.interface) {
63
+ _module.default.lockTo(orientation);
64
+ return;
65
+ }
66
+ if (orientation === _OrientationEnum.Orientation.landscapeLeft) {
67
+ _module.default.lockTo(_OrientationEnum.Orientation.landscapeRight);
68
+ return;
69
+ }
70
+ if (orientation === _OrientationEnum.Orientation.landscapeRight) {
71
+ _module.default.lockTo(_OrientationEnum.Orientation.landscapeLeft);
72
+ return;
73
+ }
74
+ _module.default.lockTo(orientation);
75
+ }
76
+ static unlock() {
77
+ _module.default.unlock();
78
+ }
79
+ static isLocked() {
80
+ return _module.default.isLocked();
81
+ }
82
+ static isAutoRotationEnabled() {
83
+ if (_reactNative.Platform.OS !== 'android') {
84
+ return _AutoRotationEnum.AutoRotation.unknown;
85
+ }
86
+ return _module.default.isAutoRotationEnabled() ? _AutoRotationEnum.AutoRotation.enabled : _AutoRotationEnum.AutoRotation.disabled;
87
+ }
88
+ static resetSupportedInterfaceOrientations() {
89
+ _module.default.resetSupportedInterfaceOrientations();
90
+ }
91
+ static listenForDeviceOrientationChanges(callback) {
92
+ return _EventEmitter.default.addDeviceOrientationDidChangeListener(callback);
93
+ }
94
+ static listenForInterfaceOrientationChanges(callback) {
95
+ return _EventEmitter.default.addInterfaceOrientationDidChangeListener(callback);
96
+ }
97
+ static listenForLockChanges(callback) {
98
+ return _EventEmitter.default.addLockDidChangeListener(callback);
99
+ }
100
+ static convertOrientationToHumanReadableString(orientation) {
101
+ return RNOrientationDirector._humanReadableOrientationsResource[orientation];
102
+ }
103
+ static convertAutoRotationToHumanReadableString(autoRotation) {
104
+ return RNOrientationDirector._humanReadableAutoRotationsResource[autoRotation];
105
+ }
106
+
107
+ /**
108
+ * This method checks if the given orientation is lockable
109
+ * by interface perspective.
110
+ *
111
+ * All orientations are lockable except for unknown, faceUp
112
+ * and faceDown.
113
+ *
114
+ * This method is useful when you want to lock the interface
115
+ * orientation from a given device orientation.
116
+ *
117
+ * Example: with listenForDeviceOrientationChanges
118
+ *
119
+ * @param orientation any orientation enum value
120
+ * @returns true if the orientation is lockable
121
+ */
122
+ static isLockableOrientation(orientation) {
123
+ return !(orientation === _OrientationEnum.Orientation.unknown || orientation === _OrientationEnum.Orientation.faceUp || orientation === _OrientationEnum.Orientation.faceDown);
124
+ }
125
+ }
126
+ var _default = exports.default = RNOrientationDirector;
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var _react = _interopRequireWildcard(require("react"));
8
+ var _RNOrientationDirector = _interopRequireDefault(require("../RNOrientationDirector.js"));
9
+ var _OrientationEnum = require("../types/Orientation.enum.js");
10
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
11
+ function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
12
+ /**
13
+ * Hook that returns the current device orientation.
14
+ * It listens for orientation changes and updates the state accordingly.
15
+ */
16
+ const useDeviceOrientation = () => {
17
+ const initialRender = (0, _react.useRef)(false);
18
+ const [orientation, setOrientation] = _react.default.useState(_OrientationEnum.Orientation.unknown);
19
+ _react.default.useEffect(() => {
20
+ if (initialRender.current) {
21
+ return;
22
+ }
23
+ initialRender.current = true;
24
+ _RNOrientationDirector.default.getDeviceOrientation().then(setOrientation);
25
+ }, []);
26
+ _react.default.useEffect(() => {
27
+ const onChange = event => {
28
+ setOrientation(event.orientation);
29
+ };
30
+ const subscription = _RNOrientationDirector.default.listenForDeviceOrientationChanges(onChange);
31
+ return () => {
32
+ subscription.remove();
33
+ };
34
+ }, []);
35
+ return orientation;
36
+ };
37
+ var _default = exports.default = useDeviceOrientation;
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var _react = _interopRequireWildcard(require("react"));
8
+ var _RNOrientationDirector = _interopRequireDefault(require("../RNOrientationDirector.js"));
9
+ var _OrientationEnum = require("../types/Orientation.enum.js");
10
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
11
+ function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
12
+ /**
13
+ * Hook that returns the current interface orientation.
14
+ * It listens for orientation changes and updates the state accordingly.
15
+ */
16
+ const useInterfaceOrientation = () => {
17
+ const initialRender = (0, _react.useRef)(false);
18
+ const [orientation, setOrientation] = _react.default.useState(_OrientationEnum.Orientation.unknown);
19
+ _react.default.useEffect(() => {
20
+ if (initialRender.current) {
21
+ return;
22
+ }
23
+ initialRender.current = true;
24
+ _RNOrientationDirector.default.getInterfaceOrientation().then(setOrientation);
25
+ }, []);
26
+ _react.default.useEffect(() => {
27
+ const onChange = event => {
28
+ setOrientation(event.orientation);
29
+ };
30
+ const subscription = _RNOrientationDirector.default.listenForInterfaceOrientationChanges(onChange);
31
+ return () => {
32
+ subscription.remove();
33
+ };
34
+ }, []);
35
+ return orientation;
36
+ };
37
+ var _default = exports.default = useInterfaceOrientation;
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var _react = _interopRequireDefault(require("react"));
8
+ var _RNOrientationDirector = _interopRequireDefault(require("../RNOrientationDirector.js"));
9
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
10
+ /**
11
+ * Hook that returns whether the interface is locked.
12
+ * It listens for changes and updates the state accordingly.
13
+ */
14
+ const useIsInterfaceOrientationLocked = () => {
15
+ const [orientation, setOrientation] = _react.default.useState(() => _RNOrientationDirector.default.isLocked());
16
+ _react.default.useEffect(() => {
17
+ const onChange = event => {
18
+ setOrientation(event.locked);
19
+ };
20
+ const subscription = _RNOrientationDirector.default.listenForLockChanges(onChange);
21
+ return () => {
22
+ subscription.remove();
23
+ };
24
+ }, []);
25
+ return orientation;
26
+ };
27
+ var _default = exports.default = useIsInterfaceOrientationLocked;
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ Object.defineProperty(exports, "AutoRotation", {
7
+ enumerable: true,
8
+ get: function () {
9
+ return _AutoRotationEnum.AutoRotation;
10
+ }
11
+ });
12
+ Object.defineProperty(exports, "Orientation", {
13
+ enumerable: true,
14
+ get: function () {
15
+ return _OrientationEnum.Orientation;
16
+ }
17
+ });
18
+ Object.defineProperty(exports, "OrientationType", {
19
+ enumerable: true,
20
+ get: function () {
21
+ return _OrientationTypeEnum.OrientationType;
22
+ }
23
+ });
24
+ exports.default = void 0;
25
+ Object.defineProperty(exports, "useDeviceOrientation", {
26
+ enumerable: true,
27
+ get: function () {
28
+ return _useDeviceOrientationHook.default;
29
+ }
30
+ });
31
+ Object.defineProperty(exports, "useInterfaceOrientation", {
32
+ enumerable: true,
33
+ get: function () {
34
+ return _useInterfaceOrientationHook.default;
35
+ }
36
+ });
37
+ Object.defineProperty(exports, "useIsInterfaceOrientationLocked", {
38
+ enumerable: true,
39
+ get: function () {
40
+ return _useIsInterfaceOrientationLockedHook.default;
41
+ }
42
+ });
43
+ var _OrientationEnum = require("./types/Orientation.enum.js");
44
+ var _AutoRotationEnum = require("./types/AutoRotation.enum.js");
45
+ var _OrientationTypeEnum = require("./types/OrientationType.enum.js");
46
+ var _useDeviceOrientationHook = _interopRequireDefault(require("./hooks/useDeviceOrientation.hook.js"));
47
+ var _useInterfaceOrientationHook = _interopRequireDefault(require("./hooks/useInterfaceOrientation.hook.js"));
48
+ var _useIsInterfaceOrientationLockedHook = _interopRequireDefault(require("./hooks/useIsInterfaceOrientationLocked.hook.js"));
49
+ var _RNOrientationDirector = _interopRequireDefault(require("./RNOrientationDirector.js"));
50
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
51
+ var _default = exports.default = _RNOrientationDirector.default;
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = exports.ModuleEventEmitter = void 0;
7
+ var _reactNative = require("react-native");
8
+ const LINKING_ERROR = `The package 'react-native-orientation-director' doesn't seem to be linked. Make sure: \n\n` + _reactNative.Platform.select({
9
+ ios: "- You have run 'pod install'\n",
10
+ default: ''
11
+ }) + '- You rebuilt the app after installing the package\n' + '- You are not using Expo Go\n';
12
+
13
+ // @ts-expect-error
14
+ const isTurboModuleEnabled = global.__turboModuleProxy != null;
15
+ const Module = isTurboModuleEnabled ? require('./NativeOrientationDirector').default : _reactNative.NativeModules.OrientationDirector;
16
+ const OrientationDirectorModule = Module ? Module : new Proxy({}, {
17
+ get() {
18
+ throw new Error(LINKING_ERROR);
19
+ }
20
+ });
21
+ const ModuleEventEmitter = exports.ModuleEventEmitter = new _reactNative.NativeEventEmitter(Module);
22
+ var _default = exports.default = OrientationDirectorModule;
@@ -0,0 +1 @@
1
+ {"type":"commonjs"}
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.AutoRotation = void 0;
7
+ let AutoRotation = exports.AutoRotation = /*#__PURE__*/function (AutoRotation) {
8
+ AutoRotation[AutoRotation["unknown"] = 0] = "unknown";
9
+ AutoRotation[AutoRotation["enabled"] = 1] = "enabled";
10
+ AutoRotation[AutoRotation["disabled"] = 2] = "disabled";
11
+ return AutoRotation;
12
+ }({});
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var Event = /*#__PURE__*/function (Event) {
8
+ Event["DeviceOrientationDidChange"] = "DeviceOrientationDidChange";
9
+ Event["InterfaceOrientationDidChange"] = "InterfaceOrientationDidChange";
10
+ Event["LockDidChange"] = "LockDidChange";
11
+ return Event;
12
+ }(Event || {});
13
+ var _default = exports.default = Event;
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });