react-native-orientation-director 2.6.5 → 3.0.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 (178) hide show
  1. package/README.md +11 -33
  2. package/android/build.gradle +19 -79
  3. package/android/src/main/AndroidManifest.xml +1 -2
  4. package/android/src/{newarch → main/java/com/orientationdirector}/OrientationDirectorModule.kt +20 -11
  5. package/android/src/main/java/com/orientationdirector/OrientationDirectorPackage.kt +15 -20
  6. package/android/src/main/java/com/orientationdirector/implementation/EventManager.kt +4 -17
  7. package/android/src/main/java/com/orientationdirector/implementation/EventManagerDelegate.kt +9 -0
  8. package/android/src/main/java/com/orientationdirector/implementation/OrientationDirectorModuleImpl.kt +11 -21
  9. package/android/src/main/java/com/orientationdirector/implementation/OrientationSensorsEventListener.kt +73 -80
  10. package/android/src/main/java/com/orientationdirector/implementation/Utils.kt +0 -54
  11. package/app.plugin.js +1 -1
  12. package/ios/OrientationDirector.h +1 -18
  13. package/ios/OrientationDirector.mm +35 -35
  14. package/ios/SharedOrientationDirectorImpl.swift +12 -0
  15. package/ios/implementation/EventManager.swift +12 -37
  16. package/ios/implementation/OrientationDirectorImpl.swift +6 -6
  17. package/lib/module/EventEmitter.js +15 -9
  18. package/lib/module/EventEmitter.js.map +1 -1
  19. package/lib/module/NativeOrientationDirector.js.map +1 -1
  20. package/lib/module/module.js +1 -2
  21. package/lib/module/module.js.map +1 -1
  22. package/lib/plugin/index.d.ts +3 -0
  23. package/lib/plugin/index.js +10 -0
  24. package/lib/plugin/withAndroidConfiguration.d.ts +3 -0
  25. package/{plugin/build/withRNOrientationMainActivity.js → lib/plugin/withAndroidConfiguration.js} +3 -3
  26. package/lib/plugin/withIosConfiguration.d.ts +3 -0
  27. package/lib/plugin/withIosConfiguration.js +62 -0
  28. package/lib/typescript/{commonjs/src → src}/EventEmitter.d.ts +5 -4
  29. package/lib/typescript/src/EventEmitter.d.ts.map +1 -0
  30. package/lib/typescript/{commonjs/src → src}/NativeOrientationDirector.d.ts +10 -3
  31. package/lib/typescript/src/NativeOrientationDirector.d.ts.map +1 -0
  32. package/lib/typescript/{module/src → src}/RNOrientationDirector.d.ts +3 -3
  33. package/lib/typescript/src/RNOrientationDirector.d.ts.map +1 -0
  34. package/lib/typescript/src/hooks/useDeviceOrientation.hook.d.ts.map +1 -0
  35. package/lib/typescript/src/hooks/useInterfaceOrientation.hook.d.ts.map +1 -0
  36. package/lib/typescript/src/hooks/useIsInterfaceOrientationLocked.hook.d.ts.map +1 -0
  37. package/lib/typescript/src/index.d.ts.map +1 -0
  38. package/lib/typescript/src/module.d.ts +4 -0
  39. package/lib/typescript/src/module.d.ts.map +1 -0
  40. package/lib/typescript/src/types/AutoRotation.enum.d.ts.map +1 -0
  41. package/lib/typescript/src/types/Event.enum.d.ts.map +1 -0
  42. package/lib/typescript/src/types/HumanReadableAutoRotationsResource.type.d.ts.map +1 -0
  43. package/lib/typescript/src/types/HumanReadableOrientationsResource.type.d.ts.map +1 -0
  44. package/lib/typescript/src/types/LockableOrientation.type.d.ts.map +1 -0
  45. package/lib/typescript/src/types/LockedEvent.interface.d.ts.map +1 -0
  46. package/lib/typescript/src/types/Orientation.enum.d.ts.map +1 -0
  47. package/lib/typescript/src/types/OrientationEvent.interface.d.ts.map +1 -0
  48. package/lib/typescript/src/types/OrientationType.enum.d.ts.map +1 -0
  49. package/package.json +72 -77
  50. package/react-native-orientation-director.podspec +4 -24
  51. package/src/EventEmitter.ts +21 -24
  52. package/src/NativeOrientationDirector.ts +8 -3
  53. package/src/module.ts +1 -3
  54. package/android/gradle.properties +0 -17
  55. package/android/src/main/AndroidManifestNew.xml +0 -2
  56. package/android/src/oldarch/OrientationDirectorModule.kt +0 -66
  57. package/android/src/test/java/com/orientationdirector/implementation/OrientationDirectorModuleImplTest.kt +0 -199
  58. package/android/src/test/java/com/orientationdirector/implementation/UtilsTest.kt +0 -314
  59. package/ios/react-native-orientation-director-Bridging-Header.h +0 -6
  60. package/lib/commonjs/EventEmitter.js +0 -48
  61. package/lib/commonjs/NativeOrientationDirector.js +0 -8
  62. package/lib/commonjs/RNOrientationDirector.js +0 -126
  63. package/lib/commonjs/hooks/useDeviceOrientation.hook.js +0 -37
  64. package/lib/commonjs/hooks/useInterfaceOrientation.hook.js +0 -37
  65. package/lib/commonjs/hooks/useIsInterfaceOrientationLocked.hook.js +0 -27
  66. package/lib/commonjs/index.js +0 -51
  67. package/lib/commonjs/module.js +0 -22
  68. package/lib/commonjs/package.json +0 -1
  69. package/lib/commonjs/types/AutoRotation.enum.js +0 -12
  70. package/lib/commonjs/types/Event.enum.js +0 -13
  71. package/lib/commonjs/types/HumanReadableAutoRotationsResource.type.js +0 -5
  72. package/lib/commonjs/types/HumanReadableOrientationsResource.type.js +0 -5
  73. package/lib/commonjs/types/LockableOrientation.type.js +0 -5
  74. package/lib/commonjs/types/LockedEvent.interface.js +0 -1
  75. package/lib/commonjs/types/Orientation.enum.js +0 -17
  76. package/lib/commonjs/types/OrientationEvent.interface.js +0 -5
  77. package/lib/commonjs/types/OrientationType.enum.js +0 -11
  78. package/lib/typescript/commonjs/example/src/App.d.ts +0 -2
  79. package/lib/typescript/commonjs/example/src/App.d.ts.map +0 -1
  80. package/lib/typescript/commonjs/example/src/AppNavigationContainer.d.ts +0 -3
  81. package/lib/typescript/commonjs/example/src/AppNavigationContainer.d.ts.map +0 -1
  82. package/lib/typescript/commonjs/example/src/screens/Explore.d.ts +0 -3
  83. package/lib/typescript/commonjs/example/src/screens/Explore.d.ts.map +0 -1
  84. package/lib/typescript/commonjs/example/src/screens/Home.d.ts +0 -3
  85. package/lib/typescript/commonjs/example/src/screens/Home.d.ts.map +0 -1
  86. package/lib/typescript/commonjs/example/src/screens/InnerExplore.d.ts +0 -3
  87. package/lib/typescript/commonjs/example/src/screens/InnerExplore.d.ts.map +0 -1
  88. package/lib/typescript/commonjs/example/src/screens/styles.d.ts +0 -51
  89. package/lib/typescript/commonjs/example/src/screens/styles.d.ts.map +0 -1
  90. package/lib/typescript/commonjs/package.json +0 -1
  91. package/lib/typescript/commonjs/src/EventEmitter.d.ts.map +0 -1
  92. package/lib/typescript/commonjs/src/NativeOrientationDirector.d.ts.map +0 -1
  93. package/lib/typescript/commonjs/src/RNOrientationDirector.d.ts +0 -62
  94. package/lib/typescript/commonjs/src/RNOrientationDirector.d.ts.map +0 -1
  95. package/lib/typescript/commonjs/src/hooks/useDeviceOrientation.hook.d.ts.map +0 -1
  96. package/lib/typescript/commonjs/src/hooks/useInterfaceOrientation.hook.d.ts.map +0 -1
  97. package/lib/typescript/commonjs/src/hooks/useIsInterfaceOrientationLocked.hook.d.ts.map +0 -1
  98. package/lib/typescript/commonjs/src/index.d.ts.map +0 -1
  99. package/lib/typescript/commonjs/src/module.d.ts +0 -6
  100. package/lib/typescript/commonjs/src/module.d.ts.map +0 -1
  101. package/lib/typescript/commonjs/src/types/AutoRotation.enum.d.ts.map +0 -1
  102. package/lib/typescript/commonjs/src/types/Event.enum.d.ts.map +0 -1
  103. package/lib/typescript/commonjs/src/types/HumanReadableAutoRotationsResource.type.d.ts.map +0 -1
  104. package/lib/typescript/commonjs/src/types/HumanReadableOrientationsResource.type.d.ts.map +0 -1
  105. package/lib/typescript/commonjs/src/types/LockableOrientation.type.d.ts.map +0 -1
  106. package/lib/typescript/commonjs/src/types/LockedEvent.interface.d.ts.map +0 -1
  107. package/lib/typescript/commonjs/src/types/Orientation.enum.d.ts.map +0 -1
  108. package/lib/typescript/commonjs/src/types/OrientationEvent.interface.d.ts.map +0 -1
  109. package/lib/typescript/commonjs/src/types/OrientationType.enum.d.ts.map +0 -1
  110. package/lib/typescript/module/example/src/App.d.ts +0 -2
  111. package/lib/typescript/module/example/src/App.d.ts.map +0 -1
  112. package/lib/typescript/module/example/src/AppNavigationContainer.d.ts +0 -3
  113. package/lib/typescript/module/example/src/AppNavigationContainer.d.ts.map +0 -1
  114. package/lib/typescript/module/example/src/screens/Explore.d.ts +0 -3
  115. package/lib/typescript/module/example/src/screens/Explore.d.ts.map +0 -1
  116. package/lib/typescript/module/example/src/screens/Home.d.ts +0 -3
  117. package/lib/typescript/module/example/src/screens/Home.d.ts.map +0 -1
  118. package/lib/typescript/module/example/src/screens/InnerExplore.d.ts +0 -3
  119. package/lib/typescript/module/example/src/screens/InnerExplore.d.ts.map +0 -1
  120. package/lib/typescript/module/example/src/screens/styles.d.ts +0 -51
  121. package/lib/typescript/module/example/src/screens/styles.d.ts.map +0 -1
  122. package/lib/typescript/module/src/EventEmitter.d.ts +0 -11
  123. package/lib/typescript/module/src/EventEmitter.d.ts.map +0 -1
  124. package/lib/typescript/module/src/NativeOrientationDirector.d.ts +0 -17
  125. package/lib/typescript/module/src/NativeOrientationDirector.d.ts.map +0 -1
  126. package/lib/typescript/module/src/RNOrientationDirector.d.ts.map +0 -1
  127. package/lib/typescript/module/src/hooks/useDeviceOrientation.hook.d.ts +0 -8
  128. package/lib/typescript/module/src/hooks/useDeviceOrientation.hook.d.ts.map +0 -1
  129. package/lib/typescript/module/src/hooks/useInterfaceOrientation.hook.d.ts +0 -8
  130. package/lib/typescript/module/src/hooks/useInterfaceOrientation.hook.d.ts.map +0 -1
  131. package/lib/typescript/module/src/hooks/useIsInterfaceOrientationLocked.hook.d.ts +0 -7
  132. package/lib/typescript/module/src/hooks/useIsInterfaceOrientationLocked.hook.d.ts.map +0 -1
  133. package/lib/typescript/module/src/index.d.ts +0 -12
  134. package/lib/typescript/module/src/index.d.ts.map +0 -1
  135. package/lib/typescript/module/src/module.d.ts +0 -6
  136. package/lib/typescript/module/src/module.d.ts.map +0 -1
  137. package/lib/typescript/module/src/types/AutoRotation.enum.d.ts +0 -6
  138. package/lib/typescript/module/src/types/AutoRotation.enum.d.ts.map +0 -1
  139. package/lib/typescript/module/src/types/Event.enum.d.ts +0 -7
  140. package/lib/typescript/module/src/types/Event.enum.d.ts.map +0 -1
  141. package/lib/typescript/module/src/types/HumanReadableAutoRotationsResource.type.d.ts +0 -3
  142. package/lib/typescript/module/src/types/HumanReadableAutoRotationsResource.type.d.ts.map +0 -1
  143. package/lib/typescript/module/src/types/HumanReadableOrientationsResource.type.d.ts +0 -3
  144. package/lib/typescript/module/src/types/HumanReadableOrientationsResource.type.d.ts.map +0 -1
  145. package/lib/typescript/module/src/types/LockableOrientation.type.d.ts +0 -3
  146. package/lib/typescript/module/src/types/LockableOrientation.type.d.ts.map +0 -1
  147. package/lib/typescript/module/src/types/LockedEvent.interface.d.ts +0 -4
  148. package/lib/typescript/module/src/types/LockedEvent.interface.d.ts.map +0 -1
  149. package/lib/typescript/module/src/types/Orientation.enum.d.ts +0 -11
  150. package/lib/typescript/module/src/types/Orientation.enum.d.ts.map +0 -1
  151. package/lib/typescript/module/src/types/OrientationEvent.interface.d.ts +0 -5
  152. package/lib/typescript/module/src/types/OrientationEvent.interface.d.ts.map +0 -1
  153. package/lib/typescript/module/src/types/OrientationType.enum.d.ts +0 -5
  154. package/lib/typescript/module/src/types/OrientationType.enum.d.ts.map +0 -1
  155. package/plugin/build/custom-mod/withBridgingHeader.d.ts +0 -12
  156. package/plugin/build/custom-mod/withBridgingHeader.js +0 -107
  157. package/plugin/build/index.d.ts +0 -3
  158. package/plugin/build/index.js +0 -27
  159. package/plugin/build/withRNOrientationAppDelegate.d.ts +0 -4
  160. package/plugin/build/withRNOrientationAppDelegate.js +0 -102
  161. package/plugin/build/withRNOrientationBridgingHeader.d.ts +0 -3
  162. package/plugin/build/withRNOrientationBridgingHeader.js +0 -27
  163. package/plugin/build/withRNOrientationMainActivity.d.ts +0 -3
  164. package/plugin/tsconfig.json +0 -9
  165. /package/lib/typescript/{module/package.json → package.json} +0 -0
  166. /package/lib/typescript/{commonjs/src → src}/hooks/useDeviceOrientation.hook.d.ts +0 -0
  167. /package/lib/typescript/{commonjs/src → src}/hooks/useInterfaceOrientation.hook.d.ts +0 -0
  168. /package/lib/typescript/{commonjs/src → src}/hooks/useIsInterfaceOrientationLocked.hook.d.ts +0 -0
  169. /package/lib/typescript/{commonjs/src → src}/index.d.ts +0 -0
  170. /package/lib/typescript/{commonjs/src → src}/types/AutoRotation.enum.d.ts +0 -0
  171. /package/lib/typescript/{commonjs/src → src}/types/Event.enum.d.ts +0 -0
  172. /package/lib/typescript/{commonjs/src → src}/types/HumanReadableAutoRotationsResource.type.d.ts +0 -0
  173. /package/lib/typescript/{commonjs/src → src}/types/HumanReadableOrientationsResource.type.d.ts +0 -0
  174. /package/lib/typescript/{commonjs/src → src}/types/LockableOrientation.type.d.ts +0 -0
  175. /package/lib/typescript/{commonjs/src → src}/types/LockedEvent.interface.d.ts +0 -0
  176. /package/lib/typescript/{commonjs/src → src}/types/Orientation.enum.d.ts +0 -0
  177. /package/lib/typescript/{commonjs/src → src}/types/OrientationEvent.interface.d.ts +0 -0
  178. /package/lib/typescript/{commonjs/src → src}/types/OrientationType.enum.d.ts +0 -0
