react-native-orientation-director 1.3.0 → 2.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 (56) hide show
  1. package/README.md +30 -18
  2. package/android/build.gradle +13 -1
  3. package/android/gradle.properties +12 -0
  4. package/android/src/main/java/com/orientationdirector/OrientationDirectorPackage.kt +5 -4
  5. package/android/src/main/java/com/orientationdirector/implementation/EventManager.kt +0 -1
  6. package/android/src/main/java/com/orientationdirector/implementation/LifecycleListener.kt +1 -1
  7. package/android/src/main/java/com/orientationdirector/implementation/Orientation.kt +2 -0
  8. package/android/src/main/java/com/orientationdirector/implementation/{OrientationDirectorImpl.kt → OrientationDirectorModuleImpl.kt} +47 -33
  9. package/android/src/main/java/com/orientationdirector/implementation/OrientationSensorsEventListener.kt +79 -0
  10. package/android/src/main/java/com/orientationdirector/implementation/Utils.kt +28 -15
  11. package/android/src/newarch/OrientationDirectorModule.kt +59 -0
  12. package/android/src/oldarch/OrientationDirectorModule.kt +66 -0
  13. package/android/src/test/java/com/orientationdirector/implementation/OrientationDirectorModuleImplTest.kt +188 -0
  14. package/android/src/test/java/com/orientationdirector/implementation/UtilsTest.kt +314 -0
  15. package/ios/OrientationDirector.mm +12 -37
  16. package/lib/commonjs/EventEmitter.js +50 -0
  17. package/lib/commonjs/EventEmitter.js.map +1 -0
  18. package/lib/commonjs/NativeOrientationDirector.js.map +1 -1
  19. package/lib/commonjs/RNOrientationDirector.js +6 -8
  20. package/lib/commonjs/RNOrientationDirector.js.map +1 -1
  21. package/lib/commonjs/hooks/useDeviceOrientation.hook.js +1 -1
  22. package/lib/commonjs/hooks/useDeviceOrientation.hook.js.map +1 -1
  23. package/lib/commonjs/hooks/useInterfaceOrientation.hook.js +1 -1
  24. package/lib/commonjs/hooks/useInterfaceOrientation.hook.js.map +1 -1
  25. package/lib/commonjs/hooks/useIsInterfaceOrientationLocked.hook.js +1 -1
  26. package/lib/commonjs/hooks/useIsInterfaceOrientationLocked.hook.js.map +1 -1
  27. package/lib/commonjs/index.js +1 -1
  28. package/lib/commonjs/index.js.map +1 -1
  29. package/lib/commonjs/module.js +2 -2
  30. package/lib/commonjs/module.js.map +1 -1
  31. package/lib/module/EventEmitter.js +41 -0
  32. package/lib/module/EventEmitter.js.map +1 -0
  33. package/lib/module/NativeOrientationDirector.js.map +1 -1
  34. package/lib/module/RNOrientationDirector.js +5 -5
  35. package/lib/module/RNOrientationDirector.js.map +1 -1
  36. package/lib/module/module.js +1 -1
  37. package/lib/module/module.js.map +1 -1
  38. package/lib/typescript/src/EventEmitter.d.ts +11 -0
  39. package/lib/typescript/src/EventEmitter.d.ts.map +1 -0
  40. package/lib/typescript/src/NativeOrientationDirector.d.ts +3 -1
  41. package/lib/typescript/src/NativeOrientationDirector.d.ts.map +1 -1
  42. package/lib/typescript/src/RNOrientationDirector.d.ts +1 -1
  43. package/lib/typescript/src/RNOrientationDirector.d.ts.map +1 -1
  44. package/lib/typescript/src/module.d.ts +1 -1
  45. package/lib/typescript/src/module.d.ts.map +1 -1
  46. package/lib/typescript/src/types/Orientation.enum.d.ts.map +1 -1
  47. package/package.json +1 -1
  48. package/src/EventEmitter.ts +70 -0
  49. package/src/NativeOrientationDirector.ts +12 -1
  50. package/src/RNOrientationDirector.ts +6 -9
  51. package/src/module.ts +1 -1
  52. package/src/types/Orientation.enum.ts +0 -2
  53. package/android/src/main/java/com/orientationdirector/OrientationDirectorModule.kt +0 -65
  54. package/android/src/main/java/com/orientationdirector/implementation/SensorListener.kt +0 -26
  55. package/android/src/newarch/OrientationDirectorSpec.kt +0 -7
  56. package/android/src/oldarch/OrientationDirectorSpec.kt +0 -18
