react-native-orientation-director 2.6.4 → 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.
- package/README.md +11 -33
- package/android/build.gradle +19 -79
- package/android/src/main/AndroidManifest.xml +1 -2
- package/android/src/{newarch → main/java/com/orientationdirector}/OrientationDirectorModule.kt +20 -11
- package/android/src/main/java/com/orientationdirector/OrientationDirectorPackage.kt +15 -20
- package/android/src/main/java/com/orientationdirector/implementation/EventManager.kt +4 -17
- package/android/src/main/java/com/orientationdirector/implementation/EventManagerDelegate.kt +9 -0
- package/android/src/main/java/com/orientationdirector/implementation/OrientationDirectorModuleImpl.kt +23 -24
- package/android/src/main/java/com/orientationdirector/implementation/OrientationSensorsEventListener.kt +73 -80
- package/android/src/main/java/com/orientationdirector/implementation/Utils.kt +0 -54
- package/app.plugin.js +1 -1
- package/ios/OrientationDirector.h +1 -18
- package/ios/OrientationDirector.mm +35 -35
- package/ios/SharedOrientationDirectorImpl.swift +12 -0
- package/ios/implementation/EventManager.swift +12 -37
- package/ios/implementation/OrientationDirectorImpl.swift +6 -6
- package/lib/module/EventEmitter.js +15 -9
- package/lib/module/EventEmitter.js.map +1 -1
- package/lib/module/NativeOrientationDirector.js.map +1 -1
- package/lib/module/module.js +1 -2
- package/lib/module/module.js.map +1 -1
- package/lib/plugin/index.d.ts +3 -0
- package/lib/plugin/index.js +10 -0
- package/lib/plugin/withAndroidConfiguration.d.ts +3 -0
- package/{plugin/build/withRNOrientationMainActivity.js → lib/plugin/withAndroidConfiguration.js} +3 -3
- package/lib/plugin/withIosConfiguration.d.ts +3 -0
- package/lib/plugin/withIosConfiguration.js +62 -0
- package/lib/typescript/{commonjs/src → src}/EventEmitter.d.ts +5 -4
- package/lib/typescript/src/EventEmitter.d.ts.map +1 -0
- package/lib/typescript/{commonjs/src → src}/NativeOrientationDirector.d.ts +10 -3
- package/lib/typescript/src/NativeOrientationDirector.d.ts.map +1 -0
- package/lib/typescript/{module/src → src}/RNOrientationDirector.d.ts +3 -3
- package/lib/typescript/src/RNOrientationDirector.d.ts.map +1 -0
- package/lib/typescript/src/hooks/useDeviceOrientation.hook.d.ts.map +1 -0
- package/lib/typescript/src/hooks/useInterfaceOrientation.hook.d.ts.map +1 -0
- package/lib/typescript/src/hooks/useIsInterfaceOrientationLocked.hook.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts.map +1 -0
- package/lib/typescript/src/module.d.ts +4 -0
- package/lib/typescript/src/module.d.ts.map +1 -0
- package/lib/typescript/src/types/AutoRotation.enum.d.ts.map +1 -0
- package/lib/typescript/src/types/Event.enum.d.ts.map +1 -0
- package/lib/typescript/src/types/HumanReadableAutoRotationsResource.type.d.ts.map +1 -0
- package/lib/typescript/src/types/HumanReadableOrientationsResource.type.d.ts.map +1 -0
- package/lib/typescript/src/types/LockableOrientation.type.d.ts.map +1 -0
- package/lib/typescript/src/types/LockedEvent.interface.d.ts.map +1 -0
- package/lib/typescript/src/types/Orientation.enum.d.ts.map +1 -0
- package/lib/typescript/src/types/OrientationEvent.interface.d.ts.map +1 -0
- package/lib/typescript/src/types/OrientationType.enum.d.ts.map +1 -0
- package/package.json +72 -77
- package/react-native-orientation-director.podspec +4 -24
- package/src/EventEmitter.ts +21 -24
- package/src/NativeOrientationDirector.ts +8 -3
- package/src/module.ts +1 -3
- package/android/gradle.properties +0 -17
- package/android/src/main/AndroidManifestNew.xml +0 -2
- package/android/src/oldarch/OrientationDirectorModule.kt +0 -66
- package/android/src/test/java/com/orientationdirector/implementation/OrientationDirectorModuleImplTest.kt +0 -199
- package/android/src/test/java/com/orientationdirector/implementation/UtilsTest.kt +0 -314
- package/ios/react-native-orientation-director-Bridging-Header.h +0 -6
- package/lib/commonjs/EventEmitter.js +0 -48
- package/lib/commonjs/NativeOrientationDirector.js +0 -8
- package/lib/commonjs/RNOrientationDirector.js +0 -126
- package/lib/commonjs/hooks/useDeviceOrientation.hook.js +0 -37
- package/lib/commonjs/hooks/useInterfaceOrientation.hook.js +0 -37
- package/lib/commonjs/hooks/useIsInterfaceOrientationLocked.hook.js +0 -27
- package/lib/commonjs/index.js +0 -51
- package/lib/commonjs/module.js +0 -22
- package/lib/commonjs/package.json +0 -1
- package/lib/commonjs/types/AutoRotation.enum.js +0 -12
- package/lib/commonjs/types/Event.enum.js +0 -13
- package/lib/commonjs/types/HumanReadableAutoRotationsResource.type.js +0 -5
- package/lib/commonjs/types/HumanReadableOrientationsResource.type.js +0 -5
- package/lib/commonjs/types/LockableOrientation.type.js +0 -5
- package/lib/commonjs/types/LockedEvent.interface.js +0 -1
- package/lib/commonjs/types/Orientation.enum.js +0 -17
- package/lib/commonjs/types/OrientationEvent.interface.js +0 -5
- package/lib/commonjs/types/OrientationType.enum.js +0 -11
- package/lib/typescript/commonjs/example/src/App.d.ts +0 -2
- package/lib/typescript/commonjs/example/src/App.d.ts.map +0 -1
- package/lib/typescript/commonjs/example/src/AppNavigationContainer.d.ts +0 -3
- package/lib/typescript/commonjs/example/src/AppNavigationContainer.d.ts.map +0 -1
- package/lib/typescript/commonjs/example/src/screens/Explore.d.ts +0 -3
- package/lib/typescript/commonjs/example/src/screens/Explore.d.ts.map +0 -1
- package/lib/typescript/commonjs/example/src/screens/Home.d.ts +0 -3
- package/lib/typescript/commonjs/example/src/screens/Home.d.ts.map +0 -1
- package/lib/typescript/commonjs/example/src/screens/InnerExplore.d.ts +0 -3
- package/lib/typescript/commonjs/example/src/screens/InnerExplore.d.ts.map +0 -1
- package/lib/typescript/commonjs/example/src/screens/styles.d.ts +0 -51
- package/lib/typescript/commonjs/example/src/screens/styles.d.ts.map +0 -1
- package/lib/typescript/commonjs/package.json +0 -1
- package/lib/typescript/commonjs/src/EventEmitter.d.ts.map +0 -1
- package/lib/typescript/commonjs/src/NativeOrientationDirector.d.ts.map +0 -1
- package/lib/typescript/commonjs/src/RNOrientationDirector.d.ts +0 -62
- package/lib/typescript/commonjs/src/RNOrientationDirector.d.ts.map +0 -1
- package/lib/typescript/commonjs/src/hooks/useDeviceOrientation.hook.d.ts.map +0 -1
- package/lib/typescript/commonjs/src/hooks/useInterfaceOrientation.hook.d.ts.map +0 -1
- package/lib/typescript/commonjs/src/hooks/useIsInterfaceOrientationLocked.hook.d.ts.map +0 -1
- package/lib/typescript/commonjs/src/index.d.ts.map +0 -1
- package/lib/typescript/commonjs/src/module.d.ts +0 -6
- package/lib/typescript/commonjs/src/module.d.ts.map +0 -1
- package/lib/typescript/commonjs/src/types/AutoRotation.enum.d.ts.map +0 -1
- package/lib/typescript/commonjs/src/types/Event.enum.d.ts.map +0 -1
- package/lib/typescript/commonjs/src/types/HumanReadableAutoRotationsResource.type.d.ts.map +0 -1
- package/lib/typescript/commonjs/src/types/HumanReadableOrientationsResource.type.d.ts.map +0 -1
- package/lib/typescript/commonjs/src/types/LockableOrientation.type.d.ts.map +0 -1
- package/lib/typescript/commonjs/src/types/LockedEvent.interface.d.ts.map +0 -1
- package/lib/typescript/commonjs/src/types/Orientation.enum.d.ts.map +0 -1
- package/lib/typescript/commonjs/src/types/OrientationEvent.interface.d.ts.map +0 -1
- package/lib/typescript/commonjs/src/types/OrientationType.enum.d.ts.map +0 -1
- package/lib/typescript/module/example/src/App.d.ts +0 -2
- package/lib/typescript/module/example/src/App.d.ts.map +0 -1
- package/lib/typescript/module/example/src/AppNavigationContainer.d.ts +0 -3
- package/lib/typescript/module/example/src/AppNavigationContainer.d.ts.map +0 -1
- package/lib/typescript/module/example/src/screens/Explore.d.ts +0 -3
- package/lib/typescript/module/example/src/screens/Explore.d.ts.map +0 -1
- package/lib/typescript/module/example/src/screens/Home.d.ts +0 -3
- package/lib/typescript/module/example/src/screens/Home.d.ts.map +0 -1
- package/lib/typescript/module/example/src/screens/InnerExplore.d.ts +0 -3
- package/lib/typescript/module/example/src/screens/InnerExplore.d.ts.map +0 -1
- package/lib/typescript/module/example/src/screens/styles.d.ts +0 -51
- package/lib/typescript/module/example/src/screens/styles.d.ts.map +0 -1
- package/lib/typescript/module/src/EventEmitter.d.ts +0 -11
- package/lib/typescript/module/src/EventEmitter.d.ts.map +0 -1
- package/lib/typescript/module/src/NativeOrientationDirector.d.ts +0 -17
- package/lib/typescript/module/src/NativeOrientationDirector.d.ts.map +0 -1
- package/lib/typescript/module/src/RNOrientationDirector.d.ts.map +0 -1
- package/lib/typescript/module/src/hooks/useDeviceOrientation.hook.d.ts +0 -8
- package/lib/typescript/module/src/hooks/useDeviceOrientation.hook.d.ts.map +0 -1
- package/lib/typescript/module/src/hooks/useInterfaceOrientation.hook.d.ts +0 -8
- package/lib/typescript/module/src/hooks/useInterfaceOrientation.hook.d.ts.map +0 -1
- package/lib/typescript/module/src/hooks/useIsInterfaceOrientationLocked.hook.d.ts +0 -7
- package/lib/typescript/module/src/hooks/useIsInterfaceOrientationLocked.hook.d.ts.map +0 -1
- package/lib/typescript/module/src/index.d.ts +0 -12
- package/lib/typescript/module/src/index.d.ts.map +0 -1
- package/lib/typescript/module/src/module.d.ts +0 -6
- package/lib/typescript/module/src/module.d.ts.map +0 -1
- package/lib/typescript/module/src/types/AutoRotation.enum.d.ts +0 -6
- package/lib/typescript/module/src/types/AutoRotation.enum.d.ts.map +0 -1
- package/lib/typescript/module/src/types/Event.enum.d.ts +0 -7
- package/lib/typescript/module/src/types/Event.enum.d.ts.map +0 -1
- package/lib/typescript/module/src/types/HumanReadableAutoRotationsResource.type.d.ts +0 -3
- package/lib/typescript/module/src/types/HumanReadableAutoRotationsResource.type.d.ts.map +0 -1
- package/lib/typescript/module/src/types/HumanReadableOrientationsResource.type.d.ts +0 -3
- package/lib/typescript/module/src/types/HumanReadableOrientationsResource.type.d.ts.map +0 -1
- package/lib/typescript/module/src/types/LockableOrientation.type.d.ts +0 -3
- package/lib/typescript/module/src/types/LockableOrientation.type.d.ts.map +0 -1
- package/lib/typescript/module/src/types/LockedEvent.interface.d.ts +0 -4
- package/lib/typescript/module/src/types/LockedEvent.interface.d.ts.map +0 -1
- package/lib/typescript/module/src/types/Orientation.enum.d.ts +0 -11
- package/lib/typescript/module/src/types/Orientation.enum.d.ts.map +0 -1
- package/lib/typescript/module/src/types/OrientationEvent.interface.d.ts +0 -5
- package/lib/typescript/module/src/types/OrientationEvent.interface.d.ts.map +0 -1
- package/lib/typescript/module/src/types/OrientationType.enum.d.ts +0 -5
- package/lib/typescript/module/src/types/OrientationType.enum.d.ts.map +0 -1
- package/plugin/build/custom-mod/withBridgingHeader.d.ts +0 -12
- package/plugin/build/custom-mod/withBridgingHeader.js +0 -107
- package/plugin/build/index.d.ts +0 -3
- package/plugin/build/index.js +0 -27
- package/plugin/build/withRNOrientationAppDelegate.d.ts +0 -4
- package/plugin/build/withRNOrientationAppDelegate.js +0 -102
- package/plugin/build/withRNOrientationBridgingHeader.d.ts +0 -3
- package/plugin/build/withRNOrientationBridgingHeader.js +0 -27
- package/plugin/build/withRNOrientationMainActivity.d.ts +0 -3
- package/plugin/tsconfig.json +0 -9
- /package/lib/typescript/{module/package.json → package.json} +0 -0
- /package/lib/typescript/{commonjs/src → src}/hooks/useDeviceOrientation.hook.d.ts +0 -0
- /package/lib/typescript/{commonjs/src → src}/hooks/useInterfaceOrientation.hook.d.ts +0 -0
- /package/lib/typescript/{commonjs/src → src}/hooks/useIsInterfaceOrientationLocked.hook.d.ts +0 -0
- /package/lib/typescript/{commonjs/src → src}/index.d.ts +0 -0
- /package/lib/typescript/{commonjs/src → src}/types/AutoRotation.enum.d.ts +0 -0
- /package/lib/typescript/{commonjs/src → src}/types/Event.enum.d.ts +0 -0
- /package/lib/typescript/{commonjs/src → src}/types/HumanReadableAutoRotationsResource.type.d.ts +0 -0
- /package/lib/typescript/{commonjs/src → src}/types/HumanReadableOrientationsResource.type.d.ts +0 -0
- /package/lib/typescript/{commonjs/src → src}/types/LockableOrientation.type.d.ts +0 -0
- /package/lib/typescript/{commonjs/src → src}/types/LockedEvent.interface.d.ts +0 -0
- /package/lib/typescript/{commonjs/src → src}/types/Orientation.enum.d.ts +0 -0
- /package/lib/typescript/{commonjs/src → src}/types/OrientationEvent.interface.d.ts +0 -0
- /package/lib/typescript/{commonjs/src → src}/types/OrientationType.enum.d.ts +0 -0
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
OrientationDirector_kotlinVersion=2.0.21
|
|
2
|
-
OrientationDirector_minSdkVersion=24
|
|
3
|
-
OrientationDirector_targetSdkVersion=34
|
|
4
|
-
OrientationDirector_compileSdkVersion=35
|
|
5
|
-
OrientationDirector_ndkVersion=27.1.12297006
|
|
6
|
-
|
|
7
|
-
#########################
|
|
8
|
-
# TESTING
|
|
9
|
-
#
|
|
10
|
-
|
|
11
|
-
OrientationDirector_junitVersion=4.13.2
|
|
12
|
-
OrientationDirector_androidXCoreVersion=1.5.+
|
|
13
|
-
OrientationDirector_robolectricVersion=4.13
|
|
14
|
-
OrientationDirector_mockitoCoreVersion=5.14.2
|
|
15
|
-
|
|
16
|
-
#
|
|
17
|
-
#########################
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
package com.orientationdirector
|
|
2
|
-
|
|
3
|
-
import com.facebook.react.bridge.ReactApplicationContext
|
|
4
|
-
import com.facebook.react.bridge.ReactContextBaseJavaModule
|
|
5
|
-
import com.facebook.react.bridge.Promise
|
|
6
|
-
import com.facebook.react.bridge.ReactMethod
|
|
7
|
-
import com.orientationdirector.implementation.OrientationDirectorModuleImpl
|
|
8
|
-
|
|
9
|
-
class OrientationDirectorModule internal constructor(context: ReactApplicationContext) :
|
|
10
|
-
ReactContextBaseJavaModule(context) {
|
|
11
|
-
|
|
12
|
-
private var implementation = OrientationDirectorModuleImpl(context)
|
|
13
|
-
|
|
14
|
-
override fun getName() = OrientationDirectorModuleImpl.NAME
|
|
15
|
-
|
|
16
|
-
@ReactMethod()
|
|
17
|
-
fun getInterfaceOrientation(promise: Promise) {
|
|
18
|
-
promise.resolve(implementation.getInterfaceOrientation().ordinal)
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
@ReactMethod()
|
|
22
|
-
fun getDeviceOrientation(promise: Promise) {
|
|
23
|
-
promise.resolve(implementation.getDeviceOrientation().ordinal)
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
@ReactMethod()
|
|
27
|
-
fun lockTo(orientation: Double) {
|
|
28
|
-
implementation.lockTo(orientation.toInt())
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
@ReactMethod()
|
|
32
|
-
fun unlock() {
|
|
33
|
-
implementation.unlock()
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
@ReactMethod()
|
|
37
|
-
fun resetSupportedInterfaceOrientations() {
|
|
38
|
-
implementation.resetSupportedInterfaceOrientations()
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
@ReactMethod(isBlockingSynchronousMethod = true)
|
|
42
|
-
fun isLocked(): Boolean {
|
|
43
|
-
return implementation.getIsLocked()
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
@ReactMethod(isBlockingSynchronousMethod = true)
|
|
47
|
-
fun isAutoRotationEnabled(): Boolean {
|
|
48
|
-
return implementation.getIsAutoRotationEnabled()
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
@ReactMethod()
|
|
52
|
-
fun enableOrientationSensors() {
|
|
53
|
-
return implementation.enableOrientationSensors()
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
@ReactMethod()
|
|
57
|
-
fun disableOrientationSensors() {
|
|
58
|
-
return implementation.disableOrientationSensors()
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
@ReactMethod()
|
|
62
|
-
fun addListener(eventName: String) {}
|
|
63
|
-
|
|
64
|
-
@ReactMethod()
|
|
65
|
-
fun removeListeners(count: Double) {}
|
|
66
|
-
}
|
|
@@ -1,199 +0,0 @@
|
|
|
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_interface_orientation_matches_locked_to_landscape() {
|
|
149
|
-
mModule.lockTo(5)
|
|
150
|
-
|
|
151
|
-
assertEquals(
|
|
152
|
-
"When the interface is locked to landscape, getInterfaceOrientation should return landscape right",
|
|
153
|
-
Orientation.LANDSCAPE_RIGHT,
|
|
154
|
-
mModule.getInterfaceOrientation()
|
|
155
|
-
)
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
@Test
|
|
159
|
-
fun assert_is_locked_reset_when_unlock_is_executed() {
|
|
160
|
-
mModule.lockTo(1)
|
|
161
|
-
mModule.unlock()
|
|
162
|
-
|
|
163
|
-
assertEquals(
|
|
164
|
-
"When unlock is executed, getIsLocked should return false",
|
|
165
|
-
false,
|
|
166
|
-
mModule.getIsLocked()
|
|
167
|
-
)
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
@Test
|
|
171
|
-
@Config(
|
|
172
|
-
qualifiers = "port"
|
|
173
|
-
)
|
|
174
|
-
fun assert_interface_reset_to_portrait_on_unlock() {
|
|
175
|
-
mModule.lockTo(2)
|
|
176
|
-
mModule.unlock()
|
|
177
|
-
|
|
178
|
-
assertEquals(
|
|
179
|
-
"When unlock is executed, getInterfaceOrientation should match portrait when device is in portrait",
|
|
180
|
-
Orientation.PORTRAIT,
|
|
181
|
-
mModule.getInterfaceOrientation()
|
|
182
|
-
)
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
@Test
|
|
186
|
-
@Config(
|
|
187
|
-
qualifiers = "land"
|
|
188
|
-
)
|
|
189
|
-
fun assert_interface_reset_to_landscape_left_on_unlock() {
|
|
190
|
-
mModule.lockTo(2)
|
|
191
|
-
mModule.unlock()
|
|
192
|
-
|
|
193
|
-
assertEquals(
|
|
194
|
-
"When unlock is executed, getInterfaceOrientation should match landscape left when device is in landscape right",
|
|
195
|
-
Orientation.LANDSCAPE_LEFT,
|
|
196
|
-
mModule.getInterfaceOrientation()
|
|
197
|
-
)
|
|
198
|
-
}
|
|
199
|
-
}
|
|
@@ -1,314 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
var _reactNative = require("react-native");
|
|
8
|
-
var _module = _interopRequireWildcard(require("./module.js"));
|
|
9
|
-
var _EventEnum = _interopRequireDefault(require("./types/Event.enum.js"));
|
|
10
|
-
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
11
|
-
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
|
|
12
|
-
class EventEmitter {
|
|
13
|
-
static addDeviceOrientationDidChangeListener(callback) {
|
|
14
|
-
let listener = _module.ModuleEventEmitter.addListener(_EventEnum.default.DeviceOrientationDidChange, callback);
|
|
15
|
-
if (_reactNative.Platform.OS !== 'android') {
|
|
16
|
-
return listener;
|
|
17
|
-
}
|
|
18
|
-
const listenerCount = _module.ModuleEventEmitter.listenerCount(_EventEnum.default.DeviceOrientationDidChange);
|
|
19
|
-
if (listenerCount === 1) {
|
|
20
|
-
_module.default.enableOrientationSensors();
|
|
21
|
-
}
|
|
22
|
-
return EventEmitter.createDeviceOrientationListenerProxy(listener);
|
|
23
|
-
}
|
|
24
|
-
static addInterfaceOrientationDidChangeListener(callback) {
|
|
25
|
-
return _module.ModuleEventEmitter.addListener(_EventEnum.default.InterfaceOrientationDidChange, callback);
|
|
26
|
-
}
|
|
27
|
-
static addLockDidChangeListener(callback) {
|
|
28
|
-
return _module.ModuleEventEmitter.addListener(_EventEnum.default.LockDidChange, callback);
|
|
29
|
-
}
|
|
30
|
-
static createDeviceOrientationListenerProxy(listener) {
|
|
31
|
-
const handler = {
|
|
32
|
-
get(target, propertyKey, receiver) {
|
|
33
|
-
if (propertyKey === 'remove') {
|
|
34
|
-
disableOrientationSensorsIfLastListener();
|
|
35
|
-
}
|
|
36
|
-
return Reflect.get(target, propertyKey, receiver);
|
|
37
|
-
}
|
|
38
|
-
};
|
|
39
|
-
return new Proxy(listener, handler);
|
|
40
|
-
function disableOrientationSensorsIfLastListener() {
|
|
41
|
-
const listenerCount = _module.ModuleEventEmitter.listenerCount(_EventEnum.default.DeviceOrientationDidChange);
|
|
42
|
-
if (listenerCount === 1) {
|
|
43
|
-
_module.default.disableOrientationSensors();
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
var _default = exports.default = EventEmitter;
|