@@ -19,51 +19,6 @@ class Utils(private val context: ReactContext) {
19
19
  }
20
20
  }
21
21
 
22
- fun convertToDeviceOrientationFrom(orientationAngles: FloatArray): Orientation {
23
- if (orientationAngles.size < 3) {
24
- return Orientation.PORTRAIT
25
- }
26
-
27
- val (_, pitchRadians, rollRadians) = orientationAngles
28
-
29
- val pitch = Math.toDegrees(pitchRadians.toDouble()).toFloat()
30
- val roll = Math.toDegrees(rollRadians.toDouble()).toFloat()
31
-
32
- val faceUpDownPitchTolerance = 30f
33
-
34
- fun isValueCloseTo(value: Float, target: Float, tolerance: Float): Boolean {
35
- return value in (target - tolerance)..(target + tolerance)
36
- }
37
-
38
- return when {
39
- // Face up: device is lying flat with screen up
40
- isValueCloseTo(pitch, 0f, faceUpDownPitchTolerance) &&
41
- isValueCloseTo(roll, 0f, faceUpDownPitchTolerance) -> Orientation.FACE_UP
42
-
43
- // Face down: device is lying flat with screen down
44
- isValueCloseTo(pitch, 0f, faceUpDownPitchTolerance) &&
45
- (isValueCloseTo(roll, 180f, faceUpDownPitchTolerance) || isValueCloseTo(
46
- roll,
47
- -180f,
48
- faceUpDownPitchTolerance
49
- )) -> Orientation.FACE_DOWN
50
-
51
- // Portrait
52
- isValueCloseTo(pitch, -90f, 45f) -> Orientation.PORTRAIT
53
-
54
- // Portrait upside down
55
- isValueCloseTo(pitch, 90f, 45f) -> Orientation.PORTRAIT_UPSIDE_DOWN
56
-
57
- // Landscape left
58
- isValueCloseTo(roll, -90f, 45f) -> Orientation.LANDSCAPE_LEFT
59
-
60
- // Landscape right
61
- isValueCloseTo(roll, 90f, 45f) -> Orientation.LANDSCAPE_RIGHT
62
-
63
- else -> Orientation.UNKNOWN
64
- }
65
- }
66
-
67
22
  fun convertToActivityOrientationFrom(orientation: Orientation): Int {
68
23
  return when (orientation) {
69
24
  Orientation.LANDSCAPE_RIGHT -> ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE
@@ -93,13 +48,4 @@ class Utils(private val context: ReactContext) {
93
48
  }
94
49
  }
95
50
 
96
- fun convertToInterfaceOrientationFrom(deviceOrientation: Orientation): Orientation {
97
- return when (deviceOrientation) {
98
- Orientation.PORTRAIT -> Orientation.PORTRAIT
99
- Orientation.LANDSCAPE_RIGHT -> Orientation.LANDSCAPE_LEFT
100
- Orientation.PORTRAIT_UPSIDE_DOWN -> Orientation.PORTRAIT_UPSIDE_DOWN
101
- Orientation.LANDSCAPE_LEFT -> Orientation.LANDSCAPE_RIGHT
102
- else -> Orientation.UNKNOWN
103
- }
104
- }
105
51
  }