@@ -0,0 +1,188 @@
1
+ package com.orientationdirector.implementation
2
+
3
+ import android.os.Looper
4
+ import androidx.test.core.app.ApplicationProvider
5
+ import com.facebook.react.bridge.BridgeReactContext
6
+ import org.junit.Assert.*
7
+ import org.junit.Before
8
+ import org.junit.Test
9
+ import org.junit.runner.RunWith
10
+ import org.mockito.InjectMocks
11
+ import org.mockito.Mock
12
+ import org.mockito.Mockito.`when`
13
+ import org.mockito.MockitoAnnotations
14
+ import org.robolectric.RobolectricTestRunner
15
+ import org.robolectric.annotation.Config
16
+
17
+ @RunWith(RobolectricTestRunner::class)
18
+ class OrientationDirectorModuleImplTest {
19
+ private var context = BridgeReactContext(ApplicationProvider.getApplicationContext())
20
+
21
+ @Mock
22
+ private val mockEventManager = EventManager(context)
23
+
24
+ @Mock
25
+ private val mockAutoRotationObserver = AutoRotationObserver(
26
+ context,
27
+ android.os.Handler(Looper.getMainLooper())
28
+ )
29
+
30
+ @InjectMocks
31
+ private val mModule = OrientationDirectorModuleImpl(context)
32
+
33
+ @Before
34
+ fun setup() {
35
+ MockitoAnnotations.openMocks(this)
36
+
37
+ // We stub this method because adaptInterfaceTo checks it
38
+ `when`(mockAutoRotationObserver.getLastAutoRotationStatus()).thenReturn(true)
39
+ }
40
+
41
+ @Test
42
+ @Config(
43
+ qualifiers = "port"
44
+ )
45
+ fun assert_initial_orientation_matches_portrait() {
46
+ val orientation = mModule.getInterfaceOrientation()
47
+
48
+ assertEquals(
49
+ "When user starts the app with the device in portrait, the initial interface should be portrait",
50
+ Orientation.PORTRAIT,
51
+ orientation
52
+ )
53
+ }
54
+
55
+ @Test
56
+ @Config(
57
+ qualifiers = "land"
58
+ )
59
+ fun assert_initial_orientation_matches_landscape_left() {
60
+ val orientation = mModule.getInterfaceOrientation()
61
+
62
+ assertEquals(
63
+ "When user starts the app with the device in landscape, the initial interface should be landscape left",
64
+ Orientation.LANDSCAPE_LEFT,
65
+ orientation
66
+ )
67
+ }
68
+
69
+ @Test
70
+ fun assert_initial_device_orientation_matches_unknown_at_startup() {
71
+ val orientation = mModule.getDeviceOrientation()
72
+
73
+ assertEquals(
74
+ "When user starts the app, the initial device orientation should be unknown",
75
+ Orientation.UNKNOWN,
76
+ orientation
77
+ )
78
+ }
79
+
80
+ @Test
81
+ fun assert_initial_is_locked_matches_false_at_startup() {
82
+ val isLocked = mModule.getIsLocked()
83
+
84
+ assertEquals(
85
+ "When user starts the app, interface orientation shouldn't be locked",
86
+ false,
87
+ isLocked
88
+ )
89
+ }
90
+
91
+ @Test
92
+ fun assert_is_locked_matches_true_after_lock_to_gets_executed() {
93
+ mModule.lockTo(1)
94
+ val isLocked = mModule.getIsLocked()
95
+
96
+ assertEquals(
97
+ "When lockTo is executed, getIsLocked should match true",
98
+ true,
99
+ isLocked
100
+ )
101
+ }
102
+
103
+ @Test
104
+ fun assert_interface_orientation_matches_locked_to_portrait() {
105
+ mModule.lockTo(1)
106
+
107
+ assertEquals(
108
+ "When the interface is locked to portrait, getInterfaceOrientation should return portrait",
109
+ Orientation.PORTRAIT,
110
+ mModule.getInterfaceOrientation()
111
+ )
112
+ }
113
+
114
+ @Test
115
+ fun assert_interface_orientation_matches_locked_to_landscape_right() {
116
+ mModule.lockTo(2)
117
+
118
+ assertEquals(
119
+ "When the interface is locked to landscape right, getInterfaceOrientation should return landscape right",
120
+ Orientation.LANDSCAPE_RIGHT,
121
+ mModule.getInterfaceOrientation()
122
+ )
123
+ }
124
+
125
+ @Test
126
+ fun assert_interface_orientation_matches_locked_to_portrait_upside_down() {
127
+ mModule.lockTo(3)
128
+
129
+ assertEquals(
130
+ "When the interface is locked to portrait upside down, getInterfaceOrientation should return portrait upside down",
131
+ Orientation.PORTRAIT_UPSIDE_DOWN,
132
+ mModule.getInterfaceOrientation()
133
+ )
134
+ }
135
+
136
+ @Test
137
+ fun assert_interface_orientation_matches_locked_to_landscape_left() {
138
+ mModule.lockTo(4)
139
+
140
+ assertEquals(
141
+ "When the interface is locked to landscape left, getInterfaceOrientation should return landscape left",
142
+ Orientation.LANDSCAPE_LEFT,
143
+ mModule.getInterfaceOrientation()
144
+ )
145
+ }
146
+
147
+ @Test
148
+ fun assert_is_locked_reset_when_unlock_is_executed() {
149
+ mModule.lockTo(1)
150
+ mModule.unlock()
151
+
152
+ assertEquals(
153
+ "When unlock is executed, getIsLocked should return false",
154
+ false,
155
+ mModule.getIsLocked()
156
+ )
157
+ }
158
+
159
+ @Test
160
+ @Config(
161
+ qualifiers = "port"
162
+ )
163
+ fun assert_interface_reset_to_portrait_on_unlock() {
164
+ mModule.lockTo(2)
165
+ mModule.unlock()
166
+
167
+ assertEquals(
168
+ "When unlock is executed, getInterfaceOrientation should match portrait when device is in portrait",
169
+ Orientation.PORTRAIT,
170
+ mModule.getInterfaceOrientation()
171
+ )
172
+ }
173
+
174
+ @Test
175
+ @Config(
176
+ qualifiers = "land"
177
+ )
178
+ fun assert_interface_reset_to_landscape_left_on_unlock() {
179
+ mModule.lockTo(2)
180
+ mModule.unlock()
181
+
182
+ assertEquals(
183
+ "When unlock is executed, getInterfaceOrientation should match landscape left when device is in landscape right",
184
+ Orientation.LANDSCAPE_LEFT,
185
+ mModule.getInterfaceOrientation()
186
+ )
187
+ }
188
+ }
@@ -0,0 +1,314 @@
1
+ package com.orientationdirector.implementation
2
+
3
+ import android.content.pm.ActivityInfo
4
+ import android.os.Build
5
+ import android.view.Surface
6
+ import androidx.test.core.app.ApplicationProvider
7
+ import com.facebook.react.bridge.BridgeReactContext
8
+ import org.junit.Assert.*
9
+ import org.junit.Test
10
+ import org.junit.runner.RunWith
11
+ import org.robolectric.RobolectricTestRunner
12
+ import org.robolectric.annotation.Config
13
+
14
+ @RunWith(RobolectricTestRunner::class)
15
+ class UtilsTest {
16
+ private var context = BridgeReactContext(ApplicationProvider.getApplicationContext())
17
+ private var mUtils = Utils(context)
18
+
19
+ @Config(
20
+ sdk = [Build.VERSION_CODES.N],
21
+ qualifiers = "land"
22
+ )
23
+ @Test
24
+ fun assert_interface_rotation_matches_current_landscape() {
25
+ val rotation = mUtils.getInterfaceRotation()
26
+
27
+ assertEquals(
28
+ "When current interface orientation is landscape, rotation should be 1",
29
+ Surface.ROTATION_90,
30
+ rotation
31
+ )
32
+ }
33
+
34
+ @Config(
35
+ sdk = [Build.VERSION_CODES.R],
36
+ qualifiers = "port"
37
+ )
38
+ @Test
39
+ fun assert_interface_rotation_matches_current_portrait() {
40
+ val rotation = mUtils.getInterfaceRotation()
41
+
42
+ assertEquals(
43
+ "When current interface orientation is portrait, rotation should be 0",
44
+ Surface.ROTATION_0,
45
+ rotation
46
+ )
47
+ }
48
+
49
+ @Test
50
+ fun assert_device_orientation_is_portrait() {
51
+ val orientationAngles = FloatArray(3)
52
+ orientationAngles[1] = -(Math.PI / 2).toFloat()
53
+ orientationAngles[2] = -0f
54
+
55
+ val orientation = mUtils.convertToDeviceOrientationFrom(orientationAngles)
56
+
57
+ assertEquals(
58
+ "When pitch is half PI radians and roll is -0 radians, orientation should be portrait",
59
+ Orientation.PORTRAIT,
60
+ orientation
61
+ )
62
+ }
63
+
64
+ @Test
65
+ fun assert_device_orientation_is_landscape_right() {
66
+ val orientationAngles = FloatArray(3)
67
+ orientationAngles[1] = 0f
68
+ orientationAngles[2] = (Math.PI / 2).toFloat()
69
+
70
+ val orientation = mUtils.convertToDeviceOrientationFrom(orientationAngles)
71
+
72
+ assertEquals(
73
+ "When pitch is 0 radians and roll is half PI radians, orientation should be landscape right",
74
+ Orientation.LANDSCAPE_RIGHT,
75
+ orientation
76
+ )
77
+ }
78
+
79
+ @Test
80
+ fun assert_device_orientation_is_portrait_upside_down() {
81
+ val orientationAngles = FloatArray(3)
82
+ orientationAngles[1] = (Math.PI / 2).toFloat()
83
+ orientationAngles[2] = 0f
84
+
85
+ val orientation = mUtils.convertToDeviceOrientationFrom(orientationAngles)
86
+
87
+ assertEquals(
88
+ "When pitch is half PI radians and roll is 0 radians, orientation should be portrait upside down",
89
+ Orientation.PORTRAIT_UPSIDE_DOWN, orientation
90
+ )
91
+ }
92
+
93
+ @Test
94
+ fun assert_device_orientation_is_landscape_left() {
95
+ val orientationAngles = FloatArray(3)
96
+ orientationAngles[1] = 0f
97
+ orientationAngles[2] = -(Math.PI / 2).toFloat()
98
+
99
+ val orientation = mUtils.convertToDeviceOrientationFrom(orientationAngles)
100
+
101
+ assertEquals(
102
+ "When pitch is 0 radians and roll is negative half PI radians, orientation should be landscape left",
103
+ Orientation.LANDSCAPE_LEFT,
104
+ orientation
105
+ )
106
+ }
107
+
108
+ @Test
109
+ fun assert_device_orientation_is_face_down() {
110
+ val orientationAngles = FloatArray(3)
111
+ orientationAngles[1] = 0f
112
+ orientationAngles[2] = -(Math.PI).toFloat()
113
+
114
+ val orientation = mUtils.convertToDeviceOrientationFrom(orientationAngles)
115
+
116
+ assertEquals(
117
+ "When pitch is 0 radians and roll is negative PI radians, orientation should be face down",
118
+ Orientation.FACE_DOWN,
119
+ orientation
120
+ )
121
+ }
122
+
123
+ @Test
124
+ fun assert_device_orientation_is_face_up() {
125
+ val orientationAngles = FloatArray(3)
126
+ orientationAngles[1] = 0f
127
+ orientationAngles[2] = -0f
128
+
129
+ val orientation = mUtils.convertToDeviceOrientationFrom(orientationAngles)
130
+
131
+ assertEquals(
132
+ "When pitch is 0 radians and roll is negative 0 radians, orientation should be face up",
133
+ Orientation.FACE_UP,
134
+ orientation
135
+ )
136
+ }
137
+
138
+ @Test
139
+ fun assert_activity_orientation_conversion_from_portrait() {
140
+ val activityOrientation = mUtils.convertToActivityOrientationFrom(Orientation.PORTRAIT);
141
+
142
+ assertEquals(
143
+ "When orientation is portrait, activity orientation should be portrait",
144
+ ActivityInfo.SCREEN_ORIENTATION_PORTRAIT,
145
+ activityOrientation
146
+ )
147
+ }
148
+
149
+ @Test
150
+ fun assert_activity_orientation_conversion_from_landscape_right() {
151
+ val activityOrientation = mUtils.convertToActivityOrientationFrom(Orientation.LANDSCAPE_RIGHT);
152
+
153
+ assertEquals(
154
+ "When orientation is landscape right, activity orientation should be landscape",
155
+ ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE,
156
+ activityOrientation
157
+ )
158
+ }
159
+
160
+ @Test
161
+ fun assert_activity_orientation_conversion_from_portrait_upside_down() {
162
+ val activityOrientation =
163
+ mUtils.convertToActivityOrientationFrom(Orientation.PORTRAIT_UPSIDE_DOWN);
164
+
165
+ assertEquals(
166
+ "When orientation is portrait upside down, activity orientation should be reverse portrait",
167
+ ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT,
168
+ activityOrientation
169
+ )
170
+ }
171
+
172
+ @Test
173
+ fun assert_activity_orientation_conversion_from_landscape_left() {
174
+ val activityOrientation = mUtils.convertToActivityOrientationFrom(Orientation.LANDSCAPE_LEFT);
175
+
176
+ assertEquals(
177
+ "When orientation is landscape left, activity orientation should be reverse landscape",
178
+ ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE,
179
+ activityOrientation
180
+ )
181
+ }
182
+
183
+ @Test
184
+ fun assert_orientation_conversion_from_js_portrait() {
185
+ val orientation = mUtils.convertToOrientationFromJsValue(1)
186
+
187
+ assertEquals(
188
+ "When js value is 1, orientation should be portrait",
189
+ Orientation.PORTRAIT,
190
+ orientation
191
+ )
192
+ }
193
+
194
+ @Test
195
+ fun assert_orientation_conversion_from_js_landscape_right() {
196
+ val orientation = mUtils.convertToOrientationFromJsValue(2)
197
+
198
+ assertEquals(
199
+ "When js value is 2, orientation should be landscape right",
200
+ Orientation.LANDSCAPE_RIGHT,
201
+ orientation
202
+ )
203
+ }
204
+
205
+ @Test
206
+ fun assert_orientation_conversion_from_js_portrait_upside_down() {
207
+ val orientation = mUtils.convertToOrientationFromJsValue(3)
208
+
209
+ assertEquals(
210
+ "When js value is 3, orientation should be portrait upside down",
211
+ Orientation.PORTRAIT_UPSIDE_DOWN,
212
+ orientation
213
+ )
214
+ }
215
+
216
+ @Test
217
+ fun assert_orientation_conversion_from_js_landscape_left() {
218
+ val orientation = mUtils.convertToOrientationFromJsValue(4)
219
+
220
+ assertEquals(
221
+ "When js value is 4, orientation should be landscape left",
222
+ Orientation.LANDSCAPE_LEFT,
223
+ orientation
224
+ )
225
+ }
226
+
227
+ @Test
228
+ fun assert_orientation_conversion_from_screen_rotation_0() {
229
+ val orientation = mUtils.convertToOrientationFromScreenRotation(Surface.ROTATION_0)
230
+
231
+ assertEquals(
232
+ "When screen rotation is 0, orientation should be portrait",
233
+ Orientation.PORTRAIT,
234
+ orientation
235
+ )
236
+ }
237
+
238
+ @Test
239
+ fun assert_orientation_conversion_from_screen_rotation_90() {
240
+ val orientation = mUtils.convertToOrientationFromScreenRotation(Surface.ROTATION_90)
241
+
242
+ assertEquals(
243
+ "When screen rotation is 90, orientation should be landscape left",
244
+ Orientation.LANDSCAPE_LEFT,
245
+ orientation
246
+ )
247
+ }
248
+
249
+ @Test
250
+ fun assert_orientation_conversion_from_screen_rotation_180() {
251
+ val orientation = mUtils.convertToOrientationFromScreenRotation(Surface.ROTATION_180)
252
+
253
+ assertEquals(
254
+ "When screen rotation is 180, orientation should be portrait upside down",
255
+ Orientation.PORTRAIT_UPSIDE_DOWN,
256
+ orientation
257
+ )
258
+ }
259
+
260
+ @Test
261
+ fun assert_orientation_conversion_from_screen_rotation_270() {
262
+ val orientation = mUtils.convertToOrientationFromScreenRotation(Surface.ROTATION_270)
263
+
264
+ assertEquals(
265
+ "When screen rotation is 270, orientation should be landscape right",
266
+ Orientation.LANDSCAPE_RIGHT,
267
+ orientation
268
+ )
269
+ }
270
+
271
+ @Test
272
+ fun assert_interface_orientation_conversion_from_device_portrait() {
273
+ val orientation = mUtils.convertToInterfaceOrientationFrom(Orientation.PORTRAIT)
274
+
275
+ assertEquals(
276
+ "When device orientation is portrait, interface orientation should be portrait",
277
+ Orientation.PORTRAIT,
278
+ orientation
279
+ )
280
+ }
281
+
282
+ @Test
283
+ fun assert_interface_orientation_conversion_from_device_landscape_right() {
284
+ val orientation = mUtils.convertToInterfaceOrientationFrom(Orientation.LANDSCAPE_RIGHT)
285
+
286
+ assertEquals(
287
+ "When device orientation is landscape right, interface orientation should be landscape left",
288
+ Orientation.LANDSCAPE_LEFT,
289
+ orientation
290
+ )
291
+ }
292
+
293
+ @Test
294
+ fun assert_interface_orientation_conversion_from_device_portrait_upside_down() {
295
+ val orientation = mUtils.convertToInterfaceOrientationFrom(Orientation.PORTRAIT_UPSIDE_DOWN)
296
+
297
+ assertEquals(
298
+ "When device orientation is portrait upside down, interface orientation should be portrait upside down",
299
+ Orientation.PORTRAIT_UPSIDE_DOWN,
300
+ orientation
301
+ )
302
+ }
303
+
304
+ @Test
305
+ fun assert_interface_orientation_conversion_from_device_landscape_left() {
306
+ val orientation = mUtils.convertToInterfaceOrientationFrom(Orientation.LANDSCAPE_LEFT)
307
+
308
+ assertEquals(
309
+ "When device orientation is landscape left, interface orientation should be landscape right",
310
+ Orientation.LANDSCAPE_RIGHT,
311
+ orientation
312
+ )
313
+ }
314
+ }
@@ -41,6 +41,11 @@ RCT_EXPORT_MODULE()
41
41
  return YES;
