expo-screen-orientation 6.0.2 → 6.0.3

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/CHANGELOG.md CHANGED
@@ -10,6 +10,12 @@
10
10
 
11
11
  ### 💡 Others
12
12
 
13
+ ## 6.0.3 — 2023-07-12
14
+
15
+ ### 🐛 Bug fixes
16
+
17
+ - [iOS] When config plugin is not configured the initial orientation is now based on values in `Info.plist` instead of being set to portrait. ([#23456](https://github.com/expo/expo/pull/23456) by [@behenate](https://github.com/behenate))
18
+
13
19
  ## 6.0.2 — 2023-07-04
14
20
 
15
21
  ### 💡 Others
@@ -3,7 +3,7 @@ apply plugin: 'kotlin-android'
3
3
  apply plugin: 'maven-publish'
4
4
 
5
5
  group = 'host.exp.exponent'
6
- version = '6.0.2'
6
+ version = '6.0.3'
7
7
 
8
8
  buildscript {
9
9
  def expoModulesCorePlugin = new File(project(":expo-modules-core").projectDir.absolutePath, "ExpoModulesCorePlugin.gradle")
@@ -67,7 +67,7 @@ android {
67
67
  minSdkVersion safeExtGet("minSdkVersion", 21)
68
68
  targetSdkVersion safeExtGet("targetSdkVersion", 33)
69
69
  versionCode 7
70
- versionName '6.0.2'
70
+ versionName '6.0.3'
71
71
  }
72
72
  lintOptions {
73
73
  abortOnError false
@@ -73,6 +73,21 @@ internal func plistStringToInterfaceOrientationMask(_ maskName: String) -> UIInt
73
73
  }
74
74
  }
75
75
 
76
+ internal func orientationStringToInterfaceOrientationMask(_ orientationString: String) -> UIInterfaceOrientationMask? {
77
+ switch orientationString {
78
+ case "UIInterfaceOrientationPortrait":
79
+ return .portrait
80
+ case "UIInterfaceOrientationPortraitUpsideDown":
81
+ return .portraitUpsideDown
82
+ case "UIInterfaceOrientationLandscapeRight":
83
+ return .landscapeRight
84
+ case "UIInterfaceOrientationLandscapeLeft":
85
+ return .landscapeLeft
86
+ default:
87
+ return nil
88
+ }
89
+ }
90
+
76
91
  extension UIInterfaceOrientation {
77
92
  internal func toInterfaceOrientationMask() -> UIInterfaceOrientationMask {
78
93
  return UIInterfaceOrientationMask(rawValue: 1 << self.rawValue)
@@ -1,34 +1,44 @@
1
1
  import ExpoModulesCore
2
2
 
3
- let defaultScreenOrientationMask = "EXDefaultScreenOrientationMask"
3
+ let defaultScreenOrientationMaskKey = "EXDefaultScreenOrientationMask"
4
+ let supportedOrientationsKey = "UISupportedInterfaceOrientations"
5
+ let ipadSupportedOrientationsKey = "UISupportedInterfaceOrientations~ipad"
4
6
 
5
7
  class ScreenOrientationViewController: UIViewController {
6
8
  let screenOrientationRegistry = ScreenOrientationRegistry.shared
7
9
  private var defaultOrientationMask: UIInterfaceOrientationMask
8
10
 
9
- init(defaultOrientationMask: UIInterfaceOrientationMask = .portrait) {
11
+ init(defaultOrientationMask: UIInterfaceOrientationMask = doesDeviceHaveNotch ? .allButUpsideDown : .all) {
10
12
  self.defaultOrientationMask = defaultOrientationMask
11
13
  super.init(nibName: nil, bundle: nil)
12
14
  }
13
15
 
14
16
  convenience init(defaultScreenOrientationFromPlist: Void) {
15
- guard let orientationString = Bundle.main.object(forInfoDictionaryKey: defaultScreenOrientationMask) as? String else {
16
- self.init(defaultOrientationMask: .portrait)
17
+ let supportedInterfaceOrientations = ScreenOrientationViewController.getSupportedInterfaceOrientations()
18
+
19
+ guard let orientationString = Bundle.main.object(forInfoDictionaryKey: defaultScreenOrientationMaskKey) as? String else {
20
+ // If user hasn't defined a default interface orientation using the config plugin use the allowed values from Info.plist as the
21
+ // default orientation. Values in Info.plist are set with the "orientation" key in app.json
22
+ self.init(defaultOrientationMask: supportedInterfaceOrientations)
17
23
  return
18
24
  }
19
25
 
20
26
  guard let mask = plistStringToInterfaceOrientationMask(orientationString) else {
21
- log.warn("Orientation lock string '\(orientationString)' provided in Info.plist does not correspond to a valid orientation mask. Application will default to portrait orientation lock.")
22
- self.init(defaultOrientationMask: .portrait)
27
+ log.warn("Orientation lock string '\(orientationString)' provided in Info.plist does not correspond to a valid orientation mask. Application will default to orientation mask set in \(supportedOrientationsKey).")
28
+ self.init(defaultOrientationMask: supportedInterfaceOrientations)
23
29
  return
24
30
  }
25
31
 
26
32
  guard mask.isSupportedByDevice() else {
27
- log.warn("Orientation lock string '\(orientationString)' provided in Info.plist is not supported by the device. Application will default to portrait orientation lock.")
28
- self.init(defaultOrientationMask: .portrait)
33
+ log.warn("Orientation lock string '\(orientationString)' provided in Info.plist is not supported by the device. Application will default to orientation lock set in \(supportedOrientationsKey).")
34
+ self.init(defaultOrientationMask: supportedInterfaceOrientations)
29
35
  return
30
36
  }
31
37
 
38
+ if mask != mask.intersection(supportedInterfaceOrientations) {
39
+ log.warn("Info.plist: Orientations allowed in `\(supportedOrientationsKey)` are in conflict with the values allowed in `\(defaultScreenOrientationMaskKey)`. Values from `\(defaultScreenOrientationMaskKey)` will be used. When setting the initial orientation using the config plugin delete the `\"orientation\"` key from `app.json`")
40
+ }
41
+
32
42
  self.init(defaultOrientationMask: mask)
33
43
  }
34
44
 
@@ -61,4 +71,27 @@ class ScreenOrientationViewController: UIViewController {
61
71
  }
62
72
  return screenWindowTraitsClass.shouldAskScreensForScreenOrientation?(in: self) ?? false
63
73
  }
74
+
75
+ /**
76
+ * Parses the lists under the key 'UISupportedInterfaceOrientations' in Info.plist into a UIInterfaceOrientation mask. Also checks for ipad specific settings.
77
+ * If no orientation is found all possible orientations will be returned.
78
+ */
79
+ private static func getSupportedInterfaceOrientations() -> UIInterfaceOrientationMask {
80
+ let allPossibleOrientations: UIInterfaceOrientationMask = doesDeviceHaveNotch ? .allButUpsideDown : .all
81
+ let ipadSupportedOrientationStrings = Bundle.main.object(forInfoDictionaryKey: ipadSupportedOrientationsKey) as? [String] ?? []
82
+ let commonSupportedOrientationStrings = Bundle.main.object(forInfoDictionaryKey: supportedOrientationsKey) as? [String] ?? []
83
+ let supportedOrientationStrings = (isPad() && !ipadSupportedOrientationStrings.isEmpty) ?
84
+ ipadSupportedOrientationStrings : commonSupportedOrientationStrings
85
+ var orientationMask: UIInterfaceOrientationMask = []
86
+
87
+ for orientationString in supportedOrientationStrings {
88
+ guard let orientation = orientationStringToInterfaceOrientationMask(orientationString) else {
89
+ log.warn("Info.plist: \(orientationString) is not a valid value for the \(supportedOrientationsKey) key")
90
+ continue
91
+ }
92
+ orientationMask.insert(orientation)
93
+ }
94
+
95
+ return orientationMask.isEmpty ? allPossibleOrientations : orientationMask
96
+ }
64
97
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "expo-screen-orientation",
3
- "version": "6.0.2",
3
+ "version": "6.0.3",
4
4
  "description": "Expo universal module for managing device's screen orientation",
5
5
  "main": "build/ScreenOrientation.js",
6
6
  "types": "build/ScreenOrientation.d.ts",
@@ -41,5 +41,5 @@
41
41
  "peerDependencies": {
42
42
  "expo": "*"
43
43
  },
44
- "gitHead": "cf90d5c30c2a08a6493ebfa8aa3791aa70666759"
44
+ "gitHead": "8fdc53c90c52242a80ea511ee3073d9ab950bc68"
45
45
  }