package/app.plugin.js CHANGED
@@ -1 +1 @@
1
- module.exports = require('./plugin/build');
1
+ module.exports = require('./lib/plugin');
@@ -1,22 +1,5 @@
1
- #import <React/RCTEventEmitter.h>
2
-
3
- #ifdef RCT_NEW_ARCH_ENABLED
4
1
  #import <RNOrientationDirectorSpec/RNOrientationDirectorSpec.h>
5
2
 
6
- NS_ASSUME_NONNULL_BEGIN
7
-
8
- @interface OrientationDirector : RCTEventEmitter <NativeOrientationDirectorSpec>
9
-
10
- NS_ASSUME_NONNULL_END
11
-
12
- #else
13
- #import <React/RCTBridgeModule.h>
14
-
15
- @interface OrientationDirector : RCTEventEmitter <RCTBridgeModule>
16
- #endif
17
-
18
- @property (nonatomic, assign) BOOL isJsListening;
19
-
20
- +(UIInterfaceOrientationMask)getSupportedInterfaceOrientationsForWindow;
3
+ @interface OrientationDirector : NativeOrientationDirectorSpecBase <NativeOrientationDirectorSpec>
21
4
 
22
5
  @end
@@ -4,13 +4,13 @@
4
4
  This condition is needed to support use_frameworks.
5
5
  https://github.com/callstack/react-native-builder-bob/discussions/412#discussioncomment-6352402
6
6
  */
7
- #if __has_include("react_native_orientation_director-Swift.h")
8
- #import "react_native_orientation_director-Swift.h"
7
+ #if __has_include("OrientationDirector-Swift.h")
8
+ #import "OrientationDirector-Swift.h"
9
9
  #else
10
- #import "react_native_orientation_director/react_native_orientation_director-Swift.h"
10
+ #import "OrientationDirector/OrientationDirector-Swift.h"
11
11
  #endif
12
12
 