42
42
  }
43
43
 
44
+ + (UIInterfaceOrientationMask)getSupportedInterfaceOrientationsForWindow
45
+ {
46
+ return [_director supportedInterfaceOrientations];
47
+ }
48
+
44
49
  ///////////////////////////////////////////////////////////////////////////////////////
45
50
  /// EVENT EMITTER SETUP
46
51
  ///
@@ -62,49 +67,31 @@ RCT_EXPORT_MODULE()
62
67
  ///
63
68
  ///////////////////////////////////////////////////////////////////////////////////////
64
69
 
65
- + (UIInterfaceOrientationMask)getSupportedInterfaceOrientationsForWindow
66
- {
67
- return [_director supportedInterfaceOrientations];
68
- }
69
-
70
- #ifdef RCT_NEW_ARCH_ENABLED
71
- - (void)getInterfaceOrientation:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject
72
- #else
70
+ ///////////////////////////////////////////////////////////////////////////////////////
71
+ /// EXPORTED METHODS
72
+ ///
73
73
  RCT_EXPORT_METHOD(getInterfaceOrientation:(RCTPromiseResolveBlock)resolve
74
- rejecter:(RCTPromiseRejectBlock)reject)
75
- #endif
74
+ reject:(RCTPromiseRejectBlock)reject)
76
75
  {
77
76
  dispatch_async(dispatch_get_main_queue(), ^{
78
77
  resolve(@([_director getInterfaceOrientation]));
79
78
  });
80
79
  }
