expo-screen-orientation 6.0.2 → 6.0.4
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 +13 -0
- package/android/build.gradle +2 -2
- package/ios/ScreenOrientationModule.swift +10 -2
- package/ios/ScreenOrientationRegistry.swift +2 -1
- package/ios/ScreenOrientationUtilities.swift +15 -0
- package/ios/ScreenOrientationViewController.swift +41 -8
- package/package.json +2 -2
- package/plugin/build/withScreenOrientation.d.ts +0 -1
- package/plugin/build/withScreenOrientation.js +7 -12
- package/plugin/src/withScreenOrientation.ts +9 -13
package/CHANGELOG.md
CHANGED
|
@@ -10,6 +10,19 @@
|
|
|
10
10
|
|
|
11
11
|
### 💡 Others
|
|
12
12
|
|
|
13
|
+
## 6.0.4 — 2023-07-23
|
|
14
|
+
|
|
15
|
+
### 🐛 Bug fixes
|
|
16
|
+
|
|
17
|
+
- [iOS] Fix event emitter sending events with no registered listeners. ([#23462](https://github.com/expo/expo/pull/23462) by [@behenate](https://github.com/behenate))
|
|
18
|
+
- [iOS] Fix config plugin deleting the orientations key from `Info.plist` when the initial orientation value is set to `DEFAULT`. ([#23637](https://github.com/expo/expo/pull/23637) by [@behenate](https://github.com/behenate))
|
|
19
|
+
|
|
20
|
+
## 6.0.3 — 2023-07-12
|
|
21
|
+
|
|
22
|
+
### 🐛 Bug fixes
|
|
23
|
+
|
|
24
|
+
- [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))
|
|
25
|
+
|
|
13
26
|
## 6.0.2 — 2023-07-04
|
|
14
27
|
|
|
15
28
|
### 💡 Others
|
package/android/build.gradle
CHANGED
|
@@ -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.
|
|
6
|
+
version = '6.0.4'
|
|
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.
|
|
70
|
+
versionName '6.0.4'
|
|
71
71
|
}
|
|
72
72
|
lintOptions {
|
|
73
73
|
abortOnError false
|
|
@@ -4,7 +4,7 @@ public class ScreenOrientationModule: Module, ScreenOrientationController {
|
|
|
4
4
|
static let didUpdateDimensionsEvent = "expoDidUpdateDimensions"
|
|
5
5
|
|
|
6
6
|
let screenOrientationRegistry = ScreenOrientationRegistry.shared
|
|
7
|
-
var
|
|
7
|
+
var shouldEmitEvents = false
|
|
8
8
|
|
|
9
9
|
public func definition() -> ModuleDefinition {
|
|
10
10
|
Name("ExpoScreenOrientation")
|
|
@@ -82,12 +82,20 @@ public class ScreenOrientationModule: Module, ScreenOrientationController {
|
|
|
82
82
|
OnDestroy {
|
|
83
83
|
screenOrientationRegistry.unregisterController(self)
|
|
84
84
|
}
|
|
85
|
+
|
|
86
|
+
OnStartObserving {
|
|
87
|
+
shouldEmitEvents = true
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
OnStopObserving {
|
|
91
|
+
shouldEmitEvents = false
|
|
92
|
+
}
|
|
85
93
|
}
|
|
86
94
|
|
|
87
95
|
// MARK: - ScreenOrientationController
|
|
88
96
|
|
|
89
97
|
public func screenOrientationDidChange(_ orientation: UIInterfaceOrientation) {
|
|
90
|
-
guard let currentTraitCollection = screenOrientationRegistry.currentTraitCollection else {
|
|
98
|
+
guard let currentTraitCollection = screenOrientationRegistry.currentTraitCollection, shouldEmitEvents else {
|
|
91
99
|
return
|
|
92
100
|
}
|
|
93
101
|
|
|
@@ -79,7 +79,8 @@ public class ScreenOrientationRegistry: NSObject, UIApplicationDelegate {
|
|
|
79
79
|
/**
|
|
80
80
|
Rotates the view to currentScreenOrientation or default orientation from the orientationMask.
|
|
81
81
|
*/
|
|
82
|
-
|
|
82
|
+
@objc
|
|
83
|
+
public func enforceDesiredDeviceOrientation(withOrientationMask orientationMask: UIInterfaceOrientationMask) {
|
|
83
84
|
var newOrientation = orientationMask.defaultOrientation()
|
|
84
85
|
|
|
85
86
|
if orientationMask.contains(currentScreenOrientation) {
|
|
@@ -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
|
|
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 = .
|
|
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
|
-
|
|
16
|
-
|
|
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
|
|
22
|
-
self.init(defaultOrientationMask:
|
|
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
|
|
28
|
-
self.init(defaultOrientationMask:
|
|
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.
|
|
3
|
+
"version": "6.0.4",
|
|
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": "
|
|
44
|
+
"gitHead": "c0d646e9295094bca877513e500d3c9f2e990c42"
|
|
45
45
|
}
|
|
@@ -15,7 +15,6 @@ type OrientationMasks = keyof typeof OrientationLock;
|
|
|
15
15
|
interface ExpoConfigWithInitialOrientation extends ExpoConfig {
|
|
16
16
|
initialOrientation?: OrientationMasks;
|
|
17
17
|
}
|
|
18
|
-
export declare function getInitialOrientation(config: Pick<ExpoConfigWithInitialOrientation, 'initialOrientation'>): OrientationMasks;
|
|
19
18
|
export declare function setInitialOrientation(config: Pick<ExpoConfigWithInitialOrientation, 'initialOrientation'>, infoPlist: InfoPlist): InfoPlist;
|
|
20
19
|
declare const _default: ConfigPlugin<void | {
|
|
21
20
|
initialOrientation?: "DEFAULT" | "ALL" | "PORTRAIT" | "PORTRAIT_UP" | "PORTRAIT_DOWN" | "LANDSCAPE" | "LANDSCAPE_LEFT" | "LANDSCAPE_RIGHT" | undefined;
|
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.setInitialOrientation = exports.
|
|
6
|
+
exports.setInitialOrientation = exports.INITIAL_ORIENTATION_KEY = void 0;
|
|
7
7
|
const assert_1 = __importDefault(require("assert"));
|
|
8
8
|
const config_plugins_1 = require("expo/config-plugins");
|
|
9
9
|
const pkg = require('expo-screen-orientation/package.json');
|
|
@@ -19,7 +19,7 @@ const OrientationLock = {
|
|
|
19
19
|
LANDSCAPE_LEFT: 'UIInterfaceOrientationMaskLandscapeLeft',
|
|
20
20
|
LANDSCAPE_RIGHT: 'UIInterfaceOrientationMaskLandscapeRight',
|
|
21
21
|
};
|
|
22
|
-
const withScreenOrientationViewController = (config, { initialOrientation
|
|
22
|
+
const withScreenOrientationViewController = (config, { initialOrientation } = {}) => {
|
|
23
23
|
config = (0, config_plugins_1.withInfoPlist)(config, (config) => {
|
|
24
24
|
const extendedConfig = {
|
|
25
25
|
...config,
|
|
@@ -30,19 +30,14 @@ const withScreenOrientationViewController = (config, { initialOrientation = 'DEF
|
|
|
30
30
|
});
|
|
31
31
|
return config;
|
|
32
32
|
};
|
|
33
|
-
function getInitialOrientation(config) {
|
|
34
|
-
return config.initialOrientation ?? 'DEFAULT';
|
|
35
|
-
}
|
|
36
|
-
exports.getInitialOrientation = getInitialOrientation;
|
|
37
33
|
function setInitialOrientation(config, infoPlist) {
|
|
38
|
-
const initialOrientation =
|
|
39
|
-
|
|
40
|
-
if (initialOrientation === 'DEFAULT') {
|
|
34
|
+
const initialOrientation = config.initialOrientation;
|
|
35
|
+
if (!initialOrientation) {
|
|
41
36
|
delete infoPlist[exports.INITIAL_ORIENTATION_KEY];
|
|
37
|
+
return infoPlist;
|
|
42
38
|
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
}
|
|
39
|
+
(0, assert_1.default)(initialOrientation in OrientationLock, `Invalid initial orientation "${initialOrientation}" expected one of: ${Object.keys(OrientationLock).join(', ')}`);
|
|
40
|
+
infoPlist[exports.INITIAL_ORIENTATION_KEY] = OrientationLock[initialOrientation];
|
|
46
41
|
return infoPlist;
|
|
47
42
|
}
|
|
48
43
|
exports.setInitialOrientation = setInitialOrientation;
|
|
@@ -29,7 +29,7 @@ const withScreenOrientationViewController: ConfigPlugin<
|
|
|
29
29
|
{
|
|
30
30
|
initialOrientation?: keyof typeof OrientationLock;
|
|
31
31
|
} | void
|
|
32
|
-
> = (config, { initialOrientation
|
|
32
|
+
> = (config, { initialOrientation } = {}) => {
|
|
33
33
|
config = withInfoPlist(config, (config) => {
|
|
34
34
|
const extendedConfig = {
|
|
35
35
|
...config,
|
|
@@ -41,17 +41,16 @@ const withScreenOrientationViewController: ConfigPlugin<
|
|
|
41
41
|
return config;
|
|
42
42
|
};
|
|
43
43
|
|
|
44
|
-
export function getInitialOrientation(
|
|
45
|
-
config: Pick<ExpoConfigWithInitialOrientation, 'initialOrientation'>
|
|
46
|
-
): OrientationMasks {
|
|
47
|
-
return config.initialOrientation ?? 'DEFAULT';
|
|
48
|
-
}
|
|
49
|
-
|
|
50
44
|
export function setInitialOrientation(
|
|
51
45
|
config: Pick<ExpoConfigWithInitialOrientation, 'initialOrientation'>,
|
|
52
46
|
infoPlist: InfoPlist
|
|
53
47
|
): InfoPlist {
|
|
54
|
-
const initialOrientation =
|
|
48
|
+
const initialOrientation = config.initialOrientation;
|
|
49
|
+
|
|
50
|
+
if (!initialOrientation) {
|
|
51
|
+
delete infoPlist[INITIAL_ORIENTATION_KEY];
|
|
52
|
+
return infoPlist;
|
|
53
|
+
}
|
|
55
54
|
|
|
56
55
|
assert(
|
|
57
56
|
initialOrientation in OrientationLock,
|
|
@@ -60,11 +59,8 @@ export function setInitialOrientation(
|
|
|
60
59
|
).join(', ')}`
|
|
61
60
|
);
|
|
62
61
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
} else {
|
|
66
|
-
infoPlist[INITIAL_ORIENTATION_KEY] = OrientationLock[initialOrientation];
|
|
67
|
-
}
|
|
62
|
+
infoPlist[INITIAL_ORIENTATION_KEY] = OrientationLock[initialOrientation];
|
|
63
|
+
|
|
68
64
|
return infoPlist;
|
|
69
65
|
}
|
|
70
66
|
|