13
- static OrientationDirectorImpl *_director = [OrientationDirectorImpl new];
13
+ static OrientationDirectorImpl *_director = SharedOrientationDirectorImpl.shared;
14
14
 
15
15
  ///////////////////////////////////////////////////////////////////////////////////////
16
16
  /// EVENT EMITTER SETUP
@@ -21,7 +21,6 @@ static OrientationDirectorImpl *_director = [OrientationDirectorImpl new];
21
21
  //////////////////////////////////////////////////////////////////////////////////////////
22
22
 
23
23
  @implementation OrientationDirector
24
- RCT_EXPORT_MODULE()
25
24
 
26
25
  - (instancetype)init
27
26
  {
@@ -41,28 +40,19 @@ RCT_EXPORT_MODULE()
41
40
  return YES;
42
41
  }
43
42
 
44
- + (UIInterfaceOrientationMask)getSupportedInterfaceOrientationsForWindow
45
- {
46
- return [_director supportedInterfaceOrientations];
47
- }
48
-
49
43
  ///////////////////////////////////////////////////////////////////////////////////////
50
44
  /// EVENT EMITTER SETUP
51
45
  ///
52
- -(void)startObserving {
53
- self.isJsListening = YES;
54
- }
55
-
56
- -(void)stopObserving {
57
- self.isJsListening = NO;
46
+ -(void)emitOnDeviceOrientationDidChangeWithParams:(NSDictionary*)params {
47
+ [self emitOnDeviceOrientationChanged:params];
58
48
  }
59
49
 
60
- - (NSArray<NSString *> *)supportedEvents {
61
- return [EventManager supportedEvents];
50
+ -(void)emitOnInterfaceOrientationDidChangeWithParams:(NSDictionary*)params {
51
+ [self emitOnInterfaceOrientationChanged:params];
62
52
  }
63
53
 
64
- - (void)sendEventWithName:(NSString * _Nonnull)name params:(NSDictionary *)params {
65
- [self sendEventWithName:name body:params];
54
+ -(void)emitOnLockChangedWithParams:(NSDictionary*)params {
55
+ [self emitOnLockChanged:params];
66
56
  }
67
57
  ///
68
58
  ///////////////////////////////////////////////////////////////////////////////////////
@@ -70,28 +60,29 @@ RCT_EXPORT_MODULE()
70
60
  ///////////////////////////////////////////////////////////////////////////////////////
71
61
  /// EXPORTED METHODS
72
62
  ///
73
- RCT_EXPORT_METHOD(getInterfaceOrientation:(RCTPromiseResolveBlock)resolve
74
- reject:(RCTPromiseRejectBlock)reject)
63
+
64
+ - (void)getInterfaceOrientation:(RCTPromiseResolveBlock)resolve
65
+ reject:(RCTPromiseRejectBlock)reject
75
66
  {
76
67
  dispatch_async(dispatch_get_main_queue(), ^{
77
68
  resolve(@([_director getInterfaceOrientation]));
78
69
  });
79
70
  }
80
71
 
81
- RCT_EXPORT_METHOD(getDeviceOrientation:(RCTPromiseResolveBlock)resolve
82
- reject:(RCTPromiseRejectBlock)reject)
72
+ - (void)getDeviceOrientation:(RCTPromiseResolveBlock)resolve
73
+ reject:(RCTPromiseRejectBlock)reject
83
74
  {
84
75
  dispatch_async(dispatch_get_main_queue(), ^{
85
76
  resolve(@([_director getDeviceOrientation]));
86
77
  });
87
78
  }
88
79
 
89
- RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(isLocked)
80
+ - (NSNumber *)isLocked
90
81
  {
91
82
  return @([_director getIsLocked]);
92
83
  }
93
84
 
94
- RCT_EXPORT_METHOD(lockTo:(double)jsOrientation)
85
+ - (void)lockTo:(double)jsOrientation
95
86
  {
96
87
  NSNumber *jsOrientationNumber = @(jsOrientation);
97
88
  dispatch_async(dispatch_get_main_queue(), ^{
@@ -99,37 +90,46 @@ RCT_EXPORT_METHOD(lockTo:(double)jsOrientation)
99
90
  });
100
91
  }
101
92
 
102
- RCT_EXPORT_METHOD(unlock)
93
+ - (void)unlock
103
94
  {
104
95
  dispatch_async(dispatch_get_main_queue(), ^{
105
96
  [_director unlock];
106
97
  });
107
98
  }
108
99
 
109
- RCT_EXPORT_METHOD(resetSupportedInterfaceOrientations)
100
+ - (void)resetSupportedInterfaceOrientations
110
101
  {
111
102
  dispatch_async(dispatch_get_main_queue(), ^{
112
103
  [_director resetSupportedInterfaceOrientations];
113
104
  });
114
105
  }
115
106
 
116
- /**
117
- This method is a pure stub since we cannot access auto rotation setting in iOS
118
- */
119
- RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(isAutoRotationEnabled)
107
+ ///////////////////////////////////////////////////////////////////////////////////////
108
+ /// STUBS
109
+ ///
110
+
111
+ - (NSNumber *)isAutoRotationEnabled
120
112
  {
121
113
  return @(NO);
122
114
  }
115
+
116
+ - (void)disableOrientationSensors {}
117
+
118
+
119
+ - (void)enableOrientationSensors {}
120
+
123
121
  ///
124
122
  ///////////////////////////////////////////////////////////////////////////////////////
125
123
 
126
- // Don't compile this code when we build for the old architecture.
127
- #ifdef RCT_NEW_ARCH_ENABLED
128
124
  - (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:
129
125
  (const facebook::react::ObjCTurboModule::InitParams &)params
130
126
  {
131
127
  return std::make_shared<facebook::react::NativeOrientationDirectorSpecJSI>(params);
132
128
  }
133
- #endif
129
+
130
+ + (NSString *)moduleName
131
+ {
132
+ return @"OrientationDirector";
133
+ }
134
134
 
135
135
  @end
@@ -0,0 +1,12 @@
1
+ //
2
+ // SharedOrientationDirectorImpl.swift
3
+ // react-native-orientation-director
4
+ //
5
+ // Created by Mirko Quaglia on 14/03/26.
6
+ //
7
+
8
+ import Foundation
9
+
10
+ @objc public class SharedOrientationDirectorImpl: NSObject {
11
+ @objc public static let shared = OrientationDirectorImpl()
12
+ }
@@ -7,33 +7,25 @@
7
7
 
8
8
  import Foundation
9
9
 
10
- @objc public class EventManager: NSObject {
11
- @objc public weak var delegate: OrientationEventEmitterDelegate?
10
+ public class EventManager: NSObject {
11
+ public weak var delegate: OrientationEventEmitterDelegate?
12
12
 
13
- func sendDeviceOrientationDidChange(orientationValue: Int) {
13
+ func sendDeviceOrientationDidChange(value: Int) {
14
14
  guard let delegate = delegate else {
15
15
  return
16
16
  }
17
17
 
18
- if !delegate.isJsListening {
19
- return
20
- }
21
-
22
- let params = Dictionary(dictionaryLiteral: ("orientation", orientationValue))
23
- delegate.sendEvent(name: Event.DeviceOrientationDidChange.rawValue, params: params as NSDictionary)
18
+ let params = Dictionary(dictionaryLiteral: ("orientation", value))
19
+ delegate.emitOnDeviceOrientationDidChange(params: params as NSDictionary)
24
20
  }
25
21
 
26
- func sendInterfaceOrientationDidChange(orientationValue: Int) {
22
+ func sendInterfaceOrientationDidChange(value: Int) {
27
23
  guard let delegate = delegate else {
28
24
  return
29
25
  }
30
26
 
31
- if !delegate.isJsListening {
32
- return
33
- }
34
-
35
- let params = Dictionary(dictionaryLiteral: ("orientation", orientationValue))
36
- delegate.sendEvent(name: Event.InterfaceOrientationDidChange.rawValue, params: params as NSDictionary)
27
+ let params = Dictionary(dictionaryLiteral: ("orientation", value))
28
+ delegate.emitOnInterfaceOrientationDidChange(params: params as NSDictionary)
37
29
  }
38
30
 
39
31
  func sendLockDidChange(value: Bool) {
@@ -41,30 +33,13 @@ import Foundation
41
33
  return
42
34
  }
43
35
 
44
- if !delegate.isJsListening {
45
- return
46
- }
47
-
48
36
  let params = Dictionary(dictionaryLiteral: ("locked", value))
49
- delegate.sendEvent(name: Event.LockDidChange.rawValue, params: params as NSDictionary)
37
+ delegate.emitOnLockChanged(params: params as NSDictionary)
50
38
  }
51
39
  }
52
40
 
53
41
  @objc public protocol OrientationEventEmitterDelegate {
54
- var isJsListening: Bool { get set }
55
-
56
- func sendEvent(name: String, params: NSDictionary)
57
- }
58
-
59
- public extension EventManager {
60
-
61
- enum Event: String, CaseIterable {
62
- case DeviceOrientationDidChange
63
- case InterfaceOrientationDidChange
64
- case LockDidChange
65
- }
66
-
67
- @objc static var supportedEvents: [String] {
68
- return Event.allCases.map(\.rawValue)
69
- }
42
+ func emitOnLockChanged(params: NSDictionary)
43
+ func emitOnDeviceOrientationDidChange(params: NSDictionary)
44
+ func emitOnInterfaceOrientationDidChange(params: NSDictionary)
70
45
  }
@@ -8,7 +8,7 @@
8
8
  import Foundation
9
9
  import UIKit
10
10
 
11
- @objc public class OrientationDirectorImpl: NSObject {
11
+ @objcMembers public class OrientationDirectorImpl: NSObject {
12
12
  private static let TAG = "OrientationDirectorImpl"
13
13
 
14
14
  private let bundleManager: BundleManager = BundleManager()
@@ -19,7 +19,7 @@ import UIKit
19
19
  private var lastInterfaceOrientation = Orientation.UNKNOWN
20
20
  private var lastDeviceOrientation = Orientation.UNKNOWN
21
21
  private var isLocked = false
22
-
22
+
23
23
  /// # Only on iOS < 16
24
24
  /// This variable is needed to prevent a loop where
25
25
  /// we lock the interface to a specific orientation
@@ -174,11 +174,11 @@ import UIKit
174
174
 
175
175
  private func onOrientationChanged(uiDeviceOrientation: UIDeviceOrientation) {
176
176
  let deviceOrientation = utils.convertToOrientationFrom(deviceOrientation: uiDeviceOrientation)
177
-
177
+
178
178
  if (!self.isLocking) {
179
- self.eventManager.sendDeviceOrientationDidChange(orientationValue: deviceOrientation.rawValue)
179
+ self.eventManager.sendDeviceOrientationDidChange(value: deviceOrientation.rawValue)
180
180
  }
181
-
181
+
182
182
  lastDeviceOrientation = deviceOrientation
183
183
  adaptInterfaceTo(deviceOrientation: deviceOrientation)
184
184
  }
@@ -203,7 +203,7 @@ import UIKit
203
203
  }
204
204
 
205
205
  private func updateLastInterfaceOrientationTo(value: Orientation) {
206
- self.eventManager.sendInterfaceOrientationDidChange(orientationValue: value.rawValue)
206
+ self.eventManager.sendInterfaceOrientationDidChange(value: value.rawValue)
207
207
  lastInterfaceOrientation = value
208
208
  }
209
209
 
@@ -1,25 +1,25 @@
1
1
  "use strict";
2
2
 
3
3
  import { Platform } from 'react-native';
4
- import Module, { ModuleEventEmitter } from "./module.js";
5
- import Event from "./types/Event.enum.js";
4
+ import Module from "./module.js";
6
5
  class EventEmitter {
6
+ static androidListenerCount = 0;
7
7
  static addDeviceOrientationDidChangeListener(callback) {
8
- let listener = ModuleEventEmitter.addListener(Event.DeviceOrientationDidChange, callback);
8
+ let listener = Module.onDeviceOrientationChanged(callback);
9
9
  if (Platform.OS !== 'android') {
10
10
  return listener;
11
11
  }
12
- const listenerCount = ModuleEventEmitter.listenerCount(Event.DeviceOrientationDidChange);
13
- if (listenerCount === 1) {
12
+ EventEmitter.androidListenerCount++;
13
+ if (EventEmitter.androidListenerCount === 1) {
14
14
  Module.enableOrientationSensors();
15
15
  }
16
16
  return EventEmitter.createDeviceOrientationListenerProxy(listener);
17
17
  }
18
18
  static addInterfaceOrientationDidChangeListener(callback) {
19
- return ModuleEventEmitter.addListener(Event.InterfaceOrientationDidChange, callback);
19
+ return Module.onInterfaceOrientationChanged(callback);
20
20
  }
21
21
  static addLockDidChangeListener(callback) {
22
- return ModuleEventEmitter.addListener(Event.LockDidChange, callback);
22
+ return Module.onLockChanged(callback);
23
23
  }
24
24
  static createDeviceOrientationListenerProxy(listener) {
25
25
  const handler = {
@@ -32,10 +32,16 @@ class EventEmitter {
32
32
  };
33
33
  return new Proxy(listener, handler);
34
34
  function disableOrientationSensorsIfLastListener() {
35
- const listenerCount = ModuleEventEmitter.listenerCount(Event.DeviceOrientationDidChange);
36
- if (listenerCount === 1) {
35
+ if (EventEmitter.androidListenerCount === 1) {
36
+ EventEmitter.androidListenerCount = 0;
37
37
  Module.disableOrientationSensors();
38
+ return;
38
39
  }
40
+ if (EventEmitter.androidListenerCount === 0) {
41
+ return;
42
+ }
43
+ EventEmitter.androidListenerCount--;
44
+ return;
39
45
  }
40
46
  }
41
47
  }
@@ -1 +1 @@
1
- {"version":3,"names":["Platform","Module","ModuleEventEmitter","Event","EventEmitter","addDeviceOrientationDidChangeListener","callback","listener","addListener","DeviceOrientationDidChange","OS","listenerCount","enableOrientationSensors","createDeviceOrientationListenerProxy","addInterfaceOrientationDidChangeListener","InterfaceOrientationDidChange","addLockDidChangeListener","LockDidChange","handler","get","target","propertyKey","receiver","disableOrientationSensorsIfLastListener","Reflect","Proxy","disableOrientationSensors"],"sourceRoot":"../../src","sources":["EventEmitter.ts"],"mappings":";;AAAA,SAASA,QAAQ,QAAkC,cAAc;AACjE,OAAOC,MAAM,IAAIC,kBAAkB,QAAQ,aAAU;AACrD,OAAOC,KAAK,MAAM,uBAAoB;AAItC,MAAMC,YAAY,CAAC;EACjB,OAAOC,qCAAqCA,CAC1CC,QAAiD,EACjD;IACA,IAAIC,QAAQ,GAAGL,kBAAkB,CAACM,WAAW,CAC3CL,KAAK,CAACM,0BAA0B,EAChCH,QACF,CAAC;IAED,IAAIN,QAAQ,CAACU,EAAE,KAAK,SAAS,EAAE;MAC7B,OAAOH,QAAQ;IACjB;IAEA,MAAMI,aAAa,GAAGT,kBAAkB,CAACS,aAAa,CACpDR,KAAK,CAACM,0BACR,CAAC;IAED,IAAIE,aAAa,KAAK,CAAC,EAAE;MACvBV,MAAM,CAACW,wBAAwB,CAAC,CAAC;IACnC;IAEA,OAAOR,YAAY,CAACS,oCAAoC,CAACN,QAAQ,CAAC;EACpE;EAEA,OAAOO,wCAAwCA,CAC7CR,QAAiD,EACjD;IACA,OAAOJ,kBAAkB,CAACM,WAAW,CACnCL,KAAK,CAACY,6BAA6B,EACnCT,QACF,CAAC;EACH;EAEA,OAAOU,wBAAwBA,CAACV,QAAsC,EAAE;IACtE,OAAOJ,kBAAkB,CAACM,WAAW,CAACL,KAAK,CAACc,aAAa,EAAEX,QAAQ,CAAC;EACtE;EAEA,OAAeO,oCAAoCA,CACjDN,QAA6B,EAC7B;IACA,MAAMW,OAA0C,GAAG;MACjDC,GAAGA,CAACC,MAAM,EAAEC,WAAW,EAAEC,QAAQ,EAAE;QACjC,IAAID,WAAW,KAAK,QAAQ,EAAE;UAC5BE,uCAAuC,CAAC,CAAC;QAC3C;QACA,OAAOC,OAAO,CAACL,GAAG,CAACC,MAAM,EAAEC,WAAW,EAAEC,QAAQ,CAAC;MACnD;IACF,CAAC;IAED,OAAO,IAAIG,KAAK,CAAClB,QAAQ,EAAEW,OAAO,CAAC;IAEnC,SAASK,uCAAuCA,CAAA,EAAG;MACjD,MAAMZ,aAAa,GAAGT,kBAAkB,CAACS,aAAa,CACpDR,KAAK,CAACM,0BACR,CAAC;MAED,IAAIE,aAAa,KAAK,CAAC,EAAE;QACvBV,MAAM,CAACyB,yBAAyB,CAAC,CAAC;MACpC;IACF;EACF;AACF;AAEA,eAAetB,YAAY","ignoreList":[]}
1
+ {"version":3,"names":["Platform","Module","EventEmitter","androidListenerCount","addDeviceOrientationDidChangeListener","callback","listener","onDeviceOrientationChanged","OS","enableOrientationSensors","createDeviceOrientationListenerProxy","addInterfaceOrientationDidChangeListener","onInterfaceOrientationChanged","addLockDidChangeListener","onLockChanged","handler","get","target","propertyKey","receiver","disableOrientationSensorsIfLastListener","Reflect","Proxy","disableOrientationSensors"],"sourceRoot":"../../src","sources":["EventEmitter.ts"],"mappings":";;AAAA,SAASA,QAAQ,QAAgC,cAAc;AAC/D,OAAOC,MAAM,MAAM,aAAU;AAI7B,MAAMC,YAAY,CAAC;EACjB,OAAeC,oBAAoB,GAAG,CAAC;EAEvC,OAAOC,qCAAqCA,CAC1CC,QAAiD,EACjD;IACA,IAAIC,QAAQ,GAAGL,MAAM,CAACM,0BAA0B,CAACF,QAAQ,CAAC;IAE1D,IAAIL,QAAQ,CAACQ,EAAE,KAAK,SAAS,EAAE;MAC7B,OAAOF,QAAQ;IACjB;IAEAJ,YAAY,CAACC,oBAAoB,EAAE;IACnC,IAAID,YAAY,CAACC,oBAAoB,KAAK,CAAC,EAAE;MAC3CF,MAAM,CAACQ,wBAAwB,CAAC,CAAC;IACnC;IAEA,OAAOP,YAAY,CAACQ,oCAAoC,CAACJ,QAAQ,CAAC;EACpE;EAEA,OAAOK,wCAAwCA,CAC7CN,QAAiD,EACjD;IACA,OAAOJ,MAAM,CAACW,6BAA6B,CAACP,QAAQ,CAAC;EACvD;EAEA,OAAOQ,wBAAwBA,CAACR,QAAsC,EAAE;IACtE,OAAOJ,MAAM,CAACa,aAAa,CAACT,QAAQ,CAAC;EACvC;EAEA,OAAeK,oCAAoCA,CACjDJ,QAA2B,EAC3B;IACA,MAAMS,OAAwC,GAAG;MAC/CC,GAAGA,CAACC,MAAM,EAAEC,WAAW,EAAEC,QAAQ,EAAE;QACjC,IAAID,WAAW,KAAK,QAAQ,EAAE;UAC5BE,uCAAuC,CAAC,CAAC;QAC3C;QACA,OAAOC,OAAO,CAACL,GAAG,CAACC,MAAM,EAAEC,WAAW,EAAEC,QAAQ,CAAC;MACnD;IACF,CAAC;IAED,OAAO,IAAIG,KAAK,CAAChB,QAAQ,EAAES,OAAO,CAAC;IAEnC,SAASK,uCAAuCA,CAAA,EAAG;MACjD,IAAIlB,YAAY,CAACC,oBAAoB,KAAK,CAAC,EAAE;QAC3CD,YAAY,CAACC,oBAAoB,GAAG,CAAC;QACrCF,MAAM,CAACsB,yBAAyB,CAAC,CAAC;QAClC;MACF;MAEA,IAAIrB,YAAY,CAACC,oBAAoB,KAAK,CAAC,EAAE;QAC3C;MACF;MAEAD,YAAY,CAACC,oBAAoB,EAAE;MACnC;IACF;EACF;AACF;AAEA,eAAeD,YAAY","ignoreList":[]}
@@ -1 +1 @@
1
- {"version":3,"names":["TurboModuleRegistry","getEnforcing"],"sourceRoot":"../../src","sources":["NativeOrientationDirector.ts"],"mappings":";;AACA,SAASA,mBAAmB,QAAQ,cAAc;AA0BlD,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;AA+BlD,eAAeA,mBAAmB,CAACC,YAAY,CAAO,qBAAqB,CAAC","ignoreList":[]}
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
 
3
- import { NativeEventEmitter, NativeModules, Platform } from 'react-native';
3
+ import { NativeModules, Platform } from 'react-native';
4
4
  const LINKING_ERROR = `The package 'react-native-orientation-director' doesn't seem to be linked. Make sure: \n\n` + Platform.select({
5
5
  ios: "- You have run 'pod install'\n",
6
6
  default: ''
@@ -14,6 +14,5 @@ const OrientationDirectorModule = Module ? Module : new Proxy({}, {
14
14
  throw new Error(LINKING_ERROR);
15
15
  }
16
16
  });
17
- export const ModuleEventEmitter = new NativeEventEmitter(Module);
18
17
  export default OrientationDirectorModule;
19
18
  //# sourceMappingURL=module.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["NativeEventEmitter","NativeModules","Platform","LINKING_ERROR","select","ios","default","isTurboModuleEnabled","global","__turboModuleProxy","Module","require","OrientationDirector","OrientationDirectorModule","Proxy","get","Error","ModuleEventEmitter"],"sourceRoot":"../../src","sources":["module.ts"],"mappings":";;AAAA,SAASA,kBAAkB,EAAEC,aAAa,EAAEC,QAAQ,QAAQ,cAAc;AAG1E,MAAMC,aAAa,GACjB,4FAA4F,GAC5FD,QAAQ,CAACE,MAAM,CAAC;EAAEC,GAAG,EAAE,gCAAgC;EAAEC,OAAO,EAAE;AAAG,CAAC,CAAC,GACvE,sDAAsD,GACtD,+BAA+B;;AAEjC;AACA,MAAMC,oBAAoB,GAAGC,MAAM,CAACC,kBAAkB,IAAI,IAAI;AAE9D,MAAMC,MAAM,GAAGH,oBAAoB,GAC/BI,OAAO,CAAC,6BAA6B,CAAC,CAACL,OAAO,GAC9CL,aAAa,CAACW,mBAAmB;AAErC,MAAMC,yBAAyB,GAAGH,MAAM,GACpCA,MAAM,GACN,IAAII,KAAK,CACP,CAAC,CAAC,EACF;EACEC,GAAGA,CAAA,EAAG;IACJ,MAAM,IAAIC,KAAK,CAACb,aAAa,CAAC;EAChC;AACF,CACF,CAAC;AAEL,OAAO,MAAMc,kBAAkB,GAAG,IAAIjB,kBAAkB,CAACU,MAAM,CAAC;AAEhE,eAAeG,yBAAyB","ignoreList":[]}
1
+ {"version":3,"names":["NativeModules","Platform","LINKING_ERROR","select","ios","default","isTurboModuleEnabled","global","__turboModuleProxy","Module","require","OrientationDirector","OrientationDirectorModule","Proxy","get","Error"],"sourceRoot":"../../src","sources":["module.ts"],"mappings":";;AAAA,SAASA,aAAa,EAAEC,QAAQ,QAAQ,cAAc;AAGtD,MAAMC,aAAa,GACjB,4FAA4F,GAC5FD,QAAQ,CAACE,MAAM,CAAC;EAAEC,GAAG,EAAE,gCAAgC;EAAEC,OAAO,EAAE;AAAG,CAAC,CAAC,GACvE,sDAAsD,GACtD,+BAA+B;;AAEjC;AACA,MAAMC,oBAAoB,GAAGC,MAAM,CAACC,kBAAkB,IAAI,IAAI;AAE9D,MAAMC,MAAM,GAAGH,oBAAoB,GAC/BI,OAAO,CAAC,6BAA6B,CAAC,CAACL,OAAO,GAC9CL,aAAa,CAACW,mBAAmB;AAErC,MAAMC,yBAAyB,GAAGH,MAAM,GACpCA,MAAM,GACN,IAAII,KAAK,CACP,CAAC,CAAC,EACF;EACEC,GAAGA,CAAA,EAAG;IACJ,MAAM,IAAIC,KAAK,CAACb,aAAa,CAAC;EAChC;AACF,CACF,CAAC;AAEL,eAAeU,yBAAyB","ignoreList":[]}
@@ -0,0 +1,3 @@
1
+ import { type ConfigPlugin } from 'expo/config-plugins';
2
+ declare const withYourLibrary: ConfigPlugin;
3
+ export default withYourLibrary;
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const withAndroidConfiguration_1 = require("./withAndroidConfiguration");
4
+ const withIosConfiguration_1 = require("./withIosConfiguration");
5
+ const withYourLibrary = (config) => {
6
+ config = (0, withAndroidConfiguration_1.withAndroidConfiguration)(config);
7
+ config = (0, withIosConfiguration_1.withIosConfiguration)(config);
8
+ return config;
9
+ };
10
+ exports.default = withYourLibrary;
@@ -0,0 +1,3 @@
1
+ import { type ConfigPlugin } from 'expo/config-plugins';
2
+ export declare const withAndroidConfiguration: ConfigPlugin;
3
+ export declare function ktFileUpdater(originalContents: string): string;
@@ -1,13 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.withRNOrientationMainActivity = void 0;
3
+ exports.withAndroidConfiguration = void 0;
4
4
  exports.ktFileUpdater = ktFileUpdater;
5
5
  const config_plugins_1 = require("@expo/config-plugins");
6
6
  const generateCode_1 = require("@expo/config-plugins/build/utils/generateCode");
7
- const withRNOrientationMainActivity = (config) => {
7
+ const withAndroidConfiguration = (config) => {
8
8
  return (0, config_plugins_1.withMainActivity)(config, readMainActivityFileAndUpdateContents);
9
9
  };
10
- exports.withRNOrientationMainActivity = withRNOrientationMainActivity;
10
+ exports.withAndroidConfiguration = withAndroidConfiguration;
11
11
  async function readMainActivityFileAndUpdateContents(config) {
12
12
  const { modResults: mainActivityFile } = config;
13
13
  const worker = getCompatibleFileUpdater(mainActivityFile.language);
@@ -0,0 +1,3 @@
1
+ import { type ConfigPlugin } from 'expo/config-plugins';
2
+ export declare const withIosConfiguration: ConfigPlugin;
3
+ export declare function swiftFileUpdater(originalContents: string, sdkVersion?: string): string;
@@ -0,0 +1,62 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.withIosConfiguration = void 0;
4
+ exports.swiftFileUpdater = swiftFileUpdater;
5
+ const config_plugins_1 = require("@expo/config-plugins");
6
+ const generateCode_1 = require("@expo/config-plugins/build/utils/generateCode");
7
+ const withIosConfiguration = (config) => {
8
+ return (0, config_plugins_1.withAppDelegate)(config, readAppDelegateFileAndUpdateContents);
9
+ };
10
+ exports.withIosConfiguration = withIosConfiguration;
11
+ async function readAppDelegateFileAndUpdateContents(config) {
12
+ const { modResults: appDelegateFile } = config;
13
+ if (appDelegateFile.language !== 'swift') {
14
+ throw new Error(`Cannot add React Native Orientation Director code to AppDelegate of language "${appDelegateFile.language}"`);
15
+ }
16
+ appDelegateFile.contents = swiftFileUpdater(appDelegateFile.contents, config.sdkVersion);
17
+ return config;
18
+ }
19
+ function swiftFileUpdater(originalContents, sdkVersion) {
20
+ const methodPrefix = computeMethodPrefix(sdkVersion);
21
+ const libraryImportCodeBlock = `import OrientationDirector`;
22
+ const rightBeforeAnnotation = /@main|@UIApplicationMain/g;
23
+ const withImport = (0, generateCode_1.mergeContents)({
24
+ tag: '@react-native-orientation-director/library-import',
25
+ src: originalContents,
26
+ newSrc: libraryImportCodeBlock,
27
+ anchor: rightBeforeAnnotation,
28
+ offset: -1,
29
+ comment: '// React Native Orientation Director',
30
+ });
31
+ const supportedInterfaceOrientationsCodeBlock = `\n ${methodPrefix} func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask {
32
+ return SharedOrientationDirectorImpl.shared.supportedInterfaceOrientations
33
+ }\n`;
34
+ const rightBeforeLastClosingBrace = /didFinishLaunchingWithOptions:\s*launchOptions\)/g;
35
+ const pasteInTheListJustAfterTheClosingBracket = 2;
36
+ const completedMerge = (0, generateCode_1.mergeContents)({
37
+ tag: '@react-native-orientation-director/supportedInterfaceOrientations-implementation',
38
+ src: withImport.contents,
39
+ newSrc: supportedInterfaceOrientationsCodeBlock,
40
+ anchor: rightBeforeLastClosingBrace,
41
+ offset: pasteInTheListJustAfterTheClosingBracket,
42
+ comment: '// React Native Orientation Director',
43
+ });
44
+ return completedMerge.contents;
45
+ function computeMethodPrefix(_sdkVersion) {
46
+ if (!_sdkVersion) {
47
+ return '';
48
+ }
49
+ const rawMajor = _sdkVersion.split('.').at(0);
50
+ if (!rawMajor) {
51
+ return '';
52
+ }
53
+ const major = Number(rawMajor);
54
+ if (Number.isNaN(major)) {
55
+ return '';
56
+ }
57
+ if (major === 53) {
58
+ return '';
59
+ }
60
+ return 'public override';
61
+ }
62
+ }
@@ -1,10 +1,11 @@
1
- import { type EmitterSubscription } from 'react-native';
1
+ import { type EventSubscription } from 'react-native';
2
2
  import type { OrientationEvent } from './types/OrientationEvent.interface';
3
3
  import type { LockedEvent } from './types/LockedEvent.interface';
4
4
  declare class EventEmitter {
5
- static addDeviceOrientationDidChangeListener(callback: (orientation: OrientationEvent) => void): EmitterSubscription;
6
- static addInterfaceOrientationDidChangeListener(callback: (orientation: OrientationEvent) => void): EmitterSubscription;
7
- static addLockDidChangeListener(callback: (event: LockedEvent) => void): EmitterSubscription;
5
+ private static androidListenerCount;
6
+ static addDeviceOrientationDidChangeListener(callback: (orientation: OrientationEvent) => void): EventSubscription;
7
+ static addInterfaceOrientationDidChangeListener(callback: (orientation: OrientationEvent) => void): EventSubscription;
8
+ static addLockDidChangeListener(callback: (event: LockedEvent) => void): EventSubscription;
8
9
  private static createDeviceOrientationListenerProxy;
9
10
  }
10
11
  export default EventEmitter;
@@ -0,0 +1 @@
1
+ {"version":3,"file":"EventEmitter.d.ts","sourceRoot":"","sources":["../../../src/EventEmitter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,KAAK,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAEhE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,oCAAoC,CAAC;AAC3E,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,+BAA+B,CAAC;AAEjE,cAAM,YAAY;IAChB,OAAO,CAAC,MAAM,CAAC,oBAAoB,CAAK;IAExC,MAAM,CAAC,qCAAqC,CAC1C,QAAQ,EAAE,CAAC,WAAW,EAAE,gBAAgB,KAAK,IAAI;IAgBnD,MAAM,CAAC,wCAAwC,CAC7C,QAAQ,EAAE,CAAC,WAAW,EAAE,gBAAgB,KAAK,IAAI;IAKnD,MAAM,CAAC,wBAAwB,CAAC,QAAQ,EAAE,CAAC,KAAK,EAAE,WAAW,KAAK,IAAI;IAItE,OAAO,CAAC,MAAM,CAAC,oCAAoC;CA6BpD;AAED,eAAe,YAAY,CAAC"}
@@ -1,4 +1,4 @@
1
- import type { TurboModule } from 'react-native';
1
+ import { type CodegenTypes, type TurboModule } from 'react-native';
2
2
  export interface Spec extends TurboModule {
3
3
  getInterfaceOrientation(): Promise<number>;
4
4
  getDeviceOrientation(): Promise<number>;
@@ -9,8 +9,15 @@ export interface Spec extends TurboModule {
9
9
  isAutoRotationEnabled(): boolean;
10
10
  enableOrientationSensors(): void;
11
11
  disableOrientationSensors(): void;
12
- addListener: (eventType: string) => void;
13
- removeListeners: (count: number) => void;
12
+ readonly onDeviceOrientationChanged: CodegenTypes.EventEmitter<{
13
+ orientation: number;
14
+ }>;
15
+ readonly onInterfaceOrientationChanged: CodegenTypes.EventEmitter<{
16
+ orientation: number;
17
+ }>;
18
+ readonly onLockChanged: CodegenTypes.EventEmitter<{
19
+ locked: boolean;
20
+ }>;
14
21
  }
15
22
  declare const _default: Spec;
16
23
  export default _default;
@@ -0,0 +1 @@
1
+ {"version":3,"file":"NativeOrientationDirector.d.ts","sourceRoot":"","sources":["../../../src/NativeOrientationDirector.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,YAAY,EAAE,KAAK,WAAW,EAAE,MAAM,cAAc,CAAC;AAGnE,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;IACpB,mCAAmC,IAAI,IAAI,CAAC;IAO5C,qBAAqB,IAAI,OAAO,CAAC;IACjC,wBAAwB,IAAI,IAAI,CAAC;IACjC,yBAAyB,IAAI,IAAI,CAAC;IAKlC,QAAQ,CAAC,0BAA0B,EAAE,YAAY,CAAC,YAAY,CAAC;QAC7D,WAAW,EAAE,MAAM,CAAC;KACrB,CAAC,CAAC;IACH,QAAQ,CAAC,6BAA6B,EAAE,YAAY,CAAC,YAAY,CAAC;QAChE,WAAW,EAAE,MAAM,CAAC;KACrB,CAAC,CAAC;IACH,QAAQ,CAAC,aAAa,EAAE,YAAY,CAAC,YAAY,CAAC;QAAE,MAAM,EAAE,OAAO,CAAA;KAAE,CAAC,CAAC;CACxE;;AAED,wBAA6E"}