react-native-orientation-director 1.0.1 → 1.1.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 (51) hide show
  1. package/README.md +19 -9
  2. package/android/src/main/java/com/orientationdirector/OrientationDirectorModule.kt +5 -0
  3. package/android/src/main/java/com/orientationdirector/implementation/OrientationDirectorImpl.kt +29 -17
  4. package/android/src/main/java/com/orientationdirector/implementation/OrientationDirectorUtilsImpl.kt +26 -25
  5. package/android/src/main/java/com/orientationdirector/implementation/OrientationEventManager.kt +8 -0
  6. package/android/src/oldarch/OrientationDirectorSpec.kt +2 -1
  7. package/ios/OrientationDirector.mm +10 -1
  8. package/ios/implementation/OrientationDirectorImpl.swift +32 -8
  9. package/ios/implementation/OrientationDirectorUtils.swift +21 -0
  10. package/ios/implementation/OrientationEventManager.swift +14 -0
  11. package/lib/commonjs/NativeOrientationDirector.js.map +1 -1
  12. package/lib/commonjs/RNOrientationDirector.js +6 -0
  13. package/lib/commonjs/RNOrientationDirector.js.map +1 -1
  14. package/lib/commonjs/hooks/useIsInterfaceOrientationLocked.hook.js +28 -0
  15. package/lib/commonjs/hooks/useIsInterfaceOrientationLocked.hook.js.map +1 -0
  16. package/lib/commonjs/index.js +7 -0
  17. package/lib/commonjs/index.js.map +1 -1
  18. package/lib/commonjs/types/Event.enum.js +1 -0
  19. package/lib/commonjs/types/Event.enum.js.map +1 -1
  20. package/lib/commonjs/types/LockedEvent.interface.js +2 -0
  21. package/lib/commonjs/types/LockedEvent.interface.js.map +1 -0
  22. package/lib/module/NativeOrientationDirector.js.map +1 -1
  23. package/lib/module/RNOrientationDirector.js +6 -0
  24. package/lib/module/RNOrientationDirector.js.map +1 -1
  25. package/lib/module/hooks/useIsInterfaceOrientationLocked.hook.js +21 -0
  26. package/lib/module/hooks/useIsInterfaceOrientationLocked.hook.js.map +1 -0
  27. package/lib/module/index.js +2 -0
  28. package/lib/module/index.js.map +1 -1
  29. package/lib/module/types/Event.enum.js +1 -0
  30. package/lib/module/types/Event.enum.js.map +1 -1
  31. package/lib/module/types/LockedEvent.interface.js +2 -0
  32. package/lib/module/types/LockedEvent.interface.js.map +1 -0
  33. package/lib/typescript/src/NativeOrientationDirector.d.ts +1 -0
  34. package/lib/typescript/src/NativeOrientationDirector.d.ts.map +1 -1
  35. package/lib/typescript/src/RNOrientationDirector.d.ts +3 -0
  36. package/lib/typescript/src/RNOrientationDirector.d.ts.map +1 -1
  37. package/lib/typescript/src/hooks/useIsInterfaceOrientationLocked.hook.d.ts +7 -0
  38. package/lib/typescript/src/hooks/useIsInterfaceOrientationLocked.hook.d.ts.map +1 -0
  39. package/lib/typescript/src/index.d.ts +2 -0
  40. package/lib/typescript/src/index.d.ts.map +1 -1
  41. package/lib/typescript/src/types/Event.enum.d.ts +2 -1
  42. package/lib/typescript/src/types/Event.enum.d.ts.map +1 -1
  43. package/lib/typescript/src/types/LockedEvent.interface.d.ts +4 -0
  44. package/lib/typescript/src/types/LockedEvent.interface.d.ts.map +1 -0
  45. package/package.json +1 -1
  46. package/src/NativeOrientationDirector.ts +1 -0
  47. package/src/RNOrientationDirector.ts +9 -0
  48. package/src/hooks/useIsInterfaceOrientationLocked.hook.ts +28 -0
  49. package/src/index.tsx +3 -0
  50. package/src/types/Event.enum.ts +1 -0
  51. package/src/types/LockedEvent.interface.ts +3 -0