81
80
 
82
- #ifdef RCT_NEW_ARCH_ENABLED
83
- - (void)getDeviceOrientation:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject
84
- #else
85
81
  RCT_EXPORT_METHOD(getDeviceOrientation:(RCTPromiseResolveBlock)resolve
86
- rejecter:(RCTPromiseRejectBlock)reject)
87
- #endif
82
+ reject:(RCTPromiseRejectBlock)reject)
88
83
  {
89
84
  dispatch_async(dispatch_get_main_queue(), ^{
90
85
  resolve(@([_director getDeviceOrientation]));
91
86
  });
92
87
  }
93
88
 
94
- #ifdef RCT_NEW_ARCH_ENABLED
95
- - (NSNumber *)isLocked
96
- #else
97
89
  RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(isLocked)
98
- #endif
99
90
  {
100
91
  return @([_director getIsLocked]);
101
92
  }
102
93
 
103
- #ifdef RCT_NEW_ARCH_ENABLED
104
- - (void)lockTo:(double)jsOrientation
105
- #else
106
94
  RCT_EXPORT_METHOD(lockTo:(double)jsOrientation)
107
- #endif
108
95
  {
109
96
  NSNumber *jsOrientationNumber = @(jsOrientation);
110
97
  dispatch_async(dispatch_get_main_queue(), ^{
@@ -112,22 +99,14 @@ RCT_EXPORT_METHOD(lockTo:(double)jsOrientation)
112
99
  });
113
100
  }
