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
package/README.md
CHANGED
|
@@ -6,7 +6,10 @@
|
|
|
6
6
|
|
|
7
7
|
A React Native library that allows you to listen to orientation changes, lock interface orientation
|
|
8
8
|
to a selected one and get current orientation.
|
|
9
|
-
Written in Kotlin, Swift and Typescript.
|
|
9
|
+
Written in Kotlin, Swift and Typescript.
|
|
10
|
+
|
|
11
|
+
Kindly note that this library only supports the new architecture since v3.0.0, if you are looking for a version that
|
|
12
|
+
supports the old architecture, please check older versions.
|
|
10
13
|
|
|
11
14
|
This library takes inspiration from and builds upon the following amazing alternatives:
|
|
12
15
|
|
|
@@ -112,40 +115,20 @@ Nothing else is required for Android.
|
|
|
112
115
|
|
|
113
116
|
#### iOS
|
|
114
117
|
|
|
115
|
-
To properly handle interface orientation changes in iOS, you need to update your AppDelegate file.
|
|
116
|
-
|
|
118
|
+
To properly handle interface orientation changes in iOS, you need to update your AppDelegate file. Follow the instructions
|
|
119
|
+
below to set it up:
|
|
117
120
|
|
|
118
|
-
|
|
121
|
+
In your AppDelegate.swift file, implement the supportedInterfaceOrientationsFor method as follows:
|
|
119
122
|
|
|
120
|
-
|
|
123
|
+
```swift
|
|
121
124
|
|
|
122
|
-
|
|
123
|
-
#import <OrientationDirector.h>
|
|
125
|
+
import OrientationDirector
|
|
124
126
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
return [OrientationDirector getSupportedInterfaceOrientationsForWindow];
|
|
127
|
+
func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask {
|
|
128
|
+
return SharedOrientationDirectorImpl.shared.supportedInterfaceOrientations
|
|
128
129
|
}
|
|
129
|
-
```
|
|
130
|
-
|
|
131
|
-
##### Swift
|
|
132
|
-
|
|
133
|
-
You need to create a [bridging header](https://developer.apple.com/documentation/swift/importing-objective-c-into-swift#Import-Code-Within-an-App-Target)
|
|
134
|
-
to import the library, as shown below:
|
|
135
130
|
|
|
136
131
|
```
|
|
137
|
-
#import "OrientationDirector.h"
|
|
138
|
-
```
|
|
139
|
-
|
|
140
|
-
Then, in your AppDelegate.swift file, implement the supportedInterfaceOrientationsFor method as follows:
|
|
141
|
-
|
|
142
|
-
```swift
|
|
143
|
-
override func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask {
|
|
144
|
-
return OrientationDirector.getSupportedInterfaceOrientationsForWindow()
|
|
145
|
-
}
|
|
146
|
-
```
|
|
147
|
-
|
|
148
|
-
Note: if you are targeting react-native > 79.x, you can omit the `override` keyword.
|
|
149
132
|
|
|
150
133
|
If you need help, you can check the example project.
|
|
151
134
|
|
|
@@ -212,11 +195,6 @@ differently than on iOS, mainly in the following ways:
|
|
|
212
195
|
|
|
213
196
|
This behavior allows us to follow Google's best practices related to the Sensors Framework. More [here](https://developer.android.com/develop/sensors-and-location/sensors/sensors_overview#sensors-practices).
|
|
214
197
|
|
|
215
|
-
## Roadmap
|
|
216
|
-
|
|
217
|
-
- [ ] Add JS side tests
|
|
218
|
-
- [ ] Add iOS side tests
|
|
219
|
-
|
|
220
198
|
## Contributing
|
|
221
199
|
|
|
222
200
|
See the [contributing guide](CONTRIBUTING.md) to learn how to contribute to the repository and the development workflow.
|
package/android/build.gradle
CHANGED
|
@@ -1,6 +1,17 @@
|
|
|
1
1
|
buildscript {
|
|
2
|
-
ext.
|
|
3
|
-
|
|
2
|
+
ext.OrientationDirector = [
|
|
3
|
+
kotlinVersion: "2.0.21",
|
|
4
|
+
minSdkVersion: 24,
|
|
5
|
+
compileSdkVersion: 36,
|
|
6
|
+
targetSdkVersion: 36
|
|
7
|
+
]
|
|
8
|
+
|
|
9
|
+
ext.getExtOrDefault = { prop ->
|
|
10
|
+
if (rootProject.ext.has(prop)) {
|
|
11
|
+
return rootProject.ext.get(prop)
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
return OrientationDirector[prop]
|
|
4
15
|
}
|
|
5
16
|
|
|
6
17
|
repositories {
|
|
@@ -16,51 +27,19 @@ buildscript {
|
|
|
16
27
|
}
|
|
17
28
|
|
|
18
29
|
|
|
19
|
-
def isNewArchitectureEnabled() {
|
|
20
|
-
return rootProject.hasProperty("newArchEnabled") && rootProject.getProperty("newArchEnabled") == "true"
|
|
21
|
-
}
|
|
22
|
-
|
|
23
30
|
apply plugin: "com.android.library"
|
|
24
31
|
apply plugin: "kotlin-android"
|
|
25
32
|
|
|
26
|
-
|
|
27
|
-
apply plugin: "com.facebook.react"
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
def getExtOrIntegerDefault(name) {
|
|
31
|
-
return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties["OrientationDirector_" + name]).toInteger()
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
def getDefault(name) {
|
|
35
|
-
return project.properties["OrientationDirector_" + name]
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
def supportsNamespace() {
|
|
39
|
-
def parsed = com.android.Version.ANDROID_GRADLE_PLUGIN_VERSION.tokenize('.')
|
|
40
|
-
def major = parsed[0].toInteger()
|
|
41
|
-
def minor = parsed[1].toInteger()
|
|
42
|
-
|
|
43
|
-
// Namespace support was added in 7.3.0
|
|
44
|
-
return (major == 7 && minor >= 3) || major >= 8
|
|
45
|
-
}
|
|
33
|
+
apply plugin: "com.facebook.react"
|
|
46
34
|
|
|
47
35
|
android {
|
|
48
|
-
|
|
49
|
-
namespace "com.orientationdirector"
|
|
36
|
+
namespace "com.orientationdirector"
|
|
50
37
|
|
|
51
|
-
|
|
52
|
-
main {
|
|
53
|
-
manifest.srcFile "src/main/AndroidManifestNew.xml"
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
compileSdkVersion getExtOrIntegerDefault("compileSdkVersion")
|
|
38
|
+
compileSdkVersion getExtOrDefault("compileSdkVersion")
|
|
59
39
|
|
|
60
40
|
defaultConfig {
|
|
61
|
-
minSdkVersion
|
|
62
|
-
targetSdkVersion
|
|
63
|
-
buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString()
|
|
41
|
+
minSdkVersion getExtOrDefault("minSdkVersion")
|
|
42
|
+
targetSdkVersion getExtOrDefault("targetSdkVersion")
|
|
64
43
|
}
|
|
65
44
|
|
|
66
45
|
buildFeatures {
|
|
@@ -73,7 +52,7 @@ android {
|
|
|
73
52
|
}
|
|
74
53
|
}
|
|
75
54
|
|
|
76
|
-
|
|
55
|
+
lint {
|
|
77
56
|
disable "GradleCompatible"
|
|
78
57
|
}
|
|
79
58
|
|
|
@@ -81,47 +60,8 @@ android {
|
|
|
81
60
|
sourceCompatibility JavaVersion.VERSION_1_8
|
|
82
61
|
targetCompatibility JavaVersion.VERSION_1_8
|
|
83
62
|
}
|
|
84
|
-
|
|
85
|
-
sourceSets {
|
|
86
|
-
main {
|
|
87
|
-
if (isNewArchitectureEnabled()) {
|
|
88
|
-
java.srcDirs += [
|
|
89
|
-
"src/newarch",
|
|
90
|
-
// This is needed to build Kotlin project with NewArch enabled
|
|
91
|
-
"${project.buildDir}/generated/source/codegen/java"
|
|
92
|
-
]
|
|
93
|
-
} else {
|
|
94
|
-
java.srcDirs += ["src/oldarch"]
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
repositories {
|
|
101
|
-
mavenCentral()
|
|
102
|
-
google()
|
|
103
63
|
}
|
|
104
64
|
|
|
105
|
-
def kotlin_version = getExtOrDefault("kotlinVersion")
|
|
106
|
-
def junit_version = getDefault("junitVersion")
|
|
107
|
-
def android_x_core_version = getDefault("androidXCoreVersion")
|
|
108
|
-
def robolectric_version = getDefault("robolectricVersion")
|
|
109
|
-
def mockito_core_version = getDefault("mockitoCoreVersion")
|
|
110
|
-
|
|
111
65
|
dependencies {
|
|
112
66
|
implementation "com.facebook.react:react-android"
|
|
113
|
-
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
|
114
|
-
|
|
115
|
-
testImplementation "junit:junit:$junit_version"
|
|
116
|
-
testImplementation "androidx.test:core:$android_x_core_version"
|
|
117
|
-
testImplementation "org.robolectric:robolectric:$robolectric_version"
|
|
118
|
-
testImplementation "org.mockito:mockito-core:$mockito_core_version"
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
if (isNewArchitectureEnabled()) {
|
|
122
|
-
react {
|
|
123
|
-
jsRootDir = file("../src/")
|
|
124
|
-
libraryName = "OrientationDirector"
|
|
125
|
-
codegenJavaPackageName = "com.orientationdirector"
|
|
126
|
-
}
|
|
127
67
|
}
|
package/android/src/{newarch → main/java/com/orientationdirector}/OrientationDirectorModule.kt
RENAMED
|
@@ -2,36 +2,33 @@ package com.orientationdirector
|
|
|
2
2
|
|
|
3
3
|
import com.facebook.react.bridge.Promise
|
|
4
4
|
import com.facebook.react.bridge.ReactApplicationContext
|
|
5
|
+
import com.facebook.react.bridge.WritableMap
|
|
6
|
+
import com.orientationdirector.implementation.EventManagerDelegate
|
|
5
7
|
import com.orientationdirector.implementation.OrientationDirectorModuleImpl
|
|
6
8
|
|
|
7
|
-
class OrientationDirectorModule
|
|
8
|
-
NativeOrientationDirectorSpec(
|
|
9
|
+
class OrientationDirectorModule(reactContext: ReactApplicationContext) :
|
|
10
|
+
NativeOrientationDirectorSpec(reactContext), EventManagerDelegate {
|
|
9
11
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
override fun getName() = OrientationDirectorModuleImpl.NAME
|
|
12
|
+
override fun getName() = NAME
|
|
13
13
|
|
|
14
|
+
private var implementation = OrientationDirectorModuleImpl(reactContext, this)
|
|
14
15
|
|
|
15
16
|
override fun getInterfaceOrientation(promise: Promise) {
|
|
16
17
|
promise.resolve(implementation.getInterfaceOrientation().ordinal)
|
|
17
18
|
}
|
|
18
19
|
|
|
19
|
-
|
|
20
20
|
override fun getDeviceOrientation(promise: Promise) {
|
|
21
21
|
promise.resolve(implementation.getDeviceOrientation().ordinal)
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
|
|
25
24
|
override fun lockTo(orientation: Double) {
|
|
26
25
|
implementation.lockTo(orientation.toInt())
|
|
27
26
|
}
|
|
28
27
|
|
|
29
|
-
|
|
30
28
|
override fun unlock() {
|
|
31
29
|
implementation.unlock()
|
|
32
30
|
}
|
|
33
31
|
|
|
34
|
-
|
|
35
32
|
override fun resetSupportedInterfaceOrientations() {
|
|
36
33
|
implementation.resetSupportedInterfaceOrientations()
|
|
37
34
|
}
|
|
@@ -52,8 +49,20 @@ class OrientationDirectorModule internal constructor(context: ReactApplicationCo
|
|
|
52
49
|
return implementation.disableOrientationSensors()
|
|
53
50
|
}
|
|
54
51
|
|
|
55
|
-
override fun
|
|
52
|
+
override fun sendOnDeviceOrientationChanged(params: WritableMap) {
|
|
53
|
+
emitOnDeviceOrientationChanged(params)
|
|
54
|
+
}
|
|
56
55
|
|
|
57
|
-
override fun
|
|
56
|
+
override fun sendOnInterfaceOrientationChanged(params: WritableMap) {
|
|
57
|
+
emitOnInterfaceOrientationChanged(params)
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
override fun sendOnLockChanged(params: WritableMap) {
|
|
61
|
+
emitOnLockChanged(params)
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
companion object {
|
|
65
|
+
const val NAME = OrientationDirectorModuleImpl.NAME
|
|
66
|
+
}
|
|
58
67
|
|
|
59
68
|
}
|
|
@@ -1,35 +1,30 @@
|
|
|
1
1
|
package com.orientationdirector
|
|
2
2
|
|
|
3
3
|
import com.facebook.react.BaseReactPackage
|
|
4
|
-
import com.facebook.react.bridge.ReactApplicationContext
|
|
5
4
|
import com.facebook.react.bridge.NativeModule
|
|
6
|
-
import com.facebook.react.
|
|
5
|
+
import com.facebook.react.bridge.ReactApplicationContext
|
|
7
6
|
import com.facebook.react.module.model.ReactModuleInfo
|
|
8
|
-
import com.
|
|
9
|
-
import java.util.HashMap
|
|
7
|
+
import com.facebook.react.module.model.ReactModuleInfoProvider
|
|
10
8
|
|
|
11
9
|
class OrientationDirectorPackage : BaseReactPackage() {
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
|
|
11
|
+
override fun getModule(name: String, reactContext: ReactApplicationContext): NativeModule? =
|
|
12
|
+
if (name == OrientationDirectorModule.NAME) {
|
|
14
13
|
OrientationDirectorModule(reactContext)
|
|
15
14
|
} else {
|
|
16
15
|
null
|
|
17
16
|
}
|
|
18
|
-
}
|
|
19
17
|
|
|
20
|
-
override fun getReactModuleInfoProvider()
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
false,
|
|
28
|
-
|
|
29
|
-
false, // isCxxModule
|
|
30
|
-
isTurboModule // isTurboModule
|
|
18
|
+
override fun getReactModuleInfoProvider() = ReactModuleInfoProvider {
|
|
19
|
+
mapOf(
|
|
20
|
+
OrientationDirectorModule.NAME to ReactModuleInfo(
|
|
21
|
+
name = OrientationDirectorModule.NAME,
|
|
22
|
+
className = OrientationDirectorModule.NAME,
|
|
23
|
+
canOverrideExistingModule = false,
|
|
24
|
+
needsEagerInit = false,
|
|
25
|
+
isCxxModule = false,
|
|
26
|
+
isTurboModule = true
|
|
31
27
|
)
|
|
32
|
-
|
|
33
|
-
}
|
|
28
|
+
)
|
|
34
29
|
}
|
|
35
30
|
}
|
|
@@ -5,39 +5,26 @@ import com.facebook.react.bridge.ReactApplicationContext
|
|
|
5
5
|
import com.facebook.react.bridge.WritableMap
|
|
6
6
|
import com.facebook.react.modules.core.DeviceEventManagerModule
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
DeviceOrientationDidChange,
|
|
10
|
-
InterfaceOrientationDidChange,
|
|
11
|
-
LockDidChange,
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
class EventManager(private val context: ReactApplicationContext) {
|
|
15
|
-
|
|
8
|
+
class EventManager(private val delegate: EventManagerDelegate) {
|
|
16
9
|
fun sendDeviceOrientationDidChange(orientationValue: Int) {
|
|
17
10
|
val params = Arguments.createMap().apply {
|
|
18
11
|
putInt("orientation", orientationValue)
|
|
19
12
|
}
|
|
20
|
-
|
|
13
|
+
delegate.sendOnDeviceOrientationChanged(params)
|
|
21
14
|
}
|
|
22
15
|
|
|
23
16
|
fun sendInterfaceOrientationDidChange(orientationValue: Int) {
|
|
24
17
|
val params = Arguments.createMap().apply {
|
|
25
18
|
putInt("orientation", orientationValue)
|
|
26
19
|
}
|
|
27
|
-
|
|
20
|
+
delegate.sendOnInterfaceOrientationChanged(params)
|
|
28
21
|
}
|
|
29
22
|
|
|
30
23
|
fun sendLockDidChange(value: Boolean) {
|
|
31
24
|
val params = Arguments.createMap().apply {
|
|
32
25
|
putBoolean("locked", value)
|
|
33
26
|
}
|
|
34
|
-
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
private fun sendEvent(eventName: Event, params: WritableMap?) {
|
|
38
|
-
context
|
|
39
|
-
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)
|
|
40
|
-
.emit(eventName.name, params)
|
|
27
|
+
delegate.sendOnLockChanged(params)
|
|
41
28
|
}
|
|
42
29
|
|
|
43
30
|
companion object {
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
package com.orientationdirector.implementation
|
|
2
|
+
|
|
3
|
+
import com.facebook.react.bridge.WritableMap
|
|
4
|
+
|
|
5
|
+
interface EventManagerDelegate {
|
|
6
|
+
fun sendOnDeviceOrientationChanged(params: WritableMap)
|
|
7
|
+
fun sendOnInterfaceOrientationChanged(params: WritableMap)
|
|
8
|
+
fun sendOnLockChanged(params: WritableMap)
|
|
9
|
+
}
|
|
@@ -5,9 +5,9 @@ import android.os.Handler
|
|
|
5
5
|
import android.os.Looper
|
|
6
6
|
import com.facebook.react.bridge.ReactApplicationContext
|
|
7
7
|
|
|
8
|
-
class OrientationDirectorModuleImpl internal constructor(private val context: ReactApplicationContext) {
|
|
8
|
+
class OrientationDirectorModuleImpl internal constructor(private val context: ReactApplicationContext, eventManagerDelegate: EventManagerDelegate) {
|
|
9
9
|
private var mUtils = Utils(context)
|
|
10
|
-
private var mEventManager = EventManager(
|
|
10
|
+
private var mEventManager = EventManager(eventManagerDelegate)
|
|
11
11
|
private var mOrientationSensorsEventListener = OrientationSensorsEventListener(context)
|
|
12
12
|
private var mAutoRotationObserver = AutoRotationObserver(
|
|
13
13
|
context, Handler(
|
|
@@ -26,8 +26,8 @@ class OrientationDirectorModuleImpl internal constructor(private val context: Re
|
|
|
26
26
|
private var didComputeInitialDeviceOrientation = false;
|
|
27
27
|
|
|
28
28
|
init {
|
|
29
|
-
mOrientationSensorsEventListener.
|
|
30
|
-
|
|
29
|
+
mOrientationSensorsEventListener.setOnDeviceOrientationChangedCallback { orientation ->
|
|
30
|
+
onDeviceOrientationChanged(orientation)
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
mAutoRotationObserver.enable()
|
|
@@ -36,6 +36,9 @@ class OrientationDirectorModuleImpl internal constructor(private val context: Re
|
|
|
36
36
|
checkInterfaceOrientation(false)
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
+
// NOTE(1.init): This is needed to compute the initial device orientation
|
|
40
|
+
mOrientationSensorsEventListener.enable()
|
|
41
|
+
|
|
39
42
|
context.addLifecycleEventListener(mLifecycleListener)
|
|
40
43
|
mLifecycleListener.setOnHostResumeCallback {
|
|
41
44
|
if (!didComputeInitialDeviceOrientation || areOrientationSensorsEnabled) {
|
|
@@ -45,17 +48,17 @@ class OrientationDirectorModuleImpl internal constructor(private val context: Re
|
|
|
45
48
|
mBroadcastReceiver.register()
|
|
46
49
|
}
|
|
47
50
|
mLifecycleListener.setOnHostPauseCallback {
|
|
48
|
-
if (
|
|
51
|
+
if (!didComputeInitialDeviceOrientation || areOrientationSensorsEnabled) {
|
|
49
52
|
mOrientationSensorsEventListener.disable()
|
|
50
|
-
mAutoRotationObserver.disable()
|
|
51
53
|
}
|
|
54
|
+
mAutoRotationObserver.disable()
|
|
52
55
|
mBroadcastReceiver.unregister()
|
|
53
56
|
}
|
|
54
57
|
mLifecycleListener.setOnHostDestroyCallback {
|
|
55
|
-
if (areOrientationSensorsEnabled) {
|
|
58
|
+
if (!didComputeInitialDeviceOrientation || areOrientationSensorsEnabled) {
|
|
56
59
|
mOrientationSensorsEventListener.disable()
|
|
57
|
-
mAutoRotationObserver.disable()
|
|
58
60
|
}
|
|
61
|
+
mAutoRotationObserver.disable()
|
|
59
62
|
mBroadcastReceiver.unregister()
|
|
60
63
|
}
|
|
61
64
|
|
|
@@ -148,35 +151,31 @@ class OrientationDirectorModuleImpl internal constructor(private val context: Re
|
|
|
148
151
|
).contains(activity.requestedOrientation)
|
|
149
152
|
}
|
|
150
153
|
|
|
151
|
-
private fun
|
|
152
|
-
|
|
153
|
-
if (deviceOrientation == Orientation.UNKNOWN) {
|
|
154
|
-
return
|
|
155
|
-
}
|
|
154
|
+
private fun onDeviceOrientationChanged(deviceOrientation: Orientation) {
|
|
155
|
+
if (deviceOrientation == Orientation.UNKNOWN) return
|
|
156
156
|
|
|
157
|
-
if (lastDeviceOrientation == deviceOrientation)
|
|
158
|
-
return
|
|
159
|
-
}
|
|
157
|
+
if (lastDeviceOrientation == deviceOrientation) return
|
|
160
158
|
|
|
161
159
|
mEventManager.sendDeviceOrientationDidChange(deviceOrientation.ordinal)
|
|
162
160
|
lastDeviceOrientation = deviceOrientation
|
|
163
161
|
|
|
164
162
|
checkInterfaceOrientation()
|
|
165
163
|
|
|
166
|
-
|
|
167
|
-
|
|
164
|
+
// NOTE(2.init): This is needed to disable sensors if they were needed just for the initial
|
|
165
|
+
// device computation.
|
|
166
|
+
if (didComputeInitialDeviceOrientation) return
|
|
167
|
+
|
|
168
|
+
didComputeInitialDeviceOrientation = true
|
|
169
|
+
|
|
170
|
+
if (!areOrientationSensorsEnabled) {
|
|
168
171
|
mOrientationSensorsEventListener.disable()
|
|
169
172
|
}
|
|
170
173
|
}
|
|
171
174
|
|
|
172
175
|
private fun checkInterfaceOrientation(skipIfAutoRotationIsDisabled: Boolean = true) {
|
|
173
|
-
if (skipIfAutoRotationIsDisabled && !mAutoRotationObserver.getLastAutoRotationStatus())
|
|
174
|
-
return
|
|
175
|
-
}
|
|
176
|
+
if (skipIfAutoRotationIsDisabled && !mAutoRotationObserver.getLastAutoRotationStatus()) return
|
|
176
177
|
|
|
177
|
-
if (isLocked)
|
|
178
|
-
return
|
|
179
|
-
}
|
|
178
|
+
if (isLocked) return
|
|
180
179
|
|
|
181
180
|
if (lastDeviceOrientation != Orientation.LANDSCAPE_RIGHT && lastDeviceOrientation != Orientation.LANDSCAPE_LEFT) {
|
|
182
181
|
val rotation = mUtils.getInterfaceRotation()
|