expo-screen-orientation 5.1.1 → 6.0.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/CHANGELOG.md +23 -0
  2. package/README.md +1 -1
  3. package/android/build.gradle +8 -10
  4. package/android/src/main/AndroidManifest.xml +1 -1
  5. package/android/src/main/java/expo/modules/screenorientation/ScreenOrientationExceptions.kt +12 -0
  6. package/android/src/main/java/expo/modules/screenorientation/ScreenOrientationModule.kt +70 -128
  7. package/android/src/main/java/expo/modules/screenorientation/{Orientation.kt → enums/Orientation.kt} +1 -1
  8. package/android/src/main/java/expo/modules/screenorientation/enums/OrientationAttr.kt +39 -0
  9. package/android/src/main/java/expo/modules/screenorientation/enums/OrientationLock.kt +39 -0
  10. package/build/ExpoScreenOrientation.d.ts +1 -1
  11. package/build/ExpoScreenOrientation.d.ts.map +1 -1
  12. package/build/ExpoScreenOrientation.js +2 -2
  13. package/build/ExpoScreenOrientation.js.map +1 -1
  14. package/build/ScreenOrientation.d.ts +0 -30
  15. package/build/ScreenOrientation.d.ts.map +1 -1
  16. package/build/ScreenOrientation.js +0 -30
  17. package/build/ScreenOrientation.js.map +1 -1
  18. package/expo-module.config.json +5 -1
  19. package/ios/{EXScreenOrientation.podspec → ExpoScreenOrientation.podspec} +9 -2
  20. package/ios/{EXScreenOrientation/ScreenOrientationAppDelegate.swift → ScreenOrientationAppDelegate.swift} +5 -3
  21. package/ios/ScreenOrientationExceptions.swift +16 -0
  22. package/ios/ScreenOrientationModule.swift +118 -0
  23. package/ios/ScreenOrientationRNSScreenWindowTraits.h +11 -0
  24. package/ios/{EXScreenOrientation/ScreenOrientationReactDelegateHandler.swift → ScreenOrientationReactDelegateHandler.swift} +1 -1
  25. package/ios/ScreenOrientationRegistry.swift +252 -0
  26. package/ios/ScreenOrientationUtilities.swift +110 -0
  27. package/ios/ScreenOrientationViewController.swift +64 -0
  28. package/ios/enums/ModuleOrientation.swift +39 -0
  29. package/ios/enums/ModuleOrientationLock.swift +60 -0
  30. package/package.json +2 -2
  31. package/src/ExpoScreenOrientation.ts +2 -2
  32. package/src/ScreenOrientation.ts +0 -30
  33. package/android/src/main/java/expo/modules/screenorientation/ScreenOrientationPackage.kt +0 -8
  34. package/ios/EXScreenOrientation/EXScreenOrientationModule.h +0 -11
  35. package/ios/EXScreenOrientation/EXScreenOrientationModule.m +0 -177
  36. package/ios/EXScreenOrientation/EXScreenOrientationRegistry.h +0 -46
  37. package/ios/EXScreenOrientation/EXScreenOrientationRegistry.m +0 -272
  38. package/ios/EXScreenOrientation/EXScreenOrientationUtilities.h +0 -25
  39. package/ios/EXScreenOrientation/EXScreenOrientationUtilities.m +0 -172
  40. package/ios/EXScreenOrientation/EXScreenOrientationViewController.h +0 -14
  41. package/ios/EXScreenOrientation/EXScreenOrientationViewController.m +0 -88
  42. package/ios/EXScreenOrientation/NSString+UIInterfaceOrientationMask.h +0 -9
  43. package/ios/EXScreenOrientation/NSString+UIInterfaceOrientationMask.m +0 -21
package/CHANGELOG.md CHANGED
@@ -10,6 +10,29 @@
10
10
 
11
11
  ### 💡 Others
12
12
 