114
101
 
115
- #ifdef RCT_NEW_ARCH_ENABLED
116
- - (void)unlock
117
- #else
118
102
  RCT_EXPORT_METHOD(unlock)
119
- #endif
120
103
  {
121
104
  dispatch_async(dispatch_get_main_queue(), ^{
122
105
  [_director unlock];
123
106
  });
124
107
  }
125
108
 
126
- #ifdef RCT_NEW_ARCH_ENABLED
127
- - (void)resetSupportedInterfaceOrientations
128
- #else
129
109
  RCT_EXPORT_METHOD(resetSupportedInterfaceOrientations)
130
- #endif
131
110
  {
132
111
  dispatch_async(dispatch_get_main_queue(), ^{
133
112
  [_director resetSupportedInterfaceOrientations];
@@ -137,16 +116,12 @@ RCT_EXPORT_METHOD(resetSupportedInterfaceOrientations)
137
116
  /**
138
117
  This method is a pure stub since we cannot access auto rotation setting in iOS
139
118
  */
140
- #ifdef RCT_NEW_ARCH_ENABLED
141
- - (NSNumber *)isAutoRotationEnabled
142
- #else
143
119
  RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(isAutoRotationEnabled)
144
- #endif
145
120
  {
146
121
  return @(NO);
147
122
  }
148
-
149
-
123
+ ///
124
+ ///////////////////////////////////////////////////////////////////////////////////////
150
125
 
151
126
  // Don't compile this code when we build for the old architecture.
152
127
  #ifdef RCT_NEW_ARCH_ENABLED
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var _reactNative = require("react-native");
8
+ var _module = _interopRequireWildcard(require("./module"));
9
+ var _Event = _interopRequireDefault(require("./types/Event.enum"));
10
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
11
+ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
12
+ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
13
+ class EventEmitter {
14
+ static addDeviceOrientationDidChangeListener(callback) {
15
+ let listener = _module.ModuleEventEmitter.addListener(_Event.default.DeviceOrientationDidChange, callback);
16
+ if (_reactNative.Platform.OS !== 'android') {
17
+ return listener;
18
+ }
19
+ const listenerCount = _module.ModuleEventEmitter.listenerCount(_Event.default.DeviceOrientationDidChange);
20
+ if (listenerCount === 1) {
21
+ _module.default.enableOrientationSensors();
22
+ }
23
+ return EventEmitter.createDeviceOrientationListenerProxy(listener);
24
+ }
25
+ static addInterfaceOrientationDidChangeListener(callback) {
26
+ return _module.ModuleEventEmitter.addListener(_Event.default.InterfaceOrientationDidChange, callback);
27
+ }
28
+ static addLockDidChangeListener(callback) {
29
+ return _module.ModuleEventEmitter.addListener(_Event.default.LockDidChange, callback);
30
+ }
31
+ static createDeviceOrientationListenerProxy(listener) {
32
+ const handler = {
33
+ get(target, propertyKey, receiver) {
34
+ if (propertyKey === 'remove') {
35
+ disableOrientationSensorsIfLastListener();
36
+ }
37
+ return Reflect.get(target, propertyKey, receiver);
38
+ }
39
+ };
40
+ return new Proxy(listener, handler);
41
+ function disableOrientationSensorsIfLastListener() {
42
+ const listenerCount = _module.ModuleEventEmitter.listenerCount(_Event.default.DeviceOrientationDidChange);
43
+ if (listenerCount === 1) {
44
+ _module.default.disableOrientationSensors();
45
+ }
46
+ }
47
+ }
48
+ }
49
+ var _default = exports.default = EventEmitter;
50
+ //# sourceMappingURL=EventEmitter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_reactNative","require","_module","_interopRequireWildcard","_Event","_interopRequireDefault","e","__esModule","default","_getRequireWildcardCache","WeakMap","r","t","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","hasOwnProperty","call","i","set","EventEmitter","addDeviceOrientationDidChangeListener","callback","listener","ModuleEventEmitter","addListener","Event","DeviceOrientationDidChange","Platform","OS","listenerCount","Module","enableOrientationSensors","createDeviceOrientationListenerProxy","addInterfaceOrientationDidChangeListener","InterfaceOrientationDidChange","addLockDidChangeListener","LockDidChange","handler","target","propertyKey","receiver","disableOrientationSensorsIfLastListener","Reflect","Proxy","disableOrientationSensors","_default","exports"],"sourceRoot":"../../src","sources":["EventEmitter.ts"],"mappings":";;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AACA,IAAAC,OAAA,GAAAC,uBAAA,CAAAF,OAAA;AACA,IAAAG,MAAA,GAAAC,sBAAA,CAAAJ,OAAA;AAAuC,SAAAI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AAC,QAAA,GAAAC,OAAA,CAAA7C,OAAA,GAEckB,YAAY","ignoreList":[]}
@@ -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,GAepCC,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,GA0BpCC,gCAAmB,CAACC,YAAY,CAAO,qBAAqB,CAAC","ignoreList":[]}