package/README.md CHANGED
@@ -1,14 +1,25 @@
1
+ ![NPM Version](https://img.shields.io/npm/v/react-native-orientation-director)
2
+
3
+ ---
4
+
1
5
  # react-native-orientation-director
2
6
 
3
7
  A simple library that allows you to handle orientation changes in your React Native app.
4
8
  Written in Kotlin, Swift and Typescript. It supports both the Old and New React Native architecture.
5
9
 
10
+ This library takes inspiration from and builds upon the following amazing alternatives:
11
+
12
+ 1. [react-native-orientation-locker](https://github.com/wonday/react-native-orientation-locker)
13
+ 2. [react-native-orientation-handler](https://github.com/KroosX4V/react-native-orientation-manager)
14
+
6
15
  ## Features
7
16
 
8
17
  - [x] Get the current orientation of the device
9
18
  - [x] Get the current orientation of the interface
19
+ - [x] Get the current interface orientation status (locked or unlocked)
10
20
  - [x] Listen to device orientation changes
11
21
  - [x] Listen to interface orientation changes
22
+ - [x] Listen to interface orientation status changes
12
23
  - [x] Lock the interface orientation to a specific orientation
13
24
  - [x] Unlock the interface orientation
14
25
 
@@ -23,7 +34,7 @@ npm install react-native-orientation-director
23
34
  yarn add react-native-orientation-director
24
35
  ```
25
36
 
26
- Don't forget to run pod-install
37
+ Don't forget to run pod-install.
27
38
 
28
39
  ## Setup
29
40
 
@@ -53,17 +64,20 @@ This library exports a class called: [RNOrientationDirector](https://github.com/
53
64
  | getDeviceOrientation | Returns the last device orientation |
54
65
  | lockTo | Locks the interface to a specific orientation |
55
66
  | unlock | Unlock the interface |
67
+ | isLocked | Returns the current interface orientation status (locked / unlocked) |
56
68
  | listenForDeviceOrientationChanges | Triggers a provided callback each time the device orientation changes |
57
69
  | listenForInterfaceOrientationChanges | Triggers a provided callback each time the interface orientation changes |
70
+ | listenForLockChanges | Triggers a provided callback each time the interface orientation status changes |
58
71
  | convertOrientationToHumanReadableString | Returns a human readable string based on the given orientation |
59
72
  | setLocalizedStringProvider | Sets the mapping needed to convert orientation values to human readable strings |
60
73
 
61
74
  In addition, the library exposes the following hooks:
62
75
 
63
- | Hook | Description |
64
- |-------------------------------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------|
65
- | [useInterfaceOrientation](https://github.com/gladiuscode/react-native-orientation-director/blob/main/src/hooks/useInterfaceOrientation.hook.ts) | Returns the current interface orientation and listens to changes |
66
- | [useDeviceOrientation](https://github.com/gladiuscode/react-native-orientation-director/blob/main/src/hooks/useDeviceOrientation.hook.ts) | Returns the current device orientation and listens to changes |
76
+ | Hook | Description |
77
+ |-----------------------------------------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------|
78
+ | [useInterfaceOrientation](https://github.com/gladiuscode/react-native-orientation-director/blob/main/src/hooks/useInterfaceOrientation.hook.ts) | Returns the current interface orientation and listens to changes |
79
+ | [useDeviceOrientation](https://github.com/gladiuscode/react-native-orientation-director/blob/main/src/hooks/useDeviceOrientation.hook.ts) | Returns the current device orientation and listens to changes |
80
+ | [useIsInterfaceOrientationLocked](https://github.com/gladiuscode/react-native-orientation-director/blob/main/src/hooks/useIsInterfaceOrientationLocked.hook.ts) | Returns the current interface orientation status and listens to changes |
67
81
 
68
82
  Head over to the [example project](example) to see how to use the library.
69
83
 
@@ -78,10 +92,6 @@ Head over to the [example project](example) to see how to use the library.
78
92
 
79
93
  See the [contributing guide](CONTRIBUTING.md) to learn how to contribute to the repository and the development workflow.
80
94
 
81
- ## License
82
-
83
- MIT
84
-
85
95
  ---
86
96
 
87
97
  Made with [create-react-native-library](https://github.com/callstack/react-native-builder-bob)
@@ -38,6 +38,11 @@ class OrientationDirectorModule internal constructor(context: ReactApplicationCo
38
38
  orientationDirectorImpl.unlock()
39
39
  }
40
40
 
41
+ @ReactMethod(isBlockingSynchronousMethod = true)
42
+ override fun isLocked(): Boolean {
43
+ return orientationDirectorImpl.isLocked
44
+ }
45
+
41
46
  @ReactMethod()
42
47
  override fun addListener(eventName: String) {}
43
48
 
@@ -4,15 +4,18 @@ import android.content.pm.ActivityInfo
4
4
  import com.facebook.react.bridge.ReactApplicationContext
5
5
 
6
6
  class OrientationDirectorImpl internal constructor(private val context: ReactApplicationContext) {
7
- private var mUtils = OrientationDirectorUtilsImpl()
7
+ private var mUtils = OrientationDirectorUtilsImpl(context)
8
8
  private var mEventEmitter = OrientationEventManager(context)
9
9
  private var mSensorListener = OrientationSensorListener(context)
10
10
  private var mLifecycleListener = OrientationLifecycleListener()
11
- private var isLocked: Boolean = false
11
+
12
+ private var initialSupportedInterfaceOrientations = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
12
13
  private var lastInterfaceOrientation = Orientation.UNKNOWN
13
14
  private var lastDeviceOrientation = Orientation.UNKNOWN
14
15
  private var initialized = false
15
16
 
17
+ var isLocked: Boolean = false
18
+
16
19
  init {
17
20
  mSensorListener.setOnOrientationChangedCallback { orientation ->
18
21
  onOrientationChanged(orientation)
@@ -39,8 +42,11 @@ class OrientationDirectorImpl internal constructor(private val context: ReactApp
39
42
  mSensorListener.disable()
40
43
  }
41
44
 
45
+ initialSupportedInterfaceOrientations =
46
+ context.currentActivity?.requestedOrientation ?: initialSupportedInterfaceOrientations
42
47
  lastInterfaceOrientation = initInterfaceOrientation()
43
48
  lastDeviceOrientation = initDeviceOrientation()
49
+ isLocked = initIsLocked()
44
50
 
45
51
  initialized = true
46
52
  }
@@ -54,34 +60,24 @@ class OrientationDirectorImpl internal constructor(private val context: ReactApp
54
60
  }
55
61
 
56
62
  fun lockTo(jsOrientation: Int) {
57
- val interfaceOrientation = mUtils.getOrientationEnumFrom(jsOrientation)
63
+ val interfaceOrientation = mUtils.getOrientationFromJsOrientation(jsOrientation)
58
64
  val screenOrientation =
59
65
  mUtils.getActivityOrientationFrom(interfaceOrientation)
60
66
  context.currentActivity?.requestedOrientation = screenOrientation
61
67
  mEventEmitter.sendInterfaceOrientationDidChange(interfaceOrientation.ordinal)
62
68
  lastInterfaceOrientation = interfaceOrientation
63
- isLocked = true
69
+ updateIsLockedTo(true)
64
70
  }
65
71
 
66
72
  fun unlock() {
67
73
  context.currentActivity?.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
68
- isLocked = false
74
+ updateIsLockedTo(false)
69
75
  adaptInterfaceTo(getDeviceOrientation())
70
76
  }
71
77
 
72
78
  private fun initInterfaceOrientation(): Orientation {
73
- val activityOrientation = context.currentActivity!!.requestedOrientation
74
- if (
75
- mUtils.isActivityInPortraitOrientation(activityOrientation) ||
76
- mUtils.isActivityInLandscapeOrientation(activityOrientation)
77
- ) {
78
- return mUtils.getInterfaceOrientationFrom(activityOrientation)
79
- }
80
-
81
- val lastRotationDetected = mSensorListener.getLastRotationDetected()
82
- ?: return lastInterfaceOrientation
83
-
84
- return mUtils.getDeviceOrientationFrom(lastRotationDetected)
79
+ val rotation = mUtils.getInterfaceRotation()
80
+ return mUtils.getOrientationFromRotation(rotation)
85
81
  }
86
82
 
87
83
  private fun initDeviceOrientation(): Orientation {
@@ -91,6 +87,17 @@ class OrientationDirectorImpl internal constructor(private val context: ReactApp
91
87
  return mUtils.getDeviceOrientationFrom(lastRotationDetected)
92
88
  }
93
89
 
90
+ private fun initIsLocked(): Boolean {
91
+ val activity = context.currentActivity ?: return false
92
+ return listOf(
93
+ ActivityInfo.SCREEN_ORIENTATION_PORTRAIT,
94
+ ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE,
95
+ ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT,
96
+ ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE,
97
+ ActivityInfo.SCREEN_ORIENTATION_LOCKED,
98
+ ).contains(activity.requestedOrientation)
99
+ }
100
+
94
101
  private fun onOrientationChanged(rawDeviceOrientation: Int) {
95
102
  val deviceOrientation = mUtils.getDeviceOrientationFrom(rawDeviceOrientation)
96
103
  mEventEmitter.sendDeviceOrientationDidChange(deviceOrientation.ordinal)
@@ -111,6 +118,11 @@ class OrientationDirectorImpl internal constructor(private val context: ReactApp
111
118
  mEventEmitter.sendInterfaceOrientationDidChange(lastInterfaceOrientation.ordinal)
112
119
  }
113
120
 
121
+ private fun updateIsLockedTo(value: Boolean) {
122
+ mEventEmitter.sendLockDidChange(value)
123
+ isLocked = value
124
+ }
125
+
114
126
  companion object {
115
127
  const val NAME = "OrientationDirectorImpl"
116
128
  }
@@ -1,8 +1,23 @@
1
1
  package com.orientationdirector.implementation
2
2
 
3
+ import android.content.Context
3
4
  import android.content.pm.ActivityInfo
5
+ import android.os.Build
6
+ import android.view.Surface
7
+ import android.view.WindowManager
8
+ import com.facebook.react.bridge.ReactContext
4
9
 
5
- class OrientationDirectorUtilsImpl() {
10
+ class OrientationDirectorUtilsImpl(val context: ReactContext) {
11
+
12
+ fun getInterfaceRotation(): Int {
13
+ return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
14
+ context.currentActivity?.display?.rotation ?: Surface.ROTATION_0
15
+ } else {
16
+ val windowManager = context.getSystemService(Context.WINDOW_SERVICE) as WindowManager
17
+ @Suppress("DEPRECATION")
18
+ windowManager.defaultDisplay.rotation
19
+ }
20
+ }
6
21
 
7
22
  fun getDeviceOrientationFrom(rotation: Int): Orientation {
8
23
  var orientation = Orientation.UNKNOWN
@@ -22,29 +37,6 @@ class OrientationDirectorUtilsImpl() {
22
37
  return orientation
23
38
  }
24
39
 
25
- fun getInterfaceOrientationFrom(activityInfo: Int): Orientation {
26
- return when (activityInfo) {
27
- ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE -> Orientation.LANDSCAPE_RIGHT
28
- ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT -> Orientation.PORTRAIT_UPSIDE_DOWN
29
- ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE -> Orientation.LANDSCAPE_LEFT
30
- else -> Orientation.PORTRAIT
31
- };
32
- }
33
-
34
- fun isActivityInLandscapeOrientation(orientation: Int): Boolean {
35
- return listOf(
36
- ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE,
37
- ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE,
38
- ).contains(orientation);
39
- }
40
-
41
- fun isActivityInPortraitOrientation(orientation: Int): Boolean {
42
- return listOf(
43
- ActivityInfo.SCREEN_ORIENTATION_PORTRAIT,
44
- ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT,
45
- ).contains(orientation);
46
- }
47
-
48
40
  fun getActivityOrientationFrom(interfaceOrientation: Orientation): Int {
49
41
  return when (interfaceOrientation) {
50
42
  Orientation.LANDSCAPE_RIGHT -> ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE
@@ -54,7 +46,7 @@ class OrientationDirectorUtilsImpl() {
54
46
  }
55
47
  }
56
48
 
57
- fun getOrientationEnumFrom(jsOrientation: Int): Orientation {
49
+ fun getOrientationFromJsOrientation(jsOrientation: Int): Orientation {
58
50
  return when (jsOrientation) {
59
51
  2 -> Orientation.LANDSCAPE_RIGHT
60
52
  3 -> Orientation.PORTRAIT_UPSIDE_DOWN
@@ -62,4 +54,13 @@ class OrientationDirectorUtilsImpl() {
62
54
  else -> Orientation.PORTRAIT
63
55
  }
64
56
  }
57
+
58
+ fun getOrientationFromRotation(rotation: Int): Orientation {
59
+ return when(rotation) {
60
+ Surface.ROTATION_270 -> Orientation.LANDSCAPE_RIGHT
61
+ Surface.ROTATION_90 -> Orientation.LANDSCAPE_LEFT
62
+ Surface.ROTATION_180 -> Orientation.PORTRAIT_UPSIDE_DOWN
63
+ else -> Orientation.PORTRAIT
64
+ }
65
+ }
65
66
  }
@@ -9,6 +9,7 @@ import com.facebook.react.modules.core.DeviceEventManagerModule
9
9
  enum class Event {
10
10
  DeviceOrientationDidChange,
11
11
  InterfaceOrientationDidChange,
12
+ LockDidChange,
12
13
  }
13
14
 
14
15
  class OrientationEventManager(private val context: ReactApplicationContext) {
@@ -27,6 +28,13 @@ class OrientationEventManager(private val context: ReactApplicationContext) {
27
28
  sendEvent(Event.InterfaceOrientationDidChange, params)
28
29
  }
29
30
 
31
+ fun sendLockDidChange(value: Boolean) {
32
+ val params = Arguments.createMap().apply {
33
+ putBoolean("locked", value)
34
+ }
35
+ sendEvent(Event.LockDidChange, params)
36
+ }
37
+
30
38
  private fun sendEvent(eventName: Event, params: WritableMap?) {
31
39
  Log.d(NAME, "sendEvent - $eventName")
32
40
  Log.d(NAME, "sendEvent - $params")
@@ -6,11 +6,12 @@ import com.facebook.react.bridge.Promise
6
6
 
7
7
  abstract class OrientationDirectorSpec internal constructor(context: ReactApplicationContext) :
8
8
  ReactContextBaseJavaModule(context) {
9
-
10
9
  abstract fun getInterfaceOrientation(promise: Promise)
11
10
  abstract fun getDeviceOrientation(promise: Promise)
12
11
  abstract fun lockTo(orientation: Double)
13
12
  abstract fun unlock()
13
+
14
+ abstract fun isLocked(): Boolean
14
15
  abstract fun addListener(eventName: String)
15
16
  abstract fun removeListeners(count: Double)
16
17
  }
@@ -64,7 +64,7 @@ RCT_EXPORT_MODULE()
64
64
 
65
65
  + (UIInterfaceOrientationMask)getSupportedInterfaceOrientationsForWindow
66
66
  {
67
- return [_director supportedInterfaceOrientation];
67
+ return [_director supportedInterfaceOrientations];
68
68
  }
69
69
 
70
70
  #ifdef RCT_NEW_ARCH_ENABLED
@@ -114,6 +114,15 @@ RCT_EXPORT_METHOD(unlock)
114
114
  });
115
115
  }
116
116
 
117
+ #ifdef RCT_NEW_ARCH_ENABLED
118
+ - (NSNumber *)isLocked
119
+ #else
120
+ RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(isLocked)
121
+ #endif
122
+ {
123
+ return @([_director isLocked]);
124
+ }
125
+
117
126
  // Don't compile this code when we build for the old architecture.
118
127
  #ifdef RCT_NEW_ARCH_ENABLED
119
128
  - (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:
@@ -12,19 +12,24 @@ import UIKit
12
12
  private static let TAG = "OrientationDirectorImpl"
13
13
  private let sensorListener: OrientationSensorListener
14
14
  private let eventManager: OrientationEventManager
15
- private var isLocked: Bool = false
16
- private var lastInterfaceOrientation: Orientation = Orientation.UNKNOWN
17
- private var lastDeviceOrientation: Orientation = Orientation.UNKNOWN
15
+ private var initialSupportedInterfaceOrientations: UIInterfaceOrientationMask = UIInterfaceOrientationMask.all
16
+ private var lastInterfaceOrientation = Orientation.UNKNOWN
17
+ private var lastDeviceOrientation = Orientation.UNKNOWN
18
18
 
19
- @objc public var supportedInterfaceOrientation: UIInterfaceOrientationMask = UIInterfaceOrientationMask.all
19
+ @objc public var supportedInterfaceOrientations: UIInterfaceOrientationMask = UIInterfaceOrientationMask.all
20
+ @objc public var isLocked = false
20
21
 
21
22
  @objc public override init() {
22
23
  eventManager = OrientationEventManager()
23
24
  sensorListener = OrientationSensorListener()
24
25
  super.init()
25
26
  sensorListener.setOnOrientationChanged(callback: self.onOrientationChanged)
27
+ initialSupportedInterfaceOrientations = initInitialSupportedInterfaceOrientations()
26
28
  lastInterfaceOrientation = initInterfaceOrientation()
27
29
  lastDeviceOrientation = initDeviceOrientation()
30
+ isLocked = initIsLocked()
31
+
32
+ supportedInterfaceOrientations = initialSupportedInterfaceOrientations
28
33
  }
29
34
 
30
35
  ///////////////////////////////////////////////////////////////////////////////////////
@@ -51,17 +56,22 @@ import UIKit
51
56
 
52
57
  eventManager.sendInterfaceOrientationDidChange(orientationValue: orientation.rawValue)
53
58
  lastInterfaceOrientation = orientation
54
- isLocked = true
59
+ updateIsLockedTo(value: true)
55
60
  }
56
61
 
57
62
  @objc public func unlock() {
58
63
  self.requestInterfaceUpdateTo(mask: UIInterfaceOrientationMask.all)
59
64
 
60
65
  let deviceOrientation = OrientationDirectorUtils.getOrientationFrom(deviceOrientation: UIDevice.current.orientation)
61
- isLocked = false
66
+ updateIsLockedTo(value: false)
62
67
  self.adaptInterfaceTo(deviceOrientation: deviceOrientation)
63
68
  }
64
69
 
70
+ private func initInitialSupportedInterfaceOrientations() -> UIInterfaceOrientationMask {
71
+ let supportedInterfaceOrientations = OrientationDirectorUtils.readSupportedInterfaceOrientationsFromBundle()
72
+ return supportedInterfaceOrientations.reduce(UIInterfaceOrientationMask()) { $0.union($1) }
73
+ }
74
+
65
75
  private func initInterfaceOrientation() -> Orientation {
66
76
  let interfaceOrientation = OrientationDirectorUtils.getInterfaceOrientation()
67
77
  return OrientationDirectorUtils.getOrientationFrom(uiInterfaceOrientation: interfaceOrientation)
@@ -71,8 +81,17 @@ import UIKit
71
81
  return OrientationDirectorUtils.getOrientationFrom(deviceOrientation: UIDevice.current.orientation)
72
82
  }
73
83
 
84
+ private func initIsLocked() -> Bool {
85
+ let supportedOrientations = OrientationDirectorUtils.readSupportedInterfaceOrientationsFromBundle()
86
+ if (supportedOrientations.count > 1) {
87
+ return false
88
+ }
89
+
90
+ return supportedOrientations.first != UIInterfaceOrientationMask.all
91
+ }
92
+
74
93
  private func requestInterfaceUpdateTo(mask: UIInterfaceOrientationMask) {
75
- self.supportedInterfaceOrientation = mask
94
+ self.supportedInterfaceOrientations = mask
76
95
 
77
96
  DispatchQueue.main.async {
78
97
  if #available(iOS 16.0, *) {
@@ -122,5 +141,10 @@ import UIKit
122
141
 
123
142
  self.eventManager.sendInterfaceOrientationDidChange(orientationValue: deviceOrientation.rawValue)
124
143
  lastInterfaceOrientation = deviceOrientation
125
- }
144
+ }
145
+
146
+ private func updateIsLockedTo(value: Bool) {
147
+ eventManager.sendLockDidChange(value: value)
148
+ isLocked = value
149
+ }
126
150
  }
@@ -107,5 +107,26 @@ class OrientationDirectorUtils {
107
107
  .flatMap { $0.windows }
108
108
  .last { $0.isKeyWindow }
109
109
  }
110
+
111
+ public static func readSupportedInterfaceOrientationsFromBundle() -> [UIInterfaceOrientationMask] {
112
+ guard let rawOrientations = Bundle.main.object(forInfoDictionaryKey: "UISupportedInterfaceOrientations") as? [String] else {
113
+ return [UIInterfaceOrientationMask.all]
114
+ }
115
+
116
+ return rawOrientations.compactMap { orientation in
117
+ switch orientation {
118
+ case "UIInterfaceOrientationPortrait":
119
+ return UIInterfaceOrientationMask.portrait
120
+ case "UIInterfaceOrientationLandscapeLeft":
121
+ return UIInterfaceOrientationMask.landscapeLeft
122
+ case "UIInterfaceOrientationLandscapeRight":
123
+ return UIInterfaceOrientationMask.landscapeRight
124
+ case "UIInterfaceOrientationPortraitUpsideDown":
125
+ return UIInterfaceOrientationMask.portraitUpsideDown
126
+ default:
127
+ return UIInterfaceOrientationMask.allButUpsideDown
128
+ }
129
+ }
130
+ }
110
131
 
111
132
  }
@@ -35,6 +35,19 @@ import Foundation
35
35
  let params = Dictionary(dictionaryLiteral: ("orientation", orientationValue))
36
36
  delegate.sendEvent(name: Event.InterfaceOrientationDidChange.rawValue, params: params as NSDictionary)
37
37
  }
38
+
39
+ func sendLockDidChange(value: Bool) {
40
+ guard let delegate = delegate else {
41
+ return
42
+ }
43
+
44
+ if (!delegate.isJsListening) {
45
+ return
46
+ }
47
+
48
+ let params = Dictionary(dictionaryLiteral: ("locked", value))
49
+ delegate.sendEvent(name: Event.LockDidChange.rawValue, params: params as NSDictionary)
50
+ }
38
51
  }
39
52
 
40
53
  @objc public protocol OrientationEventEmitterDelegate {
@@ -48,6 +61,7 @@ public extension OrientationEventManager {
48
61
  enum Event: String, CaseIterable {
49
62
  case DeviceOrientationDidChange
50
63
  case InterfaceOrientationDidChange
64
+ case LockDidChange
51
65
  }
52
66
 
53
67
  @objc static var supportedEvents: [String] {
@@ -1 +1 @@
1
- {"version":3,"names":["_reactNative","require","_default","exports","default","TurboModuleRegistry","getEnforcing"],"sourceRoot":"../../src","sources":["NativeOrientationDirector.ts"],"mappings":";;;;;;AACA,IAAAA,YAAA,GAAAC,OAAA;AAAmD,IAAAC,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAYpCC,gCAAmB,CAACC,YAAY,CAAO,qBAAqB,CAAC","ignoreList":[]}
1
+ {"version":3,"names":["_reactNative","require","_default","exports","default","TurboModuleRegistry","getEnforcing"],"sourceRoot":"../../src","sources":["NativeOrientationDirector.ts"],"mappings":";;;;;;AACA,IAAAA,YAAA,GAAAC,OAAA;AAAmD,IAAAC,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAapCC,gCAAmB,CAACC,YAAY,CAAO,qBAAqB,CAAC","ignoreList":[]}
@@ -35,12 +35,18 @@ class RNOrientationDirector {
35
35
  static unlock() {
36
36
  _module.default.unlock();
37
37
  }
38
+ static isLocked() {
39
+ return _module.default.isLocked();
40
+ }
38
41
  static listenForDeviceOrientationChanges(callback) {
39
42
  return _module.EventEmitter.addListener(_Event.default.DeviceOrientationDidChange, callback);
40
43
  }
41
44
  static listenForInterfaceOrientationChanges(callback) {
42
45
  return _module.EventEmitter.addListener(_Event.default.InterfaceOrientationDidChange, callback);
43
46
  }
47
+ static listenForLockChanges(callback) {
48
+ return _module.EventEmitter.addListener(_Event.default.LockDidChange, callback);
49
+ }
44
50
  static convertOrientationToHumanReadableString(orientation) {
45
51
  return RNOrientationDirector._localizedStringProvider[orientation];
46
52
  }
@@ -1 +1 @@
1
- {"version":3,"names":["_module","_interopRequireWildcard","require","_Event","_interopRequireDefault","_Orientation","obj","__esModule","default","_getRequireWildcardCache","e","WeakMap","r","t","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","hasOwnProperty","call","i","set","RNOrientationDirector","_localizedStringProvider","Orientation","unknown","portrait","portraitUpsideDown","landscapeLeft","landscapeRight","faceUp","faceDown","setLocalizedStringProvider","provider","getInterfaceOrientation","Module","getDeviceOrientation","lockTo","orientation","unlock","listenForDeviceOrientationChanges","callback","EventEmitter","addListener","Event","DeviceOrientationDidChange","listenForInterfaceOrientationChanges","InterfaceOrientationDidChange","convertOrientationToHumanReadableString","_default","exports"],"sourceRoot":"../../src","sources":["RNOrientationDirector.ts"],"mappings":";;;;;;AAAA,IAAAA,OAAA,GAAAC,uBAAA,CAAAC,OAAA;AACA,IAAAC,MAAA,GAAAC,sBAAA,CAAAF,OAAA;AAEA,IAAAG,YAAA,GAAAH,OAAA;AAAuD,SAAAE,uBAAAE,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAAA,SAAAG,yBAAAC,CAAA,6BAAAC,OAAA,mBAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,CAAAC,CAAA,WAAAA,CAAA,GAAAG,CAAA,GAAAD,CAAA,KAAAF,CAAA;AAAA,SAAAT,wBAAAS,CAAA,EAAAE,CAAA,SAAAA,CAAA,IAAAF,CAAA,IAAAA,CAAA,CAAAH,UAAA,SAAAG,CAAA,eAAAA,CAAA,uBAAAA,CAAA,yBAAAA,CAAA,WAAAF,OAAA,EAAAE,CAAA,QAAAG,CAAA,GAAAJ,wBAAA,CAAAG,CAAA,OAAAC,CAAA,IAAAA,CAAA,CAAAC,G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IAClD,OAAOD,eAAM,CAACC,oBAAoB,CAAC,CAAC;EACtC;EAEA,OAAOC,MAAMA,CAACC,WAAgC,EAAE;IAC9CH,eAAM,CAACE,MAAM,CAACC,WAAW,CAAC;EAC5B;EAEA,OAAOC,MAAMA,CAAA,EAAG;IACdJ,eAAM,CAACI,MAAM,CAAC,CAAC;EACjB;EAEA,OAAOC,iCAAiCA,CACtCC,QAAiD,EACjD;IACA,OAAOC,oBAAY,CAACC,WAAW,CAACC,cAAK,CAACC,0BAA0B,EAAEJ,QAAQ,CAAC;EAC7E;EAEA,OAAOK,oCAAoCA,CACzCL,QAAiD,EACjD;IACA,OAAOC,oBAAY,CAACC,WAAW,CAC7BC,cAAK,CAACG,6BAA6B,EACnCN,QACF,CAAC;EACH;EAEA,OAAOO,uCAAuCA,CAC5CV,WAAwB,EAChB;IACR,OAAOhB,qBAAqB,CAACC,wBAAwB,CAACe,WAAW,CAAC;EACpE;AACF;AAAC,IAAAW,QAAA,GAAAC,OAAA,CAAA/C,OAAA,GAEcmB,qBAAqB","ignoreList":[]}
1
+ {"version":3,"names":["_module","_interopRequireWildcard","require","_Event","_interopRequireDefault","_Orientation","obj","__esModule","default","_getRequireWildcardCache","e","WeakMap","r","t","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","hasOwnProperty","call","i","set","RNOrientationDirector","_localizedStringProvider","Orientation","unknown","portrait","portraitUpsideDown","landscapeLeft","landscapeRight","faceUp","faceDown","setLocalizedStringProvider","provider","getInterfaceOrientation","Module","getDeviceOrientation","lockTo","orientation","unlock","isLocked","listenForDeviceOrientationChanges","callback","EventEmitter","addListener","Event","DeviceOrientationDidChange","listenForInterfaceOrientationChanges","InterfaceOrientationDidChange","listenForLockChanges","LockDidChange","convertOrientationToHumanReadableString","_default","exports"],"sourceRoot":"../../src","sources":["RNOrientationDirector.ts"],"mappings":";;;;;;AAAA,IAAAA,OAAA,GAAAC,uBAAA,CAAAC,OAAA;AACA,IAAAC,MAAA,GAAA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W,CAACC,cAAK,CAACK,aAAa,EAAER,QAAQ,CAAC;EAChE;EAEA,OAAOS,uCAAuCA,CAC5Cb,WAAwB,EAChB;IACR,OAAOhB,qBAAqB,CAACC,wBAAwB,CAACe,WAAW,CAAC;EACpE;AACF;AAAC,IAAAc,QAAA,GAAAC,OAAA,CAAAlD,OAAA,GAEcmB,qBAAqB","ignoreList":[]}
@@ -0,0 +1,28 @@
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"));
9
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
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;
28
+ //# sourceMappingURL=useIsInterfaceOrientationLocked.hook.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_react","_interopRequireDefault","require","_RNOrientationDirector","obj","__esModule","default","useIsInterfaceOrientationLocked","orientation","setOrientation","React","useState","RNOrientationDirector","isLocked","useEffect","onChange","event","locked","subscription","listenForLockChanges","remove","_default","exports"],"sourceRoot":"../../../src","sources":["hooks/useIsInterfaceOrientationLocked.hook.ts"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,sBAAA,GAAAF,sBAAA,CAAAC,OAAA;AAA6D,SAAAD,uBAAAG,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAG7D;AACA;AACA;AACA;AACA,MAAMG,+BAA+B,GAAGA,CAAA,KAAM;EAC5C,MAAM,CAACC,WAAW,EAAEC,cAAc,CAAC,GAAGC,cAAK,CAACC,QAAQ,CAAU,MAC5DC,8BAAqB,CAACC,QAAQ,CAAC,CACjC,CAAC;EAEDH,cAAK,CAACI,SAAS,CAAC,MAAM;IACpB,MAAMC,QAAQ,GAAIC,KAAkB,IAAK;MACvCP,cAAc,CAACO,KAAK,CAACC,MAAM,CAAC;IAC9B,CAAC;IAED,MAAMC,YAAY,GAAGN,8BAAqB,CAACO,oBAAoB,CAACJ,QAAQ,CAAC;IACzE,OAAO,MAAM;MACXG,YAAY,CAACE,MAAM,CAAC,CAAC;IACvB,CAAC;EACH,CAAC,EAAE,EAAE,CAAC;EAEN,OAAOZ,WAAW;AACpB,CAAC;AAAC,IAAAa,QAAA,GAAAC,OAAA,CAAAhB,OAAA,GAEaC,+BAA+B","ignoreList":[]}
@@ -22,9 +22,16 @@ Object.defineProperty(exports, "useInterfaceOrientation", {
22
22
  return _useInterfaceOrientation.default;
23
23
  }
24
24
  });
25
+ Object.defineProperty(exports, "useIsInterfaceOrientationLocked", {
26
+ enumerable: true,
27
+ get: function () {
28
+ return _useIsInterfaceOrientationLocked.default;
29
+ }
30
+ });
25
31
  var _Orientation = require("./types/Orientation.enum");
26
32
  var _useDeviceOrientation = _interopRequireDefault(require("./hooks/useDeviceOrientation.hook"));
27
33
  var _useInterfaceOrientation = _interopRequireDefault(require("./hooks/useInterfaceOrientation.hook"));
34
+ var _useIsInterfaceOrientationLocked = _interopRequireDefault(require("./hooks/useIsInterfaceOrientationLocked.hook"));
28
35
  var _RNOrientationDirector = _interopRequireDefault(require("./RNOrientationDirector"));
29
36
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
30
37
  var _default = exports.default = _RNOrientationDirector.default;
@@ -1 +1 @@
1
- {"version":3,"names":["_Orientation","require","_useDeviceOrientation","_interopRequireDefault","_useInterfaceOrientation","_RNOrientationDirector","obj","__esModule","default","_default","exports","RNOrientationDirector"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AAEA,IAAAC,qBAAA,GAAAC,sBAAA,CAAAF,OAAA;AAGA,IAAAG,wBAAA,GAAAD,sBAAA,CAAAF,OAAA;AAGA,IAAAI,sBAAA,GAAAF,sBAAA,CAAAF,OAAA;AAA4D,SAAAE,uBAAAG,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAAA,IAAAG,QAAA,GAAAC,OAAA,CAAAF,OAAA,GAC7CG,8BAAqB","ignoreList":[]}
1
+ {"version":3,"names":["_Orientation","require","_useDeviceOrientation","_interopRequireDefault","_useInterfaceOrientation","_useIsInterfaceOrientationLocked","_RNOrientationDirector","obj","__esModule","default","_default","exports","RNOrientationDirector"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AAEA,IAAAC,qBAAA,GAAAC,sBAAA,CAAAF,OAAA;AAGA,IAAAG,wBAAA,GAAAD,sBAAA,CAAAF,OAAA;AAGA,IAAAI,gCAAA,GAAAF,sBAAA,CAAAF,OAAA;AAGA,IAAAK,sBAAA,GAAAH,sBAAA,CAAAF,OAAA;AAA4D,SAAAE,uBAAAI,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAAA,IAAAG,QAAA,GAAAC,OAAA,CAAAF,OAAA,GAC7CG,8BAAqB","ignoreList":[]}
@@ -7,6 +7,7 @@ exports.default = void 0;
7
7
  var Event = /*#__PURE__*/function (Event) {
8
8
  Event["DeviceOrientationDidChange"] = "DeviceOrientationDidChange";
9
9
  Event["InterfaceOrientationDidChange"] = "InterfaceOrientationDidChange";
10
+ Event["LockDidChange"] = "LockDidChange";
10
11
  return Event;
11
12
  }(Event || {});
12
13
  var _default = exports.default = Event;
@@ -1 +1 @@
1
- {"version":3,"names":["Event","_default","exports","default"],"sourceRoot":"../../../src","sources":["types/Event.enum.ts"],"mappings":";;;;;;IAAKA,KAAK,0BAALA,KAAK;EAALA,KAAK;EAALA,KAAK;EAAA,OAALA,KAAK;AAAA,EAALA,KAAK;AAAA,IAAAC,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAKKH,KAAK","ignoreList":[]}
1
+ {"version":3,"names":["Event","_default","exports","default"],"sourceRoot":"../../../src","sources":["types/Event.enum.ts"],"mappings":";;;;;;IAAKA,KAAK,0BAALA,KAAK;EAALA,KAAK;EAALA,KAAK;EAALA,KAAK;EAAA,OAALA,KAAK;AAAA,EAALA,KAAK;AAAA,IAAAC,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAMKH,KAAK","ignoreList":[]}
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ //# sourceMappingURL=LockedEvent.interface.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":[],"sourceRoot":"../../../src","sources":["types/LockedEvent.interface.ts"],"mappings":"","ignoreList":[]}
@@ -1 +1 @@
1
- {"version":3,"names":["TurboModuleRegistry","getEnforcing"],"sourceRoot":"../../src","sources":["NativeOrientationDirector.ts"],"mappings":"AACA,SAASA,mBAAmB,QAAQ,cAAc;AAYlD,eAAeA,mBAAmB,CAACC,YAAY,CAAO,qBAAqB,CAAC","ignoreList":[]}
1
+ {"version":3,"names":["TurboModuleRegistry","getEnforcing"],"sourceRoot":"../../src","sources":["NativeOrientationDirector.ts"],"mappings":"AACA,SAASA,mBAAmB,QAAQ,cAAc;AAalD,eAAeA,mBAAmB,CAACC,YAAY,CAAO,qBAAqB,CAAC","ignoreList":[]}
@@ -26,12 +26,18 @@ class RNOrientationDirector {
26
26
  static unlock() {
27
27
  Module.unlock();
28
28
  }
29
+ static isLocked() {
30
+ return Module.isLocked();
31
+ }
29
32
  static listenForDeviceOrientationChanges(callback) {
30
33
  return EventEmitter.addListener(Event.DeviceOrientationDidChange, callback);
31
34
  }
32
35
  static listenForInterfaceOrientationChanges(callback) {
33
36
  return EventEmitter.addListener(Event.InterfaceOrientationDidChange, callback);
34
37
  }
38
+ static listenForLockChanges(callback) {
39
+ return EventEmitter.addListener(Event.LockDidChange, callback);
40
+ }
35
41
  static convertOrientationToHumanReadableString(orientation) {
36
42
  return RNOrientationDirector._localizedStringProvider[orientation];
37
43
  }
@@ -1 +1 @@
1
- {"version":3,"names":["Module","EventEmitter","Event","Orientation","RNOrientationDirector","_localizedStringProvider","unknown","portrait","portraitUpsideDown","landscapeLeft","landscapeRight","faceUp","faceDown","setLocalizedStringProvider","provider","getInterfaceOrientation","getDeviceOrientation","lockTo","orientation","unlock","listenForDeviceOrientationChanges","callback","addListener","DeviceOrientationDidChange","listenForInterfaceOrientationChanges","InterfaceOrientationDidChange","convertOrientationToHumanReadableString"],"sourceRoot":"../../src","sources":["RNOrientationDirector.ts"],"mappings":"AAAA,OAAOA,MAAM,IAAIC,YAAY,QAAQ,UAAU;AAC/C,OAAOC,KAAK,MAAM,oBAAoB;AAEtC,SAASC,WAAW,QAAQ,0BAA0B;AAItD,MAAMC,qBAAqB,CAAC;EAC1B,OAAeC,wBAAwB,GACrC;IACE,CAACF,WAAW,CAACG,OAAO,GAAG,SAAS;IAChC,CAACH,WAAW,CAACI,QAAQ,GAAG,UAAU;IAClC,CAACJ,WAAW,CAACK,kBAAkB,GAAG,sBAAsB;IACxD,CAACL,WAAW,CAACM,aAAa,GAAG,gBAAgB;IAC7C,CAACN,WAAW,CAACO,cAAc,GAAG,iBAAiB;IAC/C,CAACP,WAAW,CAACQ,MAAM,GAAG,SAAS;IAC/B,CAACR,WAAW,CAACS,QAAQ,GAAG;EAC1B,CAAC;EAEHC,0BAA0BA,CACxBC,QAAuD,EACvD;IACAV,qBAAqB,CAACC,wBAAwB,GAAGS,QAAQ;EAC3D;EAEA,OAAOC,uBAAuBA,CAAA,EAAyB;IACrD,OAAOf,MAAM,CAACe,uBAAuB,CAAC,CAAC;EACzC;EAEA,OAAOC,oBAAoBA,CAAA,EAAyB;IAClD,OAAOhB,MAAM,CAACgB,oBAAoB,CAAC,CAAC;EACtC;EAEA,OAAOC,MAAMA,CAACC,WAAgC,EAAE;IAC9ClB,MAAM,CAACiB,MAAM,CAACC,WAAW,CAAC;EAC5B;EAEA,OAAOC,MAAMA,CAAA,EAAG;IACdnB,MAAM,CAACmB,MAAM,CAAC,CAAC;EACjB;EAEA,OAAOC,iCAAiCA,CACtCC,QAAiD,EACjD;IACA,OAAOpB,YAAY,CAACqB,WAAW,CAACpB,KAAK,CAACqB,0BAA0B,EAAEF,QAAQ,CAAC;EAC7E;EAEA,OAAOG,oCAAoCA,CACzCH,QAAiD,EACjD;IACA,OAAOpB,YAAY,CAACqB,WAAW,CAC7BpB,KAAK,CAACuB,6BAA6B,EACnCJ,QACF,CAAC;EACH;EAEA,OAAOK,uCAAuCA,CAC5CR,WAAwB,EAChB;IACR,OAAOd,qBAAqB,CAACC,wBAAwB,CAACa,WAAW,CAAC;EACpE;AACF;AAEA,eAAed,qBAAqB","ignoreList":[]}
1
+ {"version":3,"names":["Module","EventEmitter","Event","Orientation","RNOrientationDirector","_localizedStringProvider","unknown","portrait","portraitUpsideDown","landscapeLeft","landscapeRight","faceUp","faceDown","setLocalizedStringProvider","provider","getInterfaceOrientation","getDeviceOrientation","lockTo","orientation","unlock","isLocked","listenForDeviceOrientationChanges","callback","addListener","DeviceOrientationDidChange","listenForInterfaceOrientationChanges","InterfaceOrientationDidChange","listenForLockChanges","LockDidChange","convertOrientationToHumanReadableString"],"sourceRoot":"../../src","sources":["RNOrientationDirector.ts"],"mappings":"AAAA,OAAOA,MAAM,IAAIC,YAAY,QAAQ,UAAU;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;EAEA,OAAOK,oBAAoBA,CAACL,QAA4C,EAAE;IACxE,OAAOrB,YAAY,CAACsB,WAAW,CAACrB,KAAK,CAAC0B,aAAa,EAAEN,QAAQ,CAAC;EAChE;EAEA,OAAOO,uCAAuCA,CAC5CX,WAAwB,EAChB;IACR,OAAOd,qBAAqB,CAACC,wBAAwB,CAACa,WAAW,CAAC;EACpE;AACF;AAEA,eAAed,qBAAqB","ignoreList":[]}
@@ -0,0 +1,21 @@
1
+ import React from 'react';
2
+ import RNOrientationDirector from '../RNOrientationDirector';
3
+ /**
4
+ * Hook that returns whether the interface is locked.
5
+ * It listens for changes and updates the state accordingly.
6
+ */
7
+ const useIsInterfaceOrientationLocked = () => {
8
+ const [orientation, setOrientation] = React.useState(() => RNOrientationDirector.isLocked());
9
+ React.useEffect(() => {
10
+ const onChange = event => {
11
+ setOrientation(event.locked);
12
+ };
13
+ const subscription = RNOrientationDirector.listenForLockChanges(onChange);
14
+ return () => {
15
+ subscription.remove();
16
+ };
17
+ }, []);
18
+ return orientation;
19
+ };
20
+ export default useIsInterfaceOrientationLocked;
21
+ //# sourceMappingURL=useIsInterfaceOrientationLocked.hook.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["React","RNOrientationDirector","useIsInterfaceOrientationLocked","orientation","setOrientation","useState","isLocked","useEffect","onChange","event","locked","subscription","listenForLockChanges","remove"],"sourceRoot":"../../../src","sources":["hooks/useIsInterfaceOrientationLocked.hook.ts"],"mappings":"AAAA,OAAOA,KAAK,MAAM,OAAO;AACzB,OAAOC,qBAAqB,MAAM,0BAA0B;AAG5D;AACA;AACA;AACA;AACA,MAAMC,+BAA+B,GAAGA,CAAA,KAAM;EAC5C,MAAM,CAACC,WAAW,EAAEC,cAAc,CAAC,GAAGJ,KAAK,CAACK,QAAQ,CAAU,MAC5DJ,qBAAqB,CAACK,QAAQ,CAAC,CACjC,CAAC;EAEDN,KAAK,CAACO,SAAS,CAAC,MAAM;IACpB,MAAMC,QAAQ,GAAIC,KAAkB,IAAK;MACvCL,cAAc,CAACK,KAAK,CAACC,MAAM,CAAC;IAC9B,CAAC;IAED,MAAMC,YAAY,GAAGV,qBAAqB,CAACW,oBAAoB,CAACJ,QAAQ,CAAC;IACzE,OAAO,MAAM;MACXG,YAAY,CAACE,MAAM,CAAC,CAAC;IACvB,CAAC;EACH,CAAC,EAAE,EAAE,CAAC;EAEN,OAAOV,WAAW;AACpB,CAAC;AAED,eAAeD,+BAA+B","ignoreList":[]}
@@ -3,6 +3,8 @@ import useDeviceOrientation from './hooks/useDeviceOrientation.hook';
3
3
  export { useDeviceOrientation };
4
4
  import useInterfaceOrientation from './hooks/useInterfaceOrientation.hook';
5
5
  export { useInterfaceOrientation };
6
+ import useIsInterfaceOrientationLocked from './hooks/useIsInterfaceOrientationLocked.hook';
7
+ export { useIsInterfaceOrientationLocked };
6
8
  import RNOrientationDirector from './RNOrientationDirector';
7
9
  export default RNOrientationDirector;
8
10
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["Orientation","useDeviceOrientation","useInterfaceOrientation","RNOrientationDirector"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":"AAAA,SAASA,WAAW,QAAQ,0BAA0B;AAEtD,OAAOC,oBAAoB,MAAM,mCAAmC;AACpE,SAASA,oBAAoB;AAE7B,OAAOC,uBAAuB,MAAM,sCAAsC;AAC1E,SAASA,uBAAuB;AAEhC,OAAOC,qBAAqB,MAAM,yBAAyB;AAC3D,eAAeA,qBAAqB","ignoreList":[]}
1
+ {"version":3,"names":["Orientation","useDeviceOrientation","useInterfaceOrientation","useIsInterfaceOrientationLocked","RNOrientationDirector"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":"AAAA,SAASA,WAAW,QAAQ,0BAA0B;AAEtD,OAAOC,oBAAoB,MAAM,mCAAmC;AACpE,SAASA,oBAAoB;AAE7B,OAAOC,uBAAuB,MAAM,sCAAsC;AAC1E,SAASA,uBAAuB;AAEhC,OAAOC,+BAA+B,MAAM,8CAA8C;AAC1F,SAASA,+BAA+B;AAExC,OAAOC,qBAAqB,MAAM,yBAAyB;AAC3D,eAAeA,qBAAqB","ignoreList":[]}
@@ -1,6 +1,7 @@
1
1
  var Event = /*#__PURE__*/function (Event) {
2
2
  Event["DeviceOrientationDidChange"] = "DeviceOrientationDidChange";
3
3
  Event["InterfaceOrientationDidChange"] = "InterfaceOrientationDidChange";
4
+ Event["LockDidChange"] = "LockDidChange";
4
5
  return Event;
5
6
  }(Event || {});
6
7
  export default Event;
@@ -1 +1 @@
1
- {"version":3,"names":["Event"],"sourceRoot":"../../../src","sources":["types/Event.enum.ts"],"mappings":"IAAKA,KAAK,0BAALA,KAAK;EAALA,KAAK;EAALA,KAAK;EAAA,OAALA,KAAK;AAAA,EAALA,KAAK;AAKV,eAAeA,KAAK","ignoreList":[]}
1
+ {"version":3,"names":["Event"],"sourceRoot":"../../../src","sources":["types/Event.enum.ts"],"mappings":"IAAKA,KAAK,0BAALA,KAAK;EAALA,KAAK;EAALA,KAAK;EAALA,KAAK;EAAA,OAALA,KAAK;AAAA,EAALA,KAAK;AAMV,eAAeA,KAAK","ignoreList":[]}
@@ -0,0 +1,2 @@
1
+
2
+ //# sourceMappingURL=LockedEvent.interface.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":[],"sourceRoot":"../../../src","sources":["types/LockedEvent.interface.ts"],"mappings":"","ignoreList":[]}
@@ -4,6 +4,7 @@ export interface Spec extends TurboModule {
4
4
  getDeviceOrientation(): Promise<number>;
5
5
  lockTo(orientation: number): void;
6
6
  unlock(): void;
7
+ isLocked(): boolean;
7
8
  addListener: (eventType: string) => void;
8
9
  removeListeners: (count: number) => void;
9
10
  }
@@ -1 +1 @@
1
- {"version":3,"file":"NativeOrientationDirector.d.ts","sourceRoot":"","sources":["../../../src/NativeOrientationDirector.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAGhD,MAAM,WAAW,IAAK,SAAQ,WAAW;IACvC,uBAAuB,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC;IAC3C,oBAAoB,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC;IACxC,MAAM,CAAC,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;IAClC,MAAM,IAAI,IAAI,CAAC;IAEf,WAAW,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,IAAI,CAAC;IACzC,eAAe,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;CAC1C;;AAED,wBAA6E"}
1
+ {"version":3,"file":"NativeOrientationDirector.d.ts","sourceRoot":"","sources":["../../../src/NativeOrientationDirector.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAGhD,MAAM,WAAW,IAAK,SAAQ,WAAW;IACvC,uBAAuB,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC;IAC3C,oBAAoB,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC;IACxC,MAAM,CAAC,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;IAClC,MAAM,IAAI,IAAI,CAAC;IACf,QAAQ,IAAI,OAAO,CAAC;IAEpB,WAAW,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,IAAI,CAAC;IACzC,eAAe,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;CAC1C;;AAED,wBAA6E"}
@@ -2,6 +2,7 @@ import type { InterfaceOrientationToLocalizedStringProvider } from './types/Inte
2
2
  import { Orientation } from './types/Orientation.enum';
3
3
  import type { OrientationEvent } from './types/OrientationEvent.interface';
4
4
  import type { LockableOrientation } from './types/LockableOrientation.type';
5
+ import type { LockedEvent } from './types/LockedEvent.interface';
5
6
  declare class RNOrientationDirector {
6
7
  private static _localizedStringProvider;
7
8
  setLocalizedStringProvider(provider: InterfaceOrientationToLocalizedStringProvider): void;
@@ -9,8 +10,10 @@ declare class RNOrientationDirector {
9
10
  static getDeviceOrientation(): Promise<Orientation>;
10
11
  static lockTo(orientation: LockableOrientation): void;
11
12
  static unlock(): void;
13
+ static isLocked(): boolean;
12
14
  static listenForDeviceOrientationChanges(callback: (orientation: OrientationEvent) => void): import("react-native").EmitterSubscription;
13
15
  static listenForInterfaceOrientationChanges(callback: (orientation: OrientationEvent) => void): import("react-native").EmitterSubscription;
16
+ static listenForLockChanges(callback: (orientation: LockedEvent) => void): import("react-native").EmitterSubscription;
14
17
  static convertOrientationToHumanReadableString(orientation: Orientation): string;
15
18
  }
16
19
  export default RNOrientationDirector;
@@ -1 +1 @@
1
- {"version":3,"file":"RNOrientationDirector.d.ts","sourceRoot":"","sources":["../../../src/RNOrientationDirector.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,6CAA6C,EAAE,MAAM,4DAA4D,CAAC;AAChI,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AACvD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,oCAAoC,CAAC;AAC3E,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,kCAAkC,CAAC;AAE5E,cAAM,qBAAqB;IACzB,OAAO,CAAC,MAAM,CAAC,wBAAwB,CASnC;IAEJ,0BAA0B,CACxB,QAAQ,EAAE,6CAA6C;IAKzD,MAAM,CAAC,uBAAuB,IAAI,OAAO,CAAC,WAAW,CAAC;IAItD,MAAM,CAAC,oBAAoB,IAAI,OAAO,CAAC,WAAW,CAAC;IAInD,MAAM,CAAC,MAAM,CAAC,WAAW,EAAE,mBAAmB;IAI9C,MAAM,CAAC,MAAM;IAIb,MAAM,CAAC,iCAAiC,CACtC,QAAQ,EAAE,CAAC,WAAW,EAAE,gBAAgB,KAAK,IAAI;IAKnD,MAAM,CAAC,oCAAoC,CACzC,QAAQ,EAAE,CAAC,WAAW,EAAE,gBAAgB,KAAK,IAAI;IAQnD,MAAM,CAAC,uCAAuC,CAC5C,WAAW,EAAE,WAAW,GACvB,MAAM;CAGV;AAED,eAAe,qBAAqB,CAAC"}
1
+ {"version":3,"file":"RNOrientationDirector.d.ts","sourceRoot":"","sources":["../../../src/RNOrientationDirector.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,6CAA6C,EAAE,MAAM,4DAA4D,CAAC;AAChI,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AACvD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,oCAAoC,CAAC;AAC3E,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,kCAAkC,CAAC;AAC5E,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,+BAA+B,CAAC;AAEjE,cAAM,qBAAqB;IACzB,OAAO,CAAC,MAAM,CAAC,wBAAwB,CASnC;IAEJ,0BAA0B,CACxB,QAAQ,EAAE,6CAA6C;IAKzD,MAAM,CAAC,uBAAuB,IAAI,OAAO,CAAC,WAAW,CAAC;IAItD,MAAM,CAAC,oBAAoB,IAAI,OAAO,CAAC,WAAW,CAAC;IAInD,MAAM,CAAC,MAAM,CAAC,WAAW,EAAE,mBAAmB;IAI9C,MAAM,CAAC,MAAM;IAIb,MAAM,CAAC,QAAQ;IAIf,MAAM,CAAC,iCAAiC,CACtC,QAAQ,EAAE,CAAC,WAAW,EAAE,gBAAgB,KAAK,IAAI;IAKnD,MAAM,CAAC,oCAAoC,CACzC,QAAQ,EAAE,CAAC,WAAW,EAAE,gBAAgB,KAAK,IAAI;IAQnD,MAAM,CAAC,oBAAoB,CAAC,QAAQ,EAAE,CAAC,WAAW,EAAE,WAAW,KAAK,IAAI;IAIxE,MAAM,CAAC,uCAAuC,CAC5C,WAAW,EAAE,WAAW,GACvB,MAAM;CAGV;AAED,eAAe,qBAAqB,CAAC"}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Hook that returns whether the interface is locked.
3
+ * It listens for changes and updates the state accordingly.
4
+ */
5
+ declare const useIsInterfaceOrientationLocked: () => boolean;
6
+ export default useIsInterfaceOrientationLocked;
7
+ //# sourceMappingURL=useIsInterfaceOrientationLocked.hook.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useIsInterfaceOrientationLocked.hook.d.ts","sourceRoot":"","sources":["../../../../src/hooks/useIsInterfaceOrientationLocked.hook.ts"],"names":[],"mappings":"AAIA;;;GAGG;AACH,QAAA,MAAM,+BAA+B,eAiBpC,CAAC;AAEF,eAAe,+BAA+B,CAAC"}
@@ -3,6 +3,8 @@ import useDeviceOrientation from './hooks/useDeviceOrientation.hook';
3
3
  export { useDeviceOrientation };
4
4
  import useInterfaceOrientation from './hooks/useInterfaceOrientation.hook';
5
5
  export { useInterfaceOrientation };
6
+ import useIsInterfaceOrientationLocked from './hooks/useIsInterfaceOrientationLocked.hook';
7
+ export { useIsInterfaceOrientationLocked };
6
8
  import RNOrientationDirector from './RNOrientationDirector';
7
9
  export default RNOrientationDirector;
8
10
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAEvD,OAAO,oBAAoB,MAAM,mCAAmC,CAAC;AACrE,OAAO,EAAE,oBAAoB,EAAE,CAAC;AAEhC,OAAO,uBAAuB,MAAM,sCAAsC,CAAC;AAC3E,OAAO,EAAE,uBAAuB,EAAE,CAAC;AAEnC,OAAO,qBAAqB,MAAM,yBAAyB,CAAC;AAC5D,eAAe,qBAAqB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAEvD,OAAO,oBAAoB,MAAM,mCAAmC,CAAC;AACrE,OAAO,EAAE,oBAAoB,EAAE,CAAC;AAEhC,OAAO,uBAAuB,MAAM,sCAAsC,CAAC;AAC3E,OAAO,EAAE,uBAAuB,EAAE,CAAC;AAEnC,OAAO,+BAA+B,MAAM,8CAA8C,CAAC;AAC3F,OAAO,EAAE,+BAA+B,EAAE,CAAC;AAE3C,OAAO,qBAAqB,MAAM,yBAAyB,CAAC;AAC5D,eAAe,qBAAqB,CAAC"}
@@ -1,6 +1,7 @@
1
1
  declare enum Event {
2
2
  DeviceOrientationDidChange = "DeviceOrientationDidChange",
3
- InterfaceOrientationDidChange = "InterfaceOrientationDidChange"
3
+ InterfaceOrientationDidChange = "InterfaceOrientationDidChange",
4
+ LockDidChange = "LockDidChange"
4
5
  }
5
6
  export default Event;
6
7
  //# sourceMappingURL=Event.enum.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Event.enum.d.ts","sourceRoot":"","sources":["../../../../src/types/Event.enum.ts"],"names":[],"mappings":"AAAA,aAAK,KAAK;IACR,0BAA0B,+BAA+B;IACzD,6BAA6B,kCAAkC;CAChE;AAED,eAAe,KAAK,CAAC"}
1
+ {"version":3,"file":"Event.enum.d.ts","sourceRoot":"","sources":["../../../../src/types/Event.enum.ts"],"names":[],"mappings":"AAAA,aAAK,KAAK;IACR,0BAA0B,+BAA+B;IACzD,6BAA6B,kCAAkC;IAC/D,aAAa,kBAAkB;CAChC;AAED,eAAe,KAAK,CAAC"}
@@ -0,0 +1,4 @@
1
+ export interface LockedEvent {
2
+ locked: boolean;
3
+ }
4
+ //# sourceMappingURL=LockedEvent.interface.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"LockedEvent.interface.d.ts","sourceRoot":"","sources":["../../../../src/types/LockedEvent.interface.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,WAAW;IAC1B,MAAM,EAAE,OAAO,CAAC;CACjB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-orientation-director",
3
- "version": "1.0.1",
3
+ "version": "1.1.0",
4
4
  "description": "A Modern React Native library that allows you to access orientation",
5
5
  "main": "lib/commonjs/index",
6
6
  "module": "lib/module/index",
@@ -6,6 +6,7 @@ export interface Spec extends TurboModule {
6
6
  getDeviceOrientation(): Promise<number>;
7
7
  lockTo(orientation: number): void;
8
8
  unlock(): void;
9
+ isLocked(): boolean;
9
10
 
10
11
  addListener: (eventType: string) => void;
11
12
  removeListeners: (count: number) => void;
@@ -4,6 +4,7 @@ import type { InterfaceOrientationToLocalizedStringProvider } from './types/Inte
4
4
  import { Orientation } from './types/Orientation.enum';
5
5
  import type { OrientationEvent } from './types/OrientationEvent.interface';
6
6
  import type { LockableOrientation } from './types/LockableOrientation.type';
7
+ import type { LockedEvent } from './types/LockedEvent.interface';
7
8
 
8
9
  class RNOrientationDirector {
9
10
  private static _localizedStringProvider: InterfaceOrientationToLocalizedStringProvider =
@@ -39,6 +40,10 @@ class RNOrientationDirector {
39
40
  Module.unlock();
40
41
  }
41
42
 
43
+ static isLocked() {
44
+ return Module.isLocked();
45
+ }
46
+
42
47
  static listenForDeviceOrientationChanges(
43
48
  callback: (orientation: OrientationEvent) => void
44
49
  ) {
@@ -54,6 +59,10 @@ class RNOrientationDirector {
54
59
  );
55
60
  }
56
61
 
62
+ static listenForLockChanges(callback: (orientation: LockedEvent) => void) {
63
+ return EventEmitter.addListener(Event.LockDidChange, callback);
64
+ }
65
+
57
66
  static convertOrientationToHumanReadableString(
58
67
  orientation: Orientation
59
68
  ): string {
@@ -0,0 +1,28 @@
1
+ import React from 'react';
2
+ import RNOrientationDirector from '../RNOrientationDirector';
3
+ import type { LockedEvent } from '../types/LockedEvent.interface';
4
+
5
+ /**
6
+ * Hook that returns whether the interface is locked.
7
+ * It listens for changes and updates the state accordingly.
8
+ */
9
+ const useIsInterfaceOrientationLocked = () => {
10
+ const [orientation, setOrientation] = React.useState<boolean>(() =>
11
+ RNOrientationDirector.isLocked()
12
+ );
13
+
14
+ React.useEffect(() => {
15
+ const onChange = (event: LockedEvent) => {
16
+ setOrientation(event.locked);
17
+ };
18
+
19
+ const subscription = RNOrientationDirector.listenForLockChanges(onChange);
20
+ return () => {
21
+ subscription.remove();
22
+ };
23
+ }, []);
24
+
25
+ return orientation;
26
+ };
27
+
28
+ export default useIsInterfaceOrientationLocked;
package/src/index.tsx CHANGED
@@ -6,5 +6,8 @@ export { useDeviceOrientation };
6
6
  import useInterfaceOrientation from './hooks/useInterfaceOrientation.hook';
7
7
  export { useInterfaceOrientation };
8
8
 
9
+ import useIsInterfaceOrientationLocked from './hooks/useIsInterfaceOrientationLocked.hook';
10
+ export { useIsInterfaceOrientationLocked };
11
+
9
12
  import RNOrientationDirector from './RNOrientationDirector';
10
13
  export default RNOrientationDirector;
@@ -1,6 +1,7 @@
1
1
  enum Event {
2
2
  DeviceOrientationDidChange = 'DeviceOrientationDidChange',
3
3
  InterfaceOrientationDidChange = 'InterfaceOrientationDidChange',
4
+ LockDidChange = 'LockDidChange',
4
5
  }
5
6
 
6
7
  export default Event;
@@ -0,0 +1,3 @@
1
+ export interface LockedEvent {
2
+ locked: boolean;
3
+ }