13
+ ## 6.0.0-beta.1 — 2023-06-13
14
+
15
+ ### 🎉 New features
16
+
17
+ - Added support for React Native 0.72. ([#22588](https://github.com/expo/expo/pull/22588) by [@kudo](https://github.com/kudo))
18
+
19
+ ### 🐛 Bug fixes
20
+
21
+ - Fixed Android build warnings for Gradle version 8. ([#22537](https://github.com/expo/expo/pull/22537), [#22609](https://github.com/expo/expo/pull/22609) by [@kudo](https://github.com/kudo))
22
+ - [iOS] Fixed screen orientation on iOS 16. ([#22152](https://github.com/expo/expo/pull/22152) by [@behenate](https://github.com/behenate))
23
+ - [iOS] Fixed status bar and navigation bar following the device's orientation regardless of applied orientation lock. ([#22152](https://github.com/expo/expo/pull/22152) by [@behenate](https://github.com/behenate))
24
+ - [iOS] Fixed SafeAreaViews failing after pulling down quick settings when the device is in a different orientation than the current orientation lock allows. ([#22152](https://github.com/expo/expo/pull/22152) by [@behenate](https://github.com/behenate))
25
+
26
+ ### 💡 Others
27
+
28
+ - [iOS] Migrated to new modules API. ([#22152](https://github.com/expo/expo/pull/22152) by [@behenate](https://github.com/behenate))
29
+
30
+ ## 5.2.0 — 2023-05-08
31
+
32
+ ### 🎉 New features
33
+
34
+ - Migrated to new modules API on Android ([#22019](https://github.com/expo/expo/pull/22019) by [@behenate](https://github.com/behenate))
35
+
13
36
  ## 5.1.1 — 2023-02-09
14
37
 
15
38
  _This version does not introduce any user-facing changes._
package/README.md CHANGED
@@ -9,7 +9,7 @@ Allows you to manage the orientation of your app's interface.
9
9
 
10
10
  # Installation in managed Expo projects
11
11
 
12
- For [managed](https://docs.expo.dev/versions/latest/introduction/managed-vs-bare/) Expo projects, please follow the installation instructions in the [API documentation for the latest stable release](https://docs.expo.dev/versions/latest/sdk/screen-orientation/). If you follow the link and there is no documentation available then this library is not yet usable within managed projects — it is likely to be included in an upcoming Expo SDK release.
12
+ For [managed](https://docs.expo.dev/archive/managed-vs-bare/) Expo projects, please follow the installation instructions in the [API documentation for the latest stable release](https://docs.expo.dev/versions/latest/sdk/screen-orientation/). If you follow the link and there is no documentation available then this library is not yet usable within managed projects — it is likely to be included in an upcoming Expo SDK release.
13
13
 
14
14
  # Installation in bare React Native projects
15
15
 
@@ -3,7 +3,7 @@ apply plugin: 'kotlin-android'
3
3
  apply plugin: 'maven-publish'
4
4
 
5
5
  group = 'host.exp.exponent'
6
- version = '5.1.1'
6
+ version = '6.0.0-beta.1'
7
7
 
8
8
  buildscript {
9
9
  def expoModulesCorePlugin = new File(project(":expo-modules-core").projectDir.absolutePath, "ExpoModulesCorePlugin.gradle")
@@ -35,19 +35,11 @@ buildscript {
35
35
  }
36
36
  }
37
37
 
38
- // Creating sources with comments
39
- task androidSourcesJar(type: Jar) {
40
- classifier = 'sources'
41
- from android.sourceSets.main.java.srcDirs
42
- }
43
-
44
38
  afterEvaluate {
45
39
  publishing {
46
40
  publications {
47
41
  release(MavenPublication) {
48
42
  from components.release
49
- // Add additional sourcesJar to artifacts
50
- artifact(androidSourcesJar)
51
43
  }
52
44
  }
53
45
  repositories {
@@ -70,15 +62,21 @@ android {
70
62
  jvmTarget = JavaVersion.VERSION_11.majorVersion
71
63
  }
72
64
 
65
+ namespace "expo.modules.screenorientation"
73
66
  defaultConfig {
74
67
  minSdkVersion safeExtGet("minSdkVersion", 21)
75
68
  targetSdkVersion safeExtGet("targetSdkVersion", 33)
76
69
  versionCode 7
77
- versionName '5.1.1'
70
+ versionName '6.0.0-beta.1'
78
71
  }
79
72
  lintOptions {
80
73
  abortOnError false
81
74
  }
75
+ publishing {
76
+ singleVariant("release") {
77
+ withSourcesJar()
78
+ }
79
+ }
82
80
  }
83
81
 
84
82
  dependencies {
@@ -1,2 +1,2 @@
1
- <manifest package="expo.modules.screenorientation">
1
+ <manifest>
2
2
  </manifest>
@@ -0,0 +1,12 @@
1
+ package expo.modules.screenorientation
2
+
3
+ import expo.modules.kotlin.exception.CodedException
4
+
5
+ internal class InvalidOrientationLockException(orientationLock: Int, cause: Exception) :
6
+ CodedException("An invalid OrientationLock was passed in: $orientationLock", cause)
7
+
8
+ internal class GetOrientationLockException(cause: Exception) :
9
+ CodedException("Could not get the current screen orientation lock: ", cause)
10
+
11
+ internal class GetPlatformOrientationLockException(cause: Exception) :
12
+ CodedException("Could not get the current screen orientation platform lock", cause)
@@ -1,146 +1,117 @@
1
1
  package expo.modules.screenorientation
2
2
 
3
3
  import android.app.Activity
4
- import android.content.Context
5
- import android.content.pm.ActivityInfo
4
+ import android.os.Build
6
5
  import android.util.DisplayMetrics
7
6
  import android.view.Surface
8
- import expo.modules.core.ExportedModule
9
- import expo.modules.core.ModuleRegistry
10
- import expo.modules.core.Promise
7
+ import android.view.WindowInsets
8
+
11
9
  import expo.modules.core.errors.InvalidArgumentException
12
- import expo.modules.core.interfaces.ActivityProvider
13
- import expo.modules.core.interfaces.ExpoMethod
14
10
  import expo.modules.core.interfaces.LifecycleEventListener
15
11
  import expo.modules.core.interfaces.services.UIManager
12
+ import expo.modules.kotlin.exception.Exceptions
13
+ import expo.modules.kotlin.modules.Module
14
+ import expo.modules.kotlin.modules.ModuleDefinition
15
+ import expo.modules.screenorientation.enums.Orientation
16
+ import expo.modules.screenorientation.enums.OrientationAttr
17
+ import expo.modules.screenorientation.enums.OrientationLock
16
18
 
17
- private const val ERR_SCREEN_ORIENTATION_UNSUPPORTED_ORIENTATION_LOCK = "ERR_SCREEN_ORIENTATION_UNSUPPORTED_ORIENTATION_LOCK"
18
- private const val ERR_SCREEN_ORIENTATION_INVALID_ORIENTATION_LOCK = "ERR_SCREEN_ORIENTATION_INVALID_ORIENTATION_LOCK"
19
- private const val ERR_SCREEN_ORIENTATION_GET_ORIENTATION_LOCK = "ERR_SCREEN_ORIENTATION_GET_ORIENTATION_LOCK"
20
- private const val ERR_SCREEN_ORIENTATION_GET_PLATFORM_ORIENTATION_LOCK = "ERR_SCREEN_ORIENTATION_GET_PLATFORM_ORIENTATION_LOCK"
21
- private const val ERR_SCREEN_ORIENTATION_MISSING_ACTIVITY = "ERR_SCREEN_ORIENTATION_MISSING_ACTIVITY"
19
+ class ScreenOrientationModule : Module(), LifecycleEventListener {
20
+ private val weakCurrentActivity
21
+ get() = appContext.activityProvider?.currentActivity
22
22
 
23
- class ScreenOrientationModule(context: Context) : ExportedModule(context), LifecycleEventListener {
24
- private lateinit var mActivityProvider: ActivityProvider
25
- private var mInitialOrientation: Int? = null
23
+ private val currentActivity
24
+ get() = weakCurrentActivity ?: throw Exceptions.MissingActivity()
26
25
 
27
- override fun getName() = "ExpoScreenOrientation"
26
+ private val uiManager
27
+ get() = appContext.legacyModuleRegistry.getModule(UIManager::class.java)
28
+ ?: throw IllegalStateException("Could not find implementation for UIManager.")
28
29
 
29
- override fun onCreate(moduleRegistry: ModuleRegistry) {
30
- mActivityProvider = moduleRegistry.getModule(ActivityProvider::class.java)
31
- ?: throw IllegalStateException("Could not find implementation for ActivityProvider.")
30
+ private var initialOrientation: Int? = null
32
31
 
33
- (
34
- moduleRegistry.getModule(UIManager::class.java)
35
- ?: throw IllegalStateException("Could not find implementation for UIManager.")
36
- )
37
- .registerLifecycleEventListener(this)
38
- }
32
+ override fun definition() = ModuleDefinition {
33
+ Name("ExpoScreenOrientation")
39
34
 
40
- override fun onHostResume() {
41
- mActivityProvider.currentActivity?.let {
42
- if (mInitialOrientation == null) {
43
- mInitialOrientation = it.requestedOrientation
35
+ AsyncFunction("lockAsync") { orientationLock: OrientationLock ->
36
+ try {
37
+ currentActivity.requestedOrientation = orientationLock.toPlatformInt()
38
+ } catch (e: InvalidArgumentException) {
39
+ throw InvalidOrientationLockException(orientationLock.value, e)
44
40
  }
45
41
  }
46
- }
47
42
 
48
- override fun onHostPause() = Unit
49
-
50
- override fun onHostDestroy() = Unit
43
+ AsyncFunction("lockPlatformAsync") { orientationAttr: OrientationAttr ->
44
+ currentActivity.requestedOrientation = orientationAttr.value
45
+ }
51
46
 
52
- override fun onDestroy() {
53
- mActivityProvider.currentActivity?.let { activity ->
54
- mInitialOrientation?.let {
55
- activity.requestedOrientation = it
56
- }
47
+ AsyncFunction("getOrientationAsync") {
48
+ return@AsyncFunction getScreenOrientation(currentActivity).value
57
49
  }
58
- }
59
50
 
60
- @ExpoMethod
61
- fun lockAsync(orientationLock: Int, promise: Promise) {
62
- mActivityProvider.currentActivity?.let {
63
- return try {
64
- it.requestedOrientation = importOrientationLock(orientationLock)
65
- promise.resolve(null)
66
- } catch (e: InvalidArgumentException) {
67
- promise.reject(ERR_SCREEN_ORIENTATION_INVALID_ORIENTATION_LOCK, "An invalid OrientationLock was passed in: $orientationLock", e)
51
+ AsyncFunction("getOrientationLockAsync") {
52
+ try {
53
+ return@AsyncFunction OrientationLock.fromPlatformInt(currentActivity.requestedOrientation)
68
54
  } catch (e: Exception) {
69
- promise.reject(ERR_SCREEN_ORIENTATION_UNSUPPORTED_ORIENTATION_LOCK, "Could not apply the ScreenOrientation lock: $orientationLock", e)
55
+ throw GetOrientationLockException(e)
70
56
  }
71
57
  }
72
58
 
73
- promise.reject(ERR_SCREEN_ORIENTATION_MISSING_ACTIVITY, "Could not find activity.", null)
74
- }
75
-
76
- @ExpoMethod
77
- fun lockPlatformAsync(orientationAttr: Int, promise: Promise) {
78
- mActivityProvider.currentActivity?.let {
79
- return try {
80
- it.requestedOrientation = orientationAttr
81
- promise.resolve(null)
59
+ AsyncFunction("getPlatformOrientationLockAsync") {
60
+ try {
61
+ return@AsyncFunction currentActivity.requestedOrientation
82
62
  } catch (e: Exception) {
83
- promise.reject(ERR_SCREEN_ORIENTATION_UNSUPPORTED_ORIENTATION_LOCK, "Could not apply the ScreenOrientation platform lock: $orientationAttr", e)
63
+ throw GetPlatformOrientationLockException(e)
84
64
  }
85
65
  }
86
66
 
87
- promise.reject(ERR_SCREEN_ORIENTATION_MISSING_ACTIVITY, "Could not find activity.", null)
88
- }
89
-
90
- @ExpoMethod
91
- fun getOrientationAsync(promise: Promise) {
92
- mActivityProvider.currentActivity?.let {
93
- return promise.resolve(getScreenOrientation(it).value)
67
+ AsyncFunction("supportsOrientationLockAsync") { orientationLock: Int ->
68
+ return@AsyncFunction OrientationLock.supportsOrientationLock(orientationLock)
94
69
  }
95
70
 
96
- promise.reject(ERR_SCREEN_ORIENTATION_MISSING_ACTIVITY, "Could not find activity.", null)
97
- }
98
-
99
- @ExpoMethod
100
- fun getOrientationLockAsync(promise: Promise) {
101
- mActivityProvider.currentActivity?.let {
102
- return try {
103
- promise.resolve(exportOrientationLock(it.requestedOrientation))
104
- } catch (e: Exception) {
105
- promise.reject(ERR_SCREEN_ORIENTATION_GET_ORIENTATION_LOCK, "Could not get the current screen orientation lock", e)
106
- }
71
+ OnCreate {
72
+ uiManager.registerLifecycleEventListener(this@ScreenOrientationModule)
107
73
  }
108
74
 
109
- promise.reject(ERR_SCREEN_ORIENTATION_MISSING_ACTIVITY, "Could not find activity.", null)
110
- }
111
-
112
- @ExpoMethod
113
- fun getPlatformOrientationLockAsync(promise: Promise) {
114
- mActivityProvider.currentActivity?.let {
115
- return try {
116
- promise.resolve(it.requestedOrientation)
117
- } catch (e: Exception) {
118
- promise.reject(ERR_SCREEN_ORIENTATION_GET_PLATFORM_ORIENTATION_LOCK, "Could not get the current screen orientation platform lock", e)
75
+ OnDestroy {
76
+ uiManager.unregisterLifecycleEventListener(this@ScreenOrientationModule)
77
+ initialOrientation?.let {
78
+ weakCurrentActivity?.requestedOrientation = it
119
79
  }
120
80
  }
121
-
122
- promise.reject(ERR_SCREEN_ORIENTATION_MISSING_ACTIVITY, "Could not find activity.", null)
123
81
  }
124
82
 
125
- @ExpoMethod
126
- fun supportsOrientationLockAsync(orientationLock: Int, promise: Promise) {
127
- try {
128
- importOrientationLock(orientationLock)
129
- promise.resolve(true)
130
- } catch (e: Exception) {
131
- promise.resolve(false)
132
- }
83
+ override fun onHostResume() {
84
+ initialOrientation = initialOrientation ?: weakCurrentActivity?.requestedOrientation
133
85
  }
134
86
 
87
+ override fun onHostPause() = Unit
88
+
89
+ override fun onHostDestroy() = Unit
90
+
135
91
  // https://stackoverflow.com/a/10383164/1123156
136
92
  // Will not work in all cases as surface rotation is not standardized across android devices, but this is best effort
137
93
  private fun getScreenOrientation(activity: Activity): Orientation {
138
94
  val windowManager = activity.windowManager ?: return Orientation.UNKNOWN
139
- val rotation = windowManager.defaultDisplay.rotation
140
- val dm = DisplayMetrics().also(windowManager.defaultDisplay::getMetrics)
141
95
 
142
- val currentOrientation: Orientation
96
+ val rotation = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
97
+ currentActivity.window.context.display?.rotation ?: return Orientation.UNKNOWN
98
+ } else {
99
+ windowManager.defaultDisplay.rotation
100
+ }
143
101
 
102
+ val dm = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
103
+ val windowMetrics = windowManager.currentWindowMetrics
104
+ val insets = windowMetrics.windowInsets
105
+ .getInsetsIgnoringVisibility(WindowInsets.Type.systemBars())
106
+ DisplayMetrics().apply {
107
+ widthPixels = windowMetrics.bounds.width() - insets.left - insets.right
108
+ heightPixels = windowMetrics.bounds.height() - insets.top - insets.bottom
109
+ }
110
+ } else {
111
+ DisplayMetrics().also(windowManager.defaultDisplay::getMetrics)
112
+ }
113
+
114
+ val currentOrientation: Orientation
144
115
  if (isPortraitNaturalOrientation(rotation, dm.widthPixels, dm.heightPixels)) {
145
116
  currentOrientation = when (rotation) {
146
117
  Surface.ROTATION_0 -> Orientation.PORTRAIT_UP
@@ -172,33 +143,4 @@ class ScreenOrientationModule(context: Context) : ExportedModule(context), Lifec
172
143
  height > width || (rotation == Surface.ROTATION_90 || rotation == Surface.ROTATION_270) &&
173
144
  width > height
174
145
  }
175
-
176
- private fun exportOrientationLock(nativeOrientationLock: Int): Int {
177
- return when (nativeOrientationLock) {
178
- ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED -> 0
179
- ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR -> 1
180
- ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT -> 2
181
- ActivityInfo.SCREEN_ORIENTATION_PORTRAIT -> 3
182
- ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT -> 4
183
- ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE -> 5
184
- ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE -> 6
185
- ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE -> 7
186
- else -> 8 // other orientation
187
- }
188
- }
189
-
190
- @Throws(InvalidArgumentException::class)
191
- private fun importOrientationLock(orientationLock: Int): Int {
192
- return when (orientationLock) {
193
- 0 -> ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
194
- 1 -> ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
195
- 2 -> ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT
196
- 3 -> ActivityInfo.SCREEN_ORIENTATION_PORTRAIT
197
- 4 -> ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT
198
- 5 -> ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE
199
- 6 -> ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE
200
- 7 -> ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE
201
- else -> throw InvalidArgumentException("OrientationLock $orientationLock is not mappable to a native Android orientation attr")
202
- }
203
- }
204
146
  }
@@ -1,4 +1,4 @@
1
- package expo.modules.screenorientation
1
+ package expo.modules.screenorientation.enums
2
2
 
3
3
  /*
4
4
  * Enum representing a screen orientation.
@@ -0,0 +1,39 @@
1
+ package expo.modules.screenorientation.enums
2
+
3
+ import android.content.pm.ActivityInfo
4
+ import expo.modules.core.errors.InvalidArgumentException
5
+ import expo.modules.kotlin.types.Enumerable
6
+
7
+ enum class OrientationAttr(val value: Int) : Enumerable {
8
+ Behind(ActivityInfo.SCREEN_ORIENTATION_BEHIND),
9
+ Landscape(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE),
10
+ Portrait(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT),
11
+ FullSensor(ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR),
12
+ Unspecified(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED),
13
+ Locked(ActivityInfo.SCREEN_ORIENTATION_LOCKED),
14
+ FullUser(ActivityInfo.SCREEN_ORIENTATION_FULL_USER),
15
+ NoSensor(ActivityInfo.SCREEN_ORIENTATION_NOSENSOR),
16
+ ReverseLandscape(ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE),
17
+ ReversePortrait(ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT),
18
+ Sensor(ActivityInfo.SCREEN_ORIENTATION_SENSOR),
19
+ SensorPortrait(ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT),
20
+ SensorLandscape(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE),
21
+ User(ActivityInfo.SCREEN_ORIENTATION_USER),
22
+ UserPortrait(ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT),
23
+ UserLandscape(ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE);
24
+
25
+ internal fun toOrientationLock() = try {
26
+ OrientationLock.values().first { it.name == this@OrientationAttr.name }
27
+ } catch (e: NoSuchElementException) {
28
+ OrientationLock.Other
29
+ }
30
+
31
+ companion object {
32
+ @Throws(InvalidArgumentException::class)
33
+ fun fromInt(value: Int) = try {
34
+ OrientationAttr.values().first { it.value == value }
35
+ } catch (e: NoSuchElementException) {
36
+ throw InvalidArgumentException("Platform orientation $value is not a valid Android orientation attr")
37
+ }
38
+ }
39
+ }
@@ -0,0 +1,39 @@
1
+ package expo.modules.screenorientation.enums
2
+
3
+ import expo.modules.core.errors.InvalidArgumentException
4
+ import expo.modules.kotlin.types.Enumerable
5
+
6
+ enum class OrientationLock(val value: Int) : Enumerable {
7
+ Unspecified(0),
8
+ FullSensor(1),
9
+ SensorPortrait(2),
10
+ Portrait(3),
11
+ ReversePortrait(4),
12
+ SensorLandscape(5),
13
+ ReverseLandscape(6),
14
+ Landscape(7),
15
+ Other(8),
16
+
17
+ // Not used for anything in the native code, but it should be possible to assign an "Unknown" value to OrientationLock
18
+ // https://docs.expo.dev/versions/latest/sdk/screen-orientation/#unknown-1
19
+ Unknown(9);
20
+
21
+ @Throws(InvalidArgumentException::class)
22
+ internal fun toOrientationAttr() = try {
23
+ OrientationAttr.values().first { it.name == this@OrientationLock.name }
24
+ } catch (e: NoSuchElementException) {
25
+ throw InvalidArgumentException("OrientationLock ${this@OrientationLock} is not mappable to a native Android orientation attr")
26
+ }
27
+
28
+ @Throws(InvalidArgumentException::class)
29
+ internal fun toPlatformInt() = toOrientationAttr().value
30
+
31
+ companion object {
32
+ @Throws(InvalidArgumentException::class)
33
+ fun fromPlatformInt(value: Int) = OrientationAttr.fromInt(value).toOrientationLock()
34
+
35
+ // Other and Unknown can be assigned but are not valid orientation locks
36
+ fun supportsOrientationLock(value: Int): Boolean =
37
+ OrientationLock.values().any { it.value == value } && value != Other.value && value != Unknown.value
38
+ }
39
+ }
@@ -1,3 +1,3 @@
1
- declare const _default: import("expo-modules-core").ProxyNativeModule;
1
+ declare const _default: any;
2
2
  export default _default;
3
3
  //# sourceMappingURL=ExpoScreenOrientation.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ExpoScreenOrientation.d.ts","sourceRoot":"","sources":["../src/ExpoScreenOrientation.ts"],"names":[],"mappings":";AAEA,wBAA8D"}
1
+ {"version":3,"file":"ExpoScreenOrientation.d.ts","sourceRoot":"","sources":["../src/ExpoScreenOrientation.ts"],"names":[],"mappings":";AAEA,wBAA4D"}
@@ -1,3 +1,3 @@
1
- import { NativeModulesProxy } from 'expo-modules-core';
2
- export default NativeModulesProxy.ExpoScreenOrientation || {};
1
+ import { requireNativeModule } from 'expo-modules-core';
2
+ export default requireNativeModule('ExpoScreenOrientation');
3
3
  //# sourceMappingURL=ExpoScreenOrientation.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"ExpoScreenOrientation.js","sourceRoot":"","sources":["../src/ExpoScreenOrientation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAEvD,eAAe,kBAAkB,CAAC,qBAAqB,IAAI,EAAE,CAAC","sourcesContent":["import { NativeModulesProxy } from 'expo-modules-core';\n\nexport default NativeModulesProxy.ExpoScreenOrientation || {};\n"]}
1
+ {"version":3,"file":"ExpoScreenOrientation.js","sourceRoot":"","sources":["../src/ExpoScreenOrientation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAExD,eAAe,mBAAmB,CAAC,uBAAuB,CAAC,CAAC","sourcesContent":["import { requireNativeModule } from 'expo-modules-core';\n\nexport default requireNativeModule('ExpoScreenOrientation');\n"]}
@@ -7,13 +7,6 @@ export { Orientation, OrientationLock, PlatformOrientationInfo, OrientationChang
7
7
  * enum for possible values.
8
8
  * @return Returns a promise with `void` value, which fulfils when the orientation is set.
9
9
  *
10
- * # Error codes
11
- * - `ERR_SCREEN_ORIENTATION_INVALID_ORIENTATION_LOCK` - An invalid [`OrientationLock`](#orientationlock)
12
- * was passed in.
13
- * - `ERR_SCREEN_ORIENTATION_UNSUPPORTED_ORIENTATION_LOCK` - The platform does not support the
14
- * orientation lock policy.
15
- * - `ERR_SCREEN_ORIENTATION_MISSING_ACTIVITY` - __Android Only.__ Could not get the current activity.
16
- *
17
10
  * @example
18
11
  * ```ts
19
12
  * async function changeScreenOrientation() {
@@ -27,52 +20,29 @@ export declare function lockAsync(orientationLock: OrientationLock): Promise<voi
27
20
  * object type for the different platform formats.
28
21
  * @return Returns a promise with `void` value, resolving when the orientation is set and rejecting
29
22
  * if an invalid option or value is passed.
30
- *
31
- * # Error codes
32
- * - `ERR_SCREEN_ORIENTATION_INVALID_ORIENTATION_LOCK` - __iOS Only.__ An invalid [`OrientationLock`](#orientationlock)
33
- * was passed in.
34
- * - `ERR_SCREEN_ORIENTATION_UNSUPPORTED_ORIENTATION_LOCK` - The platform does not support the
35
- * orientation lock policy.
36
- * - `ERR_SCREEN_ORIENTATION_MISSING_ACTIVITY` - __Android Only.__ Could not get the current activity.
37
- *
38
23
  */
39
24
  export declare function lockPlatformAsync(options: PlatformOrientationInfo): Promise<void>;
40
25
  /**
41
26
  * Sets the screen orientation back to the `OrientationLock.DEFAULT` policy.
42
27
  * @return Returns a promise with `void` value, which fulfils when the orientation is set.
43
- *
44
- * # Error codes
45
- * - `ERR_SCREEN_ORIENTATION_MISSING_ACTIVITY` - __Android Only.__ Could not get the current activity.
46
28
  */
47
29
  export declare function unlockAsync(): Promise<void>;
48
30
  /**
49
31
  * Gets the current screen orientation.
50
32
  * @return Returns a promise that fulfils with an [`Orientation`](#screenorientationorientation)
51
33
  * value that reflects the current screen orientation.
52
- *
53
- * # Error codes
54
- * - `ERR_SCREEN_ORIENTATION_GET_ORIENTATION_LOCK` - __Android Only.__ An unknown error occurred
55
- * when trying to get the system lock.
56
- * - `ERR_SCREEN_ORIENTATION_MISSING_ACTIVITY` - __Android Only.__ Could not get the current activity.
57
34
  */
58
35
  export declare function getOrientationAsync(): Promise<Orientation>;
59
36
  /**
60
37
  * Gets the current screen orientation lock type.
61
38
  * @return Returns a promise which fulfils with an [`OrientationLock`](#orientationlock)
62
39
  * value.
63
- *
64
- * # Error codes
65
- * - `ERR_SCREEN_ORIENTATION_MISSING_ACTIVITY` - __Android Only.__ Could not get the current activity.
66
40
  */
67
41
  export declare function getOrientationLockAsync(): Promise<OrientationLock>;
68
42
  /**
69
43
  * Gets the platform specific screen orientation lock type.
70
44
  * @return Returns a promise which fulfils with a [`PlatformOrientationInfo`](#platformorientationinfo)
71
45
  * value.
72
- *
73
- * # Error codes
74
- * - `ERR_SCREEN_ORIENTATION_GET_PLATFORM_ORIENTATION_LOCK`
75
- * - `ERR_SCREEN_ORIENTATION_MISSING_ACTIVITY` - __Android Only.__ Could not get the current activity.
76
46
  */
77
47
  export declare function getPlatformOrientationLockAsync(): Promise<PlatformOrientationInfo>;
78
48
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"ScreenOrientation.d.ts","sourceRoot":"","sources":["../src/ScreenOrientation.ts"],"names":[],"mappings":"AAAA,OAAO,EAA0B,YAAY,EAAuB,MAAM,mBAAmB,CAAC;AAG9F,OAAO,EACL,WAAW,EACX,sBAAsB,EACtB,yBAAyB,EACzB,eAAe,EACf,uBAAuB,EACvB,kBAAkB,EAClB,cAAc,EACd,YAAY,EACZ,qBAAqB,EACtB,MAAM,2BAA2B,CAAC;AAEnC,OAAO,EACL,WAAW,EACX,eAAe,EACf,uBAAuB,EACvB,yBAAyB,EACzB,sBAAsB,EACtB,kBAAkB,EAClB,cAAc,EACd,YAAY,EACZ,qBAAqB,EACrB,YAAY,GACb,CAAC;AAQF;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAsB,SAAS,CAAC,eAAe,EAAE,eAAe,GAAG,OAAO,CAAC,IAAI,CAAC,CAgB/E;AAGD;;;;;;;;;;;;;GAaG;AACH,wBAAsB,iBAAiB,CAAC,OAAO,EAAE,uBAAuB,GAAG,OAAO,CAAC,IAAI,CAAC,CA4CvF;AAGD;;;;;;GAMG;AACH,wBAAsB,WAAW,IAAI,OAAO,CAAC,IAAI,CAAC,CAKjD;AAGD;;;;;;;;;GASG;AACH,wBAAsB,mBAAmB,IAAI,OAAO,CAAC,WAAW,CAAC,CAKhE;AAGD;;;;;;;GAOG;AACH,wBAAsB,uBAAuB,IAAI,OAAO,CAAC,eAAe,CAAC,CAKxE;AAGD;;;;;;;;GAQG;AACH,wBAAsB,+BAA+B,IAAI,OAAO,CAAC,uBAAuB,CAAC,CAiBxF;AAGD;;;;;;GAMG;AACH,wBAAsB,4BAA4B,CAChD,eAAe,EAAE,eAAe,GAC/B,OAAO,CAAC,OAAO,CAAC,CAWlB;AAaD;;;;;;;GAOG;AACH,wBAAgB,4BAA4B,CAAC,QAAQ,EAAE,yBAAyB,GAAG,YAAY,CA2B9F;AAMD;;GAEG;AACH,wBAAgB,gCAAgC,IAAI,IAAI,CAUvD;AAGD;;;;;GAKG;AACH,wBAAgB,+BAA+B,CAAC,YAAY,EAAE,YAAY,GAAG,IAAI,CAQhF"}
1
+ {"version":3,"file":"ScreenOrientation.d.ts","sourceRoot":"","sources":["../src/ScreenOrientation.ts"],"names":[],"mappings":"AAAA,OAAO,EAA0B,YAAY,EAAuB,MAAM,mBAAmB,CAAC;AAG9F,OAAO,EACL,WAAW,EACX,sBAAsB,EACtB,yBAAyB,EACzB,eAAe,EACf,uBAAuB,EACvB,kBAAkB,EAClB,cAAc,EACd,YAAY,EACZ,qBAAqB,EACtB,MAAM,2BAA2B,CAAC;AAEnC,OAAO,EACL,WAAW,EACX,eAAe,EACf,uBAAuB,EACvB,yBAAyB,EACzB,sBAAsB,EACtB,kBAAkB,EAClB,cAAc,EACd,YAAY,EACZ,qBAAqB,EACrB,YAAY,GACb,CAAC;AAQF;;;;;;;;;;;;GAYG;AACH,wBAAsB,SAAS,CAAC,eAAe,EAAE,eAAe,GAAG,OAAO,CAAC,IAAI,CAAC,CAgB/E;AAGD;;;;;GAKG;AACH,wBAAsB,iBAAiB,CAAC,OAAO,EAAE,uBAAuB,GAAG,OAAO,CAAC,IAAI,CAAC,CA4CvF;AAGD;;;GAGG;AACH,wBAAsB,WAAW,IAAI,OAAO,CAAC,IAAI,CAAC,CAKjD;AAGD;;;;GAIG;AACH,wBAAsB,mBAAmB,IAAI,OAAO,CAAC,WAAW,CAAC,CAKhE;AAGD;;;;GAIG;AACH,wBAAsB,uBAAuB,IAAI,OAAO,CAAC,eAAe,CAAC,CAKxE;AAGD;;;;GAIG;AACH,wBAAsB,+BAA+B,IAAI,OAAO,CAAC,uBAAuB,CAAC,CAiBxF;AAGD;;;;;;GAMG;AACH,wBAAsB,4BAA4B,CAChD,eAAe,EAAE,eAAe,GAC/B,OAAO,CAAC,OAAO,CAAC,CAWlB;AAaD;;;;;;;GAOG;AACH,wBAAgB,4BAA4B,CAAC,QAAQ,EAAE,yBAAyB,GAAG,YAAY,CA2B9F;AAMD;;GAEG;AACH,wBAAgB,gCAAgC,IAAI,IAAI,CAUvD;AAGD;;;;;GAKG;AACH,wBAAgB,+BAA+B,CAAC,YAAY,EAAE,YAAY,GAAG,IAAI,CAQhF"}
@@ -12,13 +12,6 @@ let _lastOrientationLock = OrientationLock.UNKNOWN;
12
12
  * enum for possible values.
13
13
  * @return Returns a promise with `void` value, which fulfils when the orientation is set.
14
14
  *
15
- * # Error codes
16
- * - `ERR_SCREEN_ORIENTATION_INVALID_ORIENTATION_LOCK` - An invalid [`OrientationLock`](#orientationlock)
17
- * was passed in.
18
- * - `ERR_SCREEN_ORIENTATION_UNSUPPORTED_ORIENTATION_LOCK` - The platform does not support the
19
- * orientation lock policy.
20
- * - `ERR_SCREEN_ORIENTATION_MISSING_ACTIVITY` - __Android Only.__ Could not get the current activity.
21
- *
22
15
  * @example
23
16
  * ```ts
24
17
  * async function changeScreenOrientation() {
@@ -46,14 +39,6 @@ export async function lockAsync(orientationLock) {
46
39
  * object type for the different platform formats.
47
40
  * @return Returns a promise with `void` value, resolving when the orientation is set and rejecting
48
41
  * if an invalid option or value is passed.
49
- *
50
- * # Error codes
51
- * - `ERR_SCREEN_ORIENTATION_INVALID_ORIENTATION_LOCK` - __iOS Only.__ An invalid [`OrientationLock`](#orientationlock)
52
- * was passed in.
53
- * - `ERR_SCREEN_ORIENTATION_UNSUPPORTED_ORIENTATION_LOCK` - The platform does not support the
54
- * orientation lock policy.
55
- * - `ERR_SCREEN_ORIENTATION_MISSING_ACTIVITY` - __Android Only.__ Could not get the current activity.
56
- *
57
42
  */
58
43
  export async function lockPlatformAsync(options) {
59
44
  if (!ExpoScreenOrientation.lockPlatformAsync) {
@@ -96,9 +81,6 @@ export async function lockPlatformAsync(options) {
96
81
  /**
97
82
  * Sets the screen orientation back to the `OrientationLock.DEFAULT` policy.
98
83
  * @return Returns a promise with `void` value, which fulfils when the orientation is set.
99
- *
100
- * # Error codes
101
- * - `ERR_SCREEN_ORIENTATION_MISSING_ACTIVITY` - __Android Only.__ Could not get the current activity.
102
84
  */
103
85
  export async function unlockAsync() {
104
86
  if (!ExpoScreenOrientation.lockAsync) {
@@ -111,11 +93,6 @@ export async function unlockAsync() {
111
93
  * Gets the current screen orientation.
112
94
  * @return Returns a promise that fulfils with an [`Orientation`](#screenorientationorientation)
113
95
  * value that reflects the current screen orientation.
114
- *
115
- * # Error codes
116
- * - `ERR_SCREEN_ORIENTATION_GET_ORIENTATION_LOCK` - __Android Only.__ An unknown error occurred
117
- * when trying to get the system lock.
118
- * - `ERR_SCREEN_ORIENTATION_MISSING_ACTIVITY` - __Android Only.__ Could not get the current activity.
119
96
  */
120
97
  export async function getOrientationAsync() {
121
98
  if (!ExpoScreenOrientation.getOrientationAsync) {
@@ -128,9 +105,6 @@ export async function getOrientationAsync() {
128
105
  * Gets the current screen orientation lock type.
129
106
  * @return Returns a promise which fulfils with an [`OrientationLock`](#orientationlock)
130
107
  * value.
131
- *
132
- * # Error codes
133
- * - `ERR_SCREEN_ORIENTATION_MISSING_ACTIVITY` - __Android Only.__ Could not get the current activity.
134
108
  */
135
109
  export async function getOrientationLockAsync() {
136
110
  if (!ExpoScreenOrientation.getOrientationLockAsync) {
@@ -143,10 +117,6 @@ export async function getOrientationLockAsync() {
143
117
  * Gets the platform specific screen orientation lock type.
144
118
  * @return Returns a promise which fulfils with a [`PlatformOrientationInfo`](#platformorientationinfo)
145
119
  * value.
146
- *
147
- * # Error codes
148
- * - `ERR_SCREEN_ORIENTATION_GET_PLATFORM_ORIENTATION_LOCK`
149
- * - `ERR_SCREEN_ORIENTATION_MISSING_ACTIVITY` - __Android Only.__ Could not get the current activity.
150
120
  */
151
121
  export async function getPlatformOrientationLockAsync() {
152
122
  const platformOrientationLock = await ExpoScreenOrientation.getPlatformOrientationLockAsync();