react-native-orientation-director 1.3.0 → 2.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.
- package/README.md +51 -18
- package/android/build.gradle +13 -1
- package/android/gradle.properties +12 -0
- package/android/src/main/java/com/orientationdirector/OrientationDirectorPackage.kt +5 -4
- package/android/src/main/java/com/orientationdirector/implementation/EventManager.kt +0 -1
- package/android/src/main/java/com/orientationdirector/implementation/LifecycleListener.kt +1 -1
- package/android/src/main/java/com/orientationdirector/implementation/Orientation.kt +2 -0
- package/android/src/main/java/com/orientationdirector/implementation/{OrientationDirectorImpl.kt → OrientationDirectorModuleImpl.kt} +47 -33
- package/android/src/main/java/com/orientationdirector/implementation/OrientationSensorsEventListener.kt +79 -0
- package/android/src/main/java/com/orientationdirector/implementation/Utils.kt +28 -15
- package/android/src/newarch/OrientationDirectorModule.kt +59 -0
- package/android/src/oldarch/OrientationDirectorModule.kt +66 -0
- package/android/src/test/java/com/orientationdirector/implementation/OrientationDirectorModuleImplTest.kt +188 -0
- package/android/src/test/java/com/orientationdirector/implementation/UtilsTest.kt +314 -0
- package/ios/OrientationDirector.mm +12 -37
- package/ios/implementation/OrientationDirectorImpl.swift +8 -15
- package/ios/implementation/Utils.swift +0 -32
- package/lib/commonjs/EventEmitter.js +50 -0
- package/lib/commonjs/EventEmitter.js.map +1 -0
- package/lib/commonjs/NativeOrientationDirector.js.map +1 -1
- package/lib/commonjs/RNOrientationDirector.js +58 -9
- package/lib/commonjs/RNOrientationDirector.js.map +1 -1
- package/lib/commonjs/hooks/useDeviceOrientation.hook.js +1 -1
- package/lib/commonjs/hooks/useDeviceOrientation.hook.js.map +1 -1
- package/lib/commonjs/hooks/useInterfaceOrientation.hook.js +1 -1
- package/lib/commonjs/hooks/useInterfaceOrientation.hook.js.map +1 -1
- package/lib/commonjs/hooks/useIsInterfaceOrientationLocked.hook.js +1 -1
- package/lib/commonjs/hooks/useIsInterfaceOrientationLocked.hook.js.map +1 -1
- package/lib/commonjs/index.js +8 -1
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/module.js +2 -2
- package/lib/commonjs/module.js.map +1 -1
- package/lib/commonjs/types/OrientationType.enum.js +12 -0
- package/lib/commonjs/types/OrientationType.enum.js.map +1 -0
- package/lib/module/EventEmitter.js +41 -0
- package/lib/module/EventEmitter.js.map +1 -0
- package/lib/module/NativeOrientationDirector.js.map +1 -1
- package/lib/module/RNOrientationDirector.js +57 -6
- package/lib/module/RNOrientationDirector.js.map +1 -1
- package/lib/module/index.js +1 -0
- package/lib/module/index.js.map +1 -1
- package/lib/module/module.js +1 -1
- package/lib/module/module.js.map +1 -1
- package/lib/module/types/OrientationType.enum.js +6 -0
- package/lib/module/types/OrientationType.enum.js.map +1 -0
- package/lib/typescript/src/EventEmitter.d.ts +11 -0
- package/lib/typescript/src/EventEmitter.d.ts.map +1 -0
- package/lib/typescript/src/NativeOrientationDirector.d.ts +3 -1
- package/lib/typescript/src/NativeOrientationDirector.d.ts.map +1 -1
- package/lib/typescript/src/RNOrientationDirector.d.ts +37 -2
- package/lib/typescript/src/RNOrientationDirector.d.ts.map +1 -1
- package/lib/typescript/src/index.d.ts +1 -0
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/module.d.ts +1 -1
- package/lib/typescript/src/module.d.ts.map +1 -1
- package/lib/typescript/src/types/Orientation.enum.d.ts.map +1 -1
- package/lib/typescript/src/types/OrientationType.enum.d.ts +5 -0
- package/lib/typescript/src/types/OrientationType.enum.d.ts.map +1 -0
- package/package.json +1 -1
- package/src/EventEmitter.ts +70 -0
- package/src/NativeOrientationDirector.ts +12 -1
- package/src/RNOrientationDirector.ts +69 -10
- package/src/index.tsx +1 -0
- package/src/module.ts +1 -1
- package/src/types/Orientation.enum.ts +0 -2
- package/src/types/OrientationType.enum.ts +4 -0
- package/android/src/main/java/com/orientationdirector/OrientationDirectorModule.kt +0 -65
- package/android/src/main/java/com/orientationdirector/implementation/SensorListener.kt +0 -26
- package/android/src/newarch/OrientationDirectorSpec.kt +0 -7
- 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
|
-
|
|
66
|
-
|
|
67
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
@@ -104,10 +104,8 @@ import UIKit
|
|
|
104
104
|
return supportedInterfaceOrientations.reduce(UIInterfaceOrientationMask()) { $0.union($1) }
|
|
105
105
|
}
|
|
106
106
|
|
|
107
|
-
// TODO: FIX BECAUSE IT ALWAYS RETURNS PORTRAIT AND ITS BROKEN
|
|
108
107
|
private func initInterfaceOrientation() -> Orientation {
|
|
109
|
-
|
|
110
|
-
return utils.convertToOrientationFrom(uiInterfaceOrientation: interfaceOrientation)
|
|
108
|
+
return self.getOrientationFromInterface()
|
|
111
109
|
}
|
|
112
110
|
|
|
113
111
|
private func initDeviceOrientation() -> Orientation {
|
|
@@ -163,18 +161,8 @@ import UIKit
|
|
|
163
161
|
if (deviceOrientation == Orientation.FACE_UP || deviceOrientation == Orientation.FACE_DOWN) {
|
|
164
162
|
return
|
|
165
163
|
}
|
|
166
|
-
|
|
167
|
-
let
|
|
168
|
-
let isSupported = self.supportedInterfaceOrientations.contains(newInterfaceOrientationMask)
|
|
169
|
-
if (!isSupported) {
|
|
170
|
-
return
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
let newInterfaceOrientation = utils.convertToOrientationFrom(mask: newInterfaceOrientationMask)
|
|
174
|
-
if (newInterfaceOrientation == lastInterfaceOrientation) {
|
|
175
|
-
return
|
|
176
|
-
}
|
|
177
|
-
|
|
164
|
+
|
|
165
|
+
let newInterfaceOrientation = self.getOrientationFromInterface()
|
|
178
166
|
updateLastInterfaceOrientationTo(value: newInterfaceOrientation)
|
|
179
167
|
}
|
|
180
168
|
|
|
@@ -187,4 +175,9 @@ import UIKit
|
|
|
187
175
|
self.eventManager.sendInterfaceOrientationDidChange(orientationValue: value.rawValue)
|
|
188
176
|
lastInterfaceOrientation = value
|
|
189
177
|
}
|
|
178
|
+
|
|
179
|
+
private func getOrientationFromInterface() -> Orientation {
|
|
180
|
+
let interfaceOrientation = utils.getInterfaceOrientation()
|
|
181
|
+
return utils.convertToOrientationFrom(uiInterfaceOrientation: interfaceOrientation)
|
|
182
|
+
}
|
|
190
183
|
}
|
|
@@ -55,19 +55,6 @@ class Utils {
|
|
|
55
55
|
}
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
-
public func convertToOrientationFrom(mask: UIInterfaceOrientationMask) -> Orientation {
|
|
59
|
-
switch(mask) {
|
|
60
|
-
case .portraitUpsideDown:
|
|
61
|
-
return .PORTRAIT_UPSIDE_DOWN
|
|
62
|
-
case .landscapeRight:
|
|
63
|
-
return .LANDSCAPE_RIGHT
|
|
64
|
-
case .landscapeLeft:
|
|
65
|
-
return .LANDSCAPE_LEFT
|
|
66
|
-
default:
|
|
67
|
-
return .PORTRAIT
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
|
|
71
58
|
/**
|
|
72
59
|
Note: .portraitUpsideDown only works for devices with home button and iPads
|
|
73
60
|
https://developer.apple.com/documentation/uikit/uiviewcontroller/1621435-supportedinterfaceorientations
|
|
@@ -87,25 +74,6 @@ class Utils {
|
|
|
87
74
|
}
|
|
88
75
|
}
|
|
89
76
|
|
|
90
|
-
/**
|
|
91
|
-
Note: .portraitUpsideDown only works for devices with home button and iPads
|
|
92
|
-
https://developer.apple.com/documentation/uikit/uiviewcontroller/1621435-supportedinterfaceorientations
|
|
93
|
-
*/
|
|
94
|
-
public func convertToMaskFrom(deviceOrientation: Orientation) -> UIInterfaceOrientationMask {
|
|
95
|
-
switch(deviceOrientation) {
|
|
96
|
-
case .PORTRAIT:
|
|
97
|
-
return .portrait
|
|
98
|
-
case .LANDSCAPE_RIGHT:
|
|
99
|
-
return .landscapeLeft
|
|
100
|
-
case .PORTRAIT_UPSIDE_DOWN:
|
|
101
|
-
return .portraitUpsideDown
|
|
102
|
-
case .LANDSCAPE_LEFT:
|
|
103
|
-
return .landscapeRight
|
|
104
|
-
default:
|
|
105
|
-
return .all
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
|
|
109
77
|
public func getInterfaceOrientation() -> UIInterfaceOrientation {
|
|
110
78
|
guard let windowScene = self.getCurrentWindow()?.windowScene else {
|
|
111
79
|
return UIInterfaceOrientation.unknown
|