expo-screen-orientation 4.0.1 → 4.1.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.
package/CHANGELOG.md CHANGED
@@ -10,6 +10,21 @@
10
10
 
11
11
  ### 💡 Others
12
12
 
13
+ ## 4.1.1 — 2021-12-08
14
+
15
+ _This version does not introduce any user-facing changes._
16
+
17
+ ## 4.1.0 — 2021-12-03
18
+
19
+ ### 💡 Others
20
+
21
+ - [plugin] Added SDK 43 tests for new AppDelegate template ([#14763](https://github.com/expo/expo/pull/14763) by [@EvanBacon](https://github.com/EvanBacon))
22
+ - The app delegate subscriber on iOS has been separated from the singleton module to hook into the new implementation of `ExpoAppDelegate`. ([#14867](https://github.com/expo/expo/pull/14867) by [@tsapeta](https://github.com/tsapeta))
23
+
24
+ ### ⚠️ Notices
25
+
26
+ - Extra setup on iOS bare projects is not necessary from the support of `ExpoReactDelegateHandler`. ([#15140](https://github.com/expo/expo/pull/15140) by [@kudo](https://github.com/kudo))
27
+
13
28
  ## 4.0.1 — 2021-10-01
14
29
 
15
30
  _This version does not introduce any user-facing changes._
package/README.md CHANGED
@@ -13,7 +13,7 @@ For managed [managed](https://docs.expo.io/versions/latest/introduction/managed-
13
13
 
14
14
  # Installation in bare React Native projects
15
15
 
16
- For bare React Native projects, you must ensure that you have [installed and configured the `react-native-unimodules` package](https://github.com/expo/expo/tree/master/packages/react-native-unimodules) before continuing.
16
+ For bare React Native projects, you must ensure that you have [installed and configured the `expo` package](https://docs.expo.dev/bare/installing-expo-modules/) before continuing.
17
17
 
18
18
  ### Add the package to your npm dependencies
19
19
 
@@ -23,33 +23,14 @@ npm install expo-screen-orientation
23
23
 
24
24
  ### Configure for iOS
25
25
 
26
- 1. Run `npx pod-install` after installing the npm package.
27
- 2. Open the `AppDelegate.m` of your application.
28
- 3. Make sure your `AppDelegate` extends `UMAppDelegateWrapper` as shown [here](https://gist.github.com/lukmccall/d2b97b2dde0d1aa04a245a369ffdd153).
29
- 4. Import `<EXScreenOrientation/EXScreenOrientationViewController.h>`
30
- 5. In `-application:didFinishLaunchingWithOptions:launchOptions` change default `root view controller` to `EXScreenOrientationViewController`:
26
+ Run `npx pod-install` after installing the npm package.
31
27
 
32
- Replace
28
+ The default [UIInterfaceOrientationMask](https://developer.apple.com/documentation/uikit/uiinterfaceorientationmask?language=objc) mask is `UIInterfaceOrientationMaskPortrait`. You can optionally add `EXDefaultScreenOrientationMask` key in your `Info.plist` to change the default orientation mask, e.g.
33
29
 
34
- ```objc
35
- UIViewController *rootViewController = [UIViewController new];
36
- ```
37
-
38
- with:
39
-
40
- ```objc
41
- UIViewController *rootViewController = [[EXScreenOrientationViewController alloc] init]; // The default screen orientation will be set to `portrait`.
42
- ```
43
-
44
- or if you want to change the default screen orientation, with:
45
-
46
- ```objc
47
- UIViewController *rootViewController = [[EXScreenOrientationViewController alloc] initWithDefaultScreenOrientationMask:UIInterfaceOrientationMaskPortrait]; // through parameter you can specify your default orientation mask.
48
- ```
49
-
50
- For more information about available orientation masks, check out [UIInterfaceOrientationMask](https://developer.apple.com/documentation/uikit/uiinterfaceorientationmask?language=objc)
51
-
52
- > **Note** if you are using a custom view controller, the controller will need to extend the `EXScreenOrientationViewController`.
30
+ ```xml
31
+ <key>EXDefaultScreenOrientationMask</key>
32
+ <string>UIInterfaceOrientationMaskAllButUpsideDown</string>
33
+ ```
53
34
 
54
35
  ### Configure for Android
55
36
 
@@ -3,7 +3,7 @@ apply plugin: 'kotlin-android'
3
3
  apply plugin: 'maven'
4
4
 
5
5
  group = 'host.exp.exponent'
6
- version = '4.0.1'
6
+ version = '4.1.1'
7
7
 
8
8
  buildscript {
9
9
  // Simple helper that allows the root project to override versions declared by this library.
@@ -57,7 +57,7 @@ android {
57
57
  minSdkVersion safeExtGet("minSdkVersion", 21)
58
58
  targetSdkVersion safeExtGet("targetSdkVersion", 30)
59
59
  versionCode 7
60
- versionName '4.0.1'
60
+ versionName '4.1.1'
61
61
  }
62
62
  lintOptions {
63
63
  abortOnError false
@@ -3,12 +3,12 @@ import { Orientation, OrientationChangeEvent, OrientationChangeListener, Orienta
3
3
  export { Orientation, OrientationLock, PlatformOrientationInfo, OrientationChangeListener, OrientationChangeEvent, WebOrientationLock, WebOrientation, SizeClassIOS, ScreenOrientationInfo, Subscription, };
4
4
  /**
5
5
  * Lock the screen orientation to a particular `OrientationLock`.
6
- * @param orientationLock The orientation lock to apply. See the [`OrientationLock`](#screenorientationorientationlock)
6
+ * @param orientationLock The orientation lock to apply. See the [`OrientationLock`](#orientationlock)
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
10
  * # Error codes
11
- * - `ERR_SCREEN_ORIENTATION_INVALID_ORIENTATION_LOCK` - An invalid [`OrientationLock`](#screenorientationorientationlock)
11
+ * - `ERR_SCREEN_ORIENTATION_INVALID_ORIENTATION_LOCK` - An invalid [`OrientationLock`](#orientationlock)
12
12
  * was passed in.
13
13
  * - `ERR_SCREEN_ORIENTATION_UNSUPPORTED_ORIENTATION_LOCK` - The platform does not support the
14
14
  * orientation lock policy.
@@ -23,13 +23,13 @@ export { Orientation, OrientationLock, PlatformOrientationInfo, OrientationChang
23
23
  */
24
24
  export declare function lockAsync(orientationLock: OrientationLock): Promise<void>;
25
25
  /**
26
- * @param options The platform specific lock to apply. See the [`PlatformOrientationInfo`](#screenorientationplatformorientationinfo)
26
+ * @param options The platform specific lock to apply. See the [`PlatformOrientationInfo`](#platformorientationinfo)
27
27
  * object type for the different platform formats.
28
28
  * @return Returns a promise with `void` value, resolving when the orientation is set and rejecting
29
29
  * if an invalid option or value is passed.
30
30
  *
31
31
  * # Error codes
32
- * - `ERR_SCREEN_ORIENTATION_INVALID_ORIENTATION_LOCK` - __iOS Only.__ An invalid [`OrientationLock`](#screenorientationorientationlock)
32
+ * - `ERR_SCREEN_ORIENTATION_INVALID_ORIENTATION_LOCK` - __iOS Only.__ An invalid [`OrientationLock`](#orientationlock)
33
33
  * was passed in.
34
34
  * - `ERR_SCREEN_ORIENTATION_UNSUPPORTED_ORIENTATION_LOCK` - The platform does not support the
35
35
  * orientation lock policy.
@@ -58,7 +58,7 @@ export declare function unlockAsync(): Promise<void>;
58
58
  export declare function getOrientationAsync(): Promise<Orientation>;
59
59
  /**
60
60
  * Gets the current screen orientation lock type.
61
- * @return Returns a promise which fulfils with an [`OrientationLock`](#screenorientationorientationlock)
61
+ * @return Returns a promise which fulfils with an [`OrientationLock`](#orientationlock)
62
62
  * value.
63
63
  *
64
64
  * # Error codes
@@ -67,7 +67,7 @@ export declare function getOrientationAsync(): Promise<Orientation>;
67
67
  export declare function getOrientationLockAsync(): Promise<OrientationLock>;
68
68
  /**
69
69
  * Gets the platform specific screen orientation lock type.
70
- * @return Returns a promise which fulfils with a [`PlatformOrientationInfo`](#screenorientationplatformorientationinfo)
70
+ * @return Returns a promise which fulfils with a [`PlatformOrientationInfo`](#platformorientationinfo)
71
71
  * value.
72
72
  *
73
73
  * # Error codes
@@ -76,7 +76,7 @@ export declare function getOrientationLockAsync(): Promise<OrientationLock>;
76
76
  */
77
77
  export declare function getPlatformOrientationLockAsync(): Promise<PlatformOrientationInfo>;
78
78
  /**
79
- * Returns whether the [`OrientationLock`](#screenorientationorientationlock) policy is supported on
79
+ * Returns whether the [`OrientationLock`](#orientationlock) policy is supported on
80
80
  * the device.
81
81
  * @param orientationLock
82
82
  * @return Returns a promise that resolves to a `boolean` value that reflects whether or not the
@@ -88,7 +88,7 @@ export declare function supportsOrientationLockAsync(orientationLock: Orientatio
88
88
  * or from `landscape` to `portrait`. For example, it won't be invoked when screen orientation
89
89
  * change from `portrait up` to `portrait down`, but it will be called when there was a change from
90
90
  * `portrait up` to `landscape left`.
91
- * @param listener Each orientation update will pass an object with the new [`OrientationChangeEvent`](#screenorientationorientationchangeevent)
91
+ * @param listener Each orientation update will pass an object with the new [`OrientationChangeEvent`](#orientationchangeevent)
92
92
  * to the listener.
93
93
  */
94
94
  export declare function addOrientationChangeListener(listener: OrientationChangeListener): Subscription;
@@ -8,12 +8,12 @@ let _lastOrientationLock = OrientationLock.UNKNOWN;
8
8
  // @needsAudit
9
9
  /**
10
10
  * Lock the screen orientation to a particular `OrientationLock`.
11
- * @param orientationLock The orientation lock to apply. See the [`OrientationLock`](#screenorientationorientationlock)
11
+ * @param orientationLock The orientation lock to apply. See the [`OrientationLock`](#orientationlock)
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
15
  * # Error codes
16
- * - `ERR_SCREEN_ORIENTATION_INVALID_ORIENTATION_LOCK` - An invalid [`OrientationLock`](#screenorientationorientationlock)
16
+ * - `ERR_SCREEN_ORIENTATION_INVALID_ORIENTATION_LOCK` - An invalid [`OrientationLock`](#orientationlock)
17
17
  * was passed in.
18
18
  * - `ERR_SCREEN_ORIENTATION_UNSUPPORTED_ORIENTATION_LOCK` - The platform does not support the
19
19
  * orientation lock policy.
@@ -42,13 +42,13 @@ export async function lockAsync(orientationLock) {
42
42
  }
43
43
  // @needsAudit @docsMissing
44
44
  /**
45
- * @param options The platform specific lock to apply. See the [`PlatformOrientationInfo`](#screenorientationplatformorientationinfo)
45
+ * @param options The platform specific lock to apply. See the [`PlatformOrientationInfo`](#platformorientationinfo)
46
46
  * object type for the different platform formats.
47
47
  * @return Returns a promise with `void` value, resolving when the orientation is set and rejecting
48
48
  * if an invalid option or value is passed.
49
49
  *
50
50
  * # Error codes
51
- * - `ERR_SCREEN_ORIENTATION_INVALID_ORIENTATION_LOCK` - __iOS Only.__ An invalid [`OrientationLock`](#screenorientationorientationlock)
51
+ * - `ERR_SCREEN_ORIENTATION_INVALID_ORIENTATION_LOCK` - __iOS Only.__ An invalid [`OrientationLock`](#orientationlock)
52
52
  * was passed in.
53
53
  * - `ERR_SCREEN_ORIENTATION_UNSUPPORTED_ORIENTATION_LOCK` - The platform does not support the
54
54
  * orientation lock policy.
@@ -126,7 +126,7 @@ export async function getOrientationAsync() {
126
126
  // @needsAudit
127
127
  /**
128
128
  * Gets the current screen orientation lock type.
129
- * @return Returns a promise which fulfils with an [`OrientationLock`](#screenorientationorientationlock)
129
+ * @return Returns a promise which fulfils with an [`OrientationLock`](#orientationlock)
130
130
  * value.
131
131
  *
132
132
  * # Error codes
@@ -141,7 +141,7 @@ export async function getOrientationLockAsync() {
141
141
  // @needsAudit
142
142
  /**
143
143
  * Gets the platform specific screen orientation lock type.
144
- * @return Returns a promise which fulfils with a [`PlatformOrientationInfo`](#screenorientationplatformorientationinfo)
144
+ * @return Returns a promise which fulfils with a [`PlatformOrientationInfo`](#platformorientationinfo)
145
145
  * value.
146
146
  *
147
147
  * # Error codes
@@ -171,7 +171,7 @@ export async function getPlatformOrientationLockAsync() {
171
171
  }
172
172
  // @needsAudit @docsMissing
173
173
  /**
174
- * Returns whether the [`OrientationLock`](#screenorientationorientationlock) policy is supported on
174
+ * Returns whether the [`OrientationLock`](#orientationlock) policy is supported on
175
175
  * the device.
176
176
  * @param orientationLock
177
177
  * @return Returns a promise that resolves to a `boolean` value that reflects whether or not the
@@ -202,7 +202,7 @@ function getEventName() {
202
202
  * or from `landscape` to `portrait`. For example, it won't be invoked when screen orientation
203
203
  * change from `portrait up` to `portrait down`, but it will be called when there was a change from
204
204
  * `portrait up` to `landscape left`.
205
- * @param listener Each orientation update will pass an object with the new [`OrientationChangeEvent`](#screenorientationorientationchangeevent)
205
+ * @param listener Each orientation update will pass an object with the new [`OrientationChangeEvent`](#orientationchangeevent)
206
206
  * to the listener.
207
207
  */
208
208
  export function addOrientationChangeListener(listener) {
@@ -1 +1 @@
1
- {"version":3,"file":"ScreenOrientation.js","sourceRoot":"","sources":["../src/ScreenOrientation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAgB,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAE9F,OAAO,qBAAqB,MAAM,yBAAyB,CAAC;AAC5D,OAAO,EACL,WAAW,EAGX,eAAe,EAEf,kB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YAChB,CAAC,eAAe,EAAE,WAAW,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC;gBACjD,uBAAuB,EAAE;gBACzB,mBAAmB,EAAE;aACtB,CAAC,CAAC;YACH,eAAe,GAAG,EAAE,WAAW,EAAE,CAAC;SACnC;QACD,QAAQ,CAAC,EAAE,eAAe,EAAE,eAAe,EAAE,CAAC,CAAC;IACjD,CAAC,CACF,CAAC;IACF,6BAA6B,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;IACjD,OAAO,YAAY,CAAC;AACtB,CAAC;AAED,6FAA6F;AAC7F,4FAA4F;AAC5F,wEAAwE;AACxE,cAAc;AACd;;GAEG;AACH,MAAM,UAAU,gCAAgC;IAC9C,kIAAkI;IAClI,IAAI,CAAC,GAAG,6BAA6B,CAAC,MAAM,CAAC;IAC7C,OAAO,CAAC,EAAE,EAAE;QACV,MAAM,UAAU,GAAG,6BAA6B,CAAC,CAAC,CAAC,CAAC;QACpD,UAAU,CAAC,MAAM,EAAE,CAAC;QAEpB,wCAAwC;QACxC,6BAA6B,CAAC,GAAG,EAAE,CAAC;KACrC;AACH,CAAC;AAED,cAAc;AACd;;;;;GAKG;AACH,MAAM,UAAU,+BAA+B,CAAC,YAA0B;IACxE,IAAI,CAAC,YAAY,IAAI,CAAC,YAAY,CAAC,MAAM,EAAE;QACzC,MAAM,IAAI,SAAS,CAAC,mCAAmC,CAAC,CAAC;KAC1D;IACD,YAAY,CAAC,MAAM,EAAE,CAAC;IACtB,6BAA6B,GAAG,6BAA6B,CAAC,MAAM,CAClE,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,KAAK,YAAY,CAC9B,CAAC;AACJ,CAAC","sourcesContent":["import { EventEmitter, Platform, Subscription, UnavailabilityError } from 'expo-modules-core';\n\nimport ExpoScreenOrientation from './ExpoScreenOrientation';\nimport {\n Orientation,\n OrientationChangeEvent,\n OrientationChangeListener,\n OrientationLock,\n PlatformOrientationInfo,\n WebOrientationLock,\n WebOrientation,\n SizeClassIOS,\n ScreenOrientationInfo,\n} from './ScreenOrientation.types';\n\nexport {\n Orientation,\n OrientationLock,\n PlatformOrientationInfo,\n OrientationChangeListener,\n OrientationChangeEvent,\n WebOrientationLock,\n WebOrientation,\n SizeClassIOS,\n ScreenOrientationInfo,\n Subscription,\n};\n\nconst _orientationChangeEmitter = new EventEmitter(ExpoScreenOrientation);\nlet _orientationChangeSubscribers: Subscription[] = [];\n\nlet _lastOrientationLock: OrientationLock = OrientationLock.UNKNOWN;\n\n// @needsAudit\n/**\n * Lock the screen orientation to a particular `OrientationLock`.\n * @param orientationLock The orientation lock to apply. See the [`OrientationLock`](#screenorientationorientationlock)\n * enum for possible values.\n * @return Returns a promise with `void` value, which fulfils when the orientation is set.\n *\n * # Error codes\n * - `ERR_SCREEN_ORIENTATION_INVALID_ORIENTATION_LOCK` - An invalid [`OrientationLock`](#screenorientationorientationlock)\n * was passed in.\n * - `ERR_SCREEN_ORIENTATION_UNSUPPORTED_ORIENTATION_LOCK` - The platform does not support the\n * orientation lock policy.\n * - `ERR_SCREEN_ORIENTATION_MISSING_ACTIVITY` - __Android Only.__ Could not get the current activity.\n *\n * @example\n * ```ts\n * async function changeScreenOrientation() {\n * await ScreenOrientation.lockAsync(ScreenOrientation.OrientationLock.LANDSCAPE_LEFT);\n * }\n * ```\n */\nexport async function lockAsync(orientationLock: OrientationLock): Promise<void> {\n if (!ExpoScreenOrientation.lockAsync) {\n throw new UnavailabilityError('ScreenOrientation', 'lockAsync');\n }\n\n const orientationLocks = Object.values(OrientationLock);\n if (!orientationLocks.includes(orientationLock)) {\n throw new TypeError(`Invalid Orientation Lock: ${orientationLock}`);\n }\n\n if (orientationLock === OrientationLock.OTHER) {\n return;\n }\n\n await ExpoScreenOrientation.lockAsync(orientationLock);\n _lastOrientationLock = orientationLock;\n}\n\n// @needsAudit @docsMissing\n/**\n * @param options The platform specific lock to apply. See the [`PlatformOrientationInfo`](#screenorientationplatformorientationinfo)\n * object type for the different platform formats.\n * @return Returns a promise with `void` value, resolving when the orientation is set and rejecting\n * if an invalid option or value is passed.\n *\n * # Error codes\n * - `ERR_SCREEN_ORIENTATION_INVALID_ORIENTATION_LOCK` - __iOS Only.__ An invalid [`OrientationLock`](#screenorientationorientationlock)\n * was passed in.\n * - `ERR_SCREEN_ORIENTATION_UNSUPPORTED_ORIENTATION_LOCK` - The platform does not support the\n * orientation lock policy.\n * - `ERR_SCREEN_ORIENTATION_MISSING_ACTIVITY` - __Android Only.__ Could not get the current activity.\n *\n */\nexport async function lockPlatformAsync(options: PlatformOrientationInfo): Promise<void> {\n if (!ExpoScreenOrientation.lockPlatformAsync) {\n throw new UnavailabilityError('ScreenOrientation', 'lockPlatformAsync');\n }\n\n const { screenOrientationConstantAndroid, screenOrientationArrayIOS, screenOrientationLockWeb } =\n options;\n let platformOrientationParam: any;\n if (Platform.OS === 'android' && screenOrientationConstantAndroid) {\n if (isNaN(screenOrientationConstantAndroid)) {\n throw new TypeError(\n `lockPlatformAsync Android platform: screenOrientationConstantAndroid cannot be called with ${screenOrientationConstantAndroid}`\n );\n }\n platformOrientationParam = screenOrientationConstantAndroid;\n } else if (Platform.OS === 'ios' && screenOrientationArrayIOS) {\n if (!Array.isArray(screenOrientationArrayIOS)) {\n throw new TypeError(\n `lockPlatformAsync iOS platform: screenOrientationArrayIOS cannot be called with ${screenOrientationArrayIOS}`\n );\n }\n\n const orientations = Object.values(Orientation);\n for (const orientation of screenOrientationArrayIOS) {\n if (!orientations.includes(orientation)) {\n throw new TypeError(\n `lockPlatformAsync iOS platform: ${orientation} is not a valid Orientation`\n );\n }\n }\n platformOrientationParam = screenOrientationArrayIOS;\n } else if (Platform.OS === 'web' && screenOrientationLockWeb) {\n const webOrientationLocks = Object.values(WebOrientationLock);\n if (!webOrientationLocks.includes(screenOrientationLockWeb)) {\n throw new TypeError(`Invalid Web Orientation Lock: ${screenOrientationLockWeb}`);\n }\n platformOrientationParam = screenOrientationLockWeb;\n }\n\n if (!platformOrientationParam) {\n throw new TypeError('lockPlatformAsync cannot be called with undefined option properties');\n }\n await ExpoScreenOrientation.lockPlatformAsync(platformOrientationParam);\n _lastOrientationLock = OrientationLock.OTHER;\n}\n\n// @needsAudit\n/**\n * Sets the screen orientation back to the `OrientationLock.DEFAULT` policy.\n * @return Returns a promise with `void` value, which fulfils when the orientation is set.\n *\n * # Error codes\n * - `ERR_SCREEN_ORIENTATION_MISSING_ACTIVITY` - __Android Only.__ Could not get the current activity.\n */\nexport async function unlockAsync(): Promise<void> {\n if (!ExpoScreenOrientation.lockAsync) {\n throw new UnavailabilityError('ScreenOrientation', 'lockAsync');\n }\n await ExpoScreenOrientation.lockAsync(OrientationLock.DEFAULT);\n}\n\n// @needsAudit\n/**\n * Gets the current screen orientation.\n * @return Returns a promise that fulfils with an [`Orientation`](#screenorientationorientation)\n * value that reflects the current screen orientation.\n *\n * # Error codes\n * - `ERR_SCREEN_ORIENTATION_GET_ORIENTATION_LOCK` - __Android Only.__ An unknown error occurred\n * when trying to get the system lock.\n * - `ERR_SCREEN_ORIENTATION_MISSING_ACTIVITY` - __Android Only.__ Could not get the current activity.\n */\nexport async function getOrientationAsync(): Promise<Orientation> {\n if (!ExpoScreenOrientation.getOrientationAsync) {\n throw new UnavailabilityError('ScreenOrientation', 'getOrientationAsync');\n }\n return await ExpoScreenOrientation.getOrientationAsync();\n}\n\n// @needsAudit\n/**\n * Gets the current screen orientation lock type.\n * @return Returns a promise which fulfils with an [`OrientationLock`](#screenorientationorientationlock)\n * value.\n *\n * # Error codes\n * - `ERR_SCREEN_ORIENTATION_MISSING_ACTIVITY` - __Android Only.__ Could not get the current activity.\n */\nexport async function getOrientationLockAsync(): Promise<OrientationLock> {\n if (!ExpoScreenOrientation.getOrientationLockAsync) {\n return _lastOrientationLock;\n }\n return await ExpoScreenOrientation.getOrientationLockAsync();\n}\n\n// @needsAudit\n/**\n * Gets the platform specific screen orientation lock type.\n * @return Returns a promise which fulfils with a [`PlatformOrientationInfo`](#screenorientationplatformorientationinfo)\n * value.\n *\n * # Error codes\n * - `ERR_SCREEN_ORIENTATION_GET_PLATFORM_ORIENTATION_LOCK`\n * - `ERR_SCREEN_ORIENTATION_MISSING_ACTIVITY` - __Android Only.__ Could not get the current activity.\n */\nexport async function getPlatformOrientationLockAsync(): Promise<PlatformOrientationInfo> {\n const platformOrientationLock = await ExpoScreenOrientation.getPlatformOrientationLockAsync();\n if (Platform.OS === 'android') {\n return {\n screenOrientationConstantAndroid: platformOrientationLock,\n };\n } else if (Platform.OS === 'ios') {\n return {\n screenOrientationArrayIOS: platformOrientationLock,\n };\n } else if (Platform.OS === 'web') {\n return {\n screenOrientationLockWeb: platformOrientationLock,\n };\n } else {\n return {};\n }\n}\n\n// @needsAudit @docsMissing\n/**\n * Returns whether the [`OrientationLock`](#screenorientationorientationlock) policy is supported on\n * the device.\n * @param orientationLock\n * @return Returns a promise that resolves to a `boolean` value that reflects whether or not the\n * orientationLock is supported.\n */\nexport async function supportsOrientationLockAsync(\n orientationLock: OrientationLock\n): Promise<boolean> {\n if (!ExpoScreenOrientation.supportsOrientationLockAsync) {\n throw new UnavailabilityError('ScreenOrientation', 'supportsOrientationLockAsync');\n }\n\n const orientationLocks = Object.values(OrientationLock);\n if (!orientationLocks.includes(orientationLock)) {\n throw new TypeError(`Invalid Orientation Lock: ${orientationLock}`);\n }\n\n return await ExpoScreenOrientation.supportsOrientationLockAsync(orientationLock);\n}\n\n// Determine the event name lazily so Jest can set up mocks in advance\nfunction getEventName(): string {\n return Platform.OS === 'ios' || Platform.OS === 'web'\n ? 'expoDidUpdateDimensions'\n : 'didUpdateDimensions';\n}\n\n// We rely on RN to emit `didUpdateDimensions`\n// If this method no longer works, it's possible that the underlying RN implementation has changed\n// see https://github.com/facebook/react-native/blob/c31f79fe478b882540d7fd31ee37b53ddbd60a17/ReactAndroid/src/main/java/com/facebook/react/modules/deviceinfo/DeviceInfoModule.java#L90\n// @needsAudit\n/**\n * Invokes the `listener` function when the screen orientation changes from `portrait` to `landscape`\n * or from `landscape` to `portrait`. For example, it won't be invoked when screen orientation\n * change from `portrait up` to `portrait down`, but it will be called when there was a change from\n * `portrait up` to `landscape left`.\n * @param listener Each orientation update will pass an object with the new [`OrientationChangeEvent`](#screenorientationorientationchangeevent)\n * to the listener.\n */\nexport function addOrientationChangeListener(listener: OrientationChangeListener): Subscription {\n if (typeof listener !== 'function') {\n throw new TypeError(`addOrientationChangeListener cannot be called with ${listener}`);\n }\n const subscription = _orientationChangeEmitter.addListener(\n getEventName(),\n async (update: OrientationChangeEvent) => {\n let orientationInfo, orientationLock;\n if (Platform.OS === 'ios' || Platform.OS === 'web') {\n // For iOS, RN relies on statusBarOrientation (deprecated) to emit `didUpdateDimensions`\n // event, so we emit our own `expoDidUpdateDimensions` event instead\n orientationLock = update.orientationLock;\n orientationInfo = update.orientationInfo;\n } else {\n // We rely on the RN Dimensions to emit the `didUpdateDimensions` event on Android\n let orientation;\n [orientationLock, orientation] = await Promise.all([\n getOrientationLockAsync(),\n getOrientationAsync(),\n ]);\n orientationInfo = { orientation };\n }\n listener({ orientationInfo, orientationLock });\n }\n );\n _orientationChangeSubscribers.push(subscription);\n return subscription;\n}\n\n// We need to keep track of our own subscribers because EventEmitter uses a shared subscriber\n// from NativeEventEmitter that is registered to the same eventTypes as us. Directly calling\n// removeAllListeners(eventName) will remove other module's subscribers.\n// @needsAudit\n/**\n * Removes all listeners subscribed to orientation change updates.\n */\nexport function removeOrientationChangeListeners(): void {\n // Remove listener by subscription instead of eventType to avoid clobbering Dimension module's subscription of didUpdateDimensions\n let i = _orientationChangeSubscribers.length;\n while (i--) {\n const subscriber = _orientationChangeSubscribers[i];\n subscriber.remove();\n\n // remove after a successful unsubscribe\n _orientationChangeSubscribers.pop();\n }\n}\n\n// @needsAudit\n/**\n * Unsubscribes the listener associated with the `Subscription` object from all orientation change\n * updates.\n * @param subscription A subscription object that manages the updates passed to a listener function\n * on an orientation change.\n */\nexport function removeOrientationChangeListener(subscription: Subscription): void {\n if (!subscription || !subscription.remove) {\n throw new TypeError(`Must pass in a valid subscription`);\n }\n subscription.remove();\n _orientationChangeSubscribers = _orientationChangeSubscribers.filter(\n (sub) => sub !== subscription\n );\n}\n"]}
1
+ {"version":3,"file":"ScreenOrientation.js","sourceRoot":"","sources":["../src/ScreenOrientation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAgB,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAE9F,OAAO,qBAAqB,MAAM,yBAAyB,CAAC;AAC5D,OAAO,EACL,WAAW,EAGX,eAAe,EAEf,kBAAkB,EAClB,cAAc,EACd,YAAY,GAEb,MAAM,2BAA2B,CAAC;AAEnC,OAAO,EACL,WAAW,EACX,eAAe,EAIf,kBAAkB,EAClB,cAAc,EACd,YAAY,GAGb,CAAC;AAEF,MAAM,yBAAyB,GAAG,IAAI,YAAY,CAAC,qBAAqB,CAAC,CAAC;AAC1E,IAAI,6BAA6B,GAAmB,EAAE,CAAC;AAEvD,IAAI,oBAAoB,GAAoB,eAAe,CAAC,OAAO,CAAC;AAEpE,cAAc;AACd;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,CAAC,KAAK,UAAU,SAAS,CAAC,eAAgC;IAC9D,IAAI,CAAC,qBAAqB,CAAC,SAAS,EAAE;QACpC,MAAM,IAAI,mBAAmB,CAAC,mBAAmB,EAAE,WAAW,CAAC,CAAC;KACjE;IAED,MAAM,gBAAgB,GAAG,MAAM,CAAC,MAAM,CAAC,eAAe,CAAC,CAAC;IACxD,IAAI,CAAC,gBAAgB,CAAC,QAAQ,CAAC,eAAe,CAAC,EAAE;QAC/C,MAAM,IAAI,SAAS,CAAC,6BAA6B,eAAe,EAAE,CAAC,CAAC;KACrE;IAED,IAAI,eAAe,KAAK,eAAe,CAAC,KAAK,EAAE;QAC7C,OAAO;KACR;IAED,MAAM,qBAAqB,CAAC,SAAS,CAAC,eAAe,CAAC,CAAC;IACvD,oBAAoB,GAAG,eAAe,CAAC;AACzC,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C,CAAC;KAC1D;IACD,YAAY,CAAC,MAAM,EAAE,CAAC;IACtB,6BAA6B,GAAG,6BAA6B,CAAC,MAAM,CAClE,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,KAAK,YAAY,CAC9B,CAAC;AACJ,CAAC","sourcesContent":["import { EventEmitter, Platform, Subscription, UnavailabilityError } from 'expo-modules-core';\n\nimport ExpoScreenOrientation from './ExpoScreenOrientation';\nimport {\n Orientation,\n OrientationChangeEvent,\n OrientationChangeListener,\n OrientationLock,\n PlatformOrientationInfo,\n WebOrientationLock,\n WebOrientation,\n SizeClassIOS,\n ScreenOrientationInfo,\n} from './ScreenOrientation.types';\n\nexport {\n Orientation,\n OrientationLock,\n PlatformOrientationInfo,\n OrientationChangeListener,\n OrientationChangeEvent,\n WebOrientationLock,\n WebOrientation,\n SizeClassIOS,\n ScreenOrientationInfo,\n Subscription,\n};\n\nconst _orientationChangeEmitter = new EventEmitter(ExpoScreenOrientation);\nlet _orientationChangeSubscribers: Subscription[] = [];\n\nlet _lastOrientationLock: OrientationLock = OrientationLock.UNKNOWN;\n\n// @needsAudit\n/**\n * Lock the screen orientation to a particular `OrientationLock`.\n * @param orientationLock The orientation lock to apply. See the [`OrientationLock`](#orientationlock)\n * enum for possible values.\n * @return Returns a promise with `void` value, which fulfils when the orientation is set.\n *\n * # Error codes\n * - `ERR_SCREEN_ORIENTATION_INVALID_ORIENTATION_LOCK` - An invalid [`OrientationLock`](#orientationlock)\n * was passed in.\n * - `ERR_SCREEN_ORIENTATION_UNSUPPORTED_ORIENTATION_LOCK` - The platform does not support the\n * orientation lock policy.\n * - `ERR_SCREEN_ORIENTATION_MISSING_ACTIVITY` - __Android Only.__ Could not get the current activity.\n *\n * @example\n * ```ts\n * async function changeScreenOrientation() {\n * await ScreenOrientation.lockAsync(ScreenOrientation.OrientationLock.LANDSCAPE_LEFT);\n * }\n * ```\n */\nexport async function lockAsync(orientationLock: OrientationLock): Promise<void> {\n if (!ExpoScreenOrientation.lockAsync) {\n throw new UnavailabilityError('ScreenOrientation', 'lockAsync');\n }\n\n const orientationLocks = Object.values(OrientationLock);\n if (!orientationLocks.includes(orientationLock)) {\n throw new TypeError(`Invalid Orientation Lock: ${orientationLock}`);\n }\n\n if (orientationLock === OrientationLock.OTHER) {\n return;\n }\n\n await ExpoScreenOrientation.lockAsync(orientationLock);\n _lastOrientationLock = orientationLock;\n}\n\n// @needsAudit @docsMissing\n/**\n * @param options The platform specific lock to apply. See the [`PlatformOrientationInfo`](#platformorientationinfo)\n * object type for the different platform formats.\n * @return Returns a promise with `void` value, resolving when the orientation is set and rejecting\n * if an invalid option or value is passed.\n *\n * # Error codes\n * - `ERR_SCREEN_ORIENTATION_INVALID_ORIENTATION_LOCK` - __iOS Only.__ An invalid [`OrientationLock`](#orientationlock)\n * was passed in.\n * - `ERR_SCREEN_ORIENTATION_UNSUPPORTED_ORIENTATION_LOCK` - The platform does not support the\n * orientation lock policy.\n * - `ERR_SCREEN_ORIENTATION_MISSING_ACTIVITY` - __Android Only.__ Could not get the current activity.\n *\n */\nexport async function lockPlatformAsync(options: PlatformOrientationInfo): Promise<void> {\n if (!ExpoScreenOrientation.lockPlatformAsync) {\n throw new UnavailabilityError('ScreenOrientation', 'lockPlatformAsync');\n }\n\n const { screenOrientationConstantAndroid, screenOrientationArrayIOS, screenOrientationLockWeb } =\n options;\n let platformOrientationParam: any;\n if (Platform.OS === 'android' && screenOrientationConstantAndroid) {\n if (isNaN(screenOrientationConstantAndroid)) {\n throw new TypeError(\n `lockPlatformAsync Android platform: screenOrientationConstantAndroid cannot be called with ${screenOrientationConstantAndroid}`\n );\n }\n platformOrientationParam = screenOrientationConstantAndroid;\n } else if (Platform.OS === 'ios' && screenOrientationArrayIOS) {\n if (!Array.isArray(screenOrientationArrayIOS)) {\n throw new TypeError(\n `lockPlatformAsync iOS platform: screenOrientationArrayIOS cannot be called with ${screenOrientationArrayIOS}`\n );\n }\n\n const orientations = Object.values(Orientation);\n for (const orientation of screenOrientationArrayIOS) {\n if (!orientations.includes(orientation)) {\n throw new TypeError(\n `lockPlatformAsync iOS platform: ${orientation} is not a valid Orientation`\n );\n }\n }\n platformOrientationParam = screenOrientationArrayIOS;\n } else if (Platform.OS === 'web' && screenOrientationLockWeb) {\n const webOrientationLocks = Object.values(WebOrientationLock);\n if (!webOrientationLocks.includes(screenOrientationLockWeb)) {\n throw new TypeError(`Invalid Web Orientation Lock: ${screenOrientationLockWeb}`);\n }\n platformOrientationParam = screenOrientationLockWeb;\n }\n\n if (!platformOrientationParam) {\n throw new TypeError('lockPlatformAsync cannot be called with undefined option properties');\n }\n await ExpoScreenOrientation.lockPlatformAsync(platformOrientationParam);\n _lastOrientationLock = OrientationLock.OTHER;\n}\n\n// @needsAudit\n/**\n * Sets the screen orientation back to the `OrientationLock.DEFAULT` policy.\n * @return Returns a promise with `void` value, which fulfils when the orientation is set.\n *\n * # Error codes\n * - `ERR_SCREEN_ORIENTATION_MISSING_ACTIVITY` - __Android Only.__ Could not get the current activity.\n */\nexport async function unlockAsync(): Promise<void> {\n if (!ExpoScreenOrientation.lockAsync) {\n throw new UnavailabilityError('ScreenOrientation', 'lockAsync');\n }\n await ExpoScreenOrientation.lockAsync(OrientationLock.DEFAULT);\n}\n\n// @needsAudit\n/**\n * Gets the current screen orientation.\n * @return Returns a promise that fulfils with an [`Orientation`](#screenorientationorientation)\n * value that reflects the current screen orientation.\n *\n * # Error codes\n * - `ERR_SCREEN_ORIENTATION_GET_ORIENTATION_LOCK` - __Android Only.__ An unknown error occurred\n * when trying to get the system lock.\n * - `ERR_SCREEN_ORIENTATION_MISSING_ACTIVITY` - __Android Only.__ Could not get the current activity.\n */\nexport async function getOrientationAsync(): Promise<Orientation> {\n if (!ExpoScreenOrientation.getOrientationAsync) {\n throw new UnavailabilityError('ScreenOrientation', 'getOrientationAsync');\n }\n return await ExpoScreenOrientation.getOrientationAsync();\n}\n\n// @needsAudit\n/**\n * Gets the current screen orientation lock type.\n * @return Returns a promise which fulfils with an [`OrientationLock`](#orientationlock)\n * value.\n *\n * # Error codes\n * - `ERR_SCREEN_ORIENTATION_MISSING_ACTIVITY` - __Android Only.__ Could not get the current activity.\n */\nexport async function getOrientationLockAsync(): Promise<OrientationLock> {\n if (!ExpoScreenOrientation.getOrientationLockAsync) {\n return _lastOrientationLock;\n }\n return await ExpoScreenOrientation.getOrientationLockAsync();\n}\n\n// @needsAudit\n/**\n * Gets the platform specific screen orientation lock type.\n * @return Returns a promise which fulfils with a [`PlatformOrientationInfo`](#platformorientationinfo)\n * value.\n *\n * # Error codes\n * - `ERR_SCREEN_ORIENTATION_GET_PLATFORM_ORIENTATION_LOCK`\n * - `ERR_SCREEN_ORIENTATION_MISSING_ACTIVITY` - __Android Only.__ Could not get the current activity.\n */\nexport async function getPlatformOrientationLockAsync(): Promise<PlatformOrientationInfo> {\n const platformOrientationLock = await ExpoScreenOrientation.getPlatformOrientationLockAsync();\n if (Platform.OS === 'android') {\n return {\n screenOrientationConstantAndroid: platformOrientationLock,\n };\n } else if (Platform.OS === 'ios') {\n return {\n screenOrientationArrayIOS: platformOrientationLock,\n };\n } else if (Platform.OS === 'web') {\n return {\n screenOrientationLockWeb: platformOrientationLock,\n };\n } else {\n return {};\n }\n}\n\n// @needsAudit @docsMissing\n/**\n * Returns whether the [`OrientationLock`](#orientationlock) policy is supported on\n * the device.\n * @param orientationLock\n * @return Returns a promise that resolves to a `boolean` value that reflects whether or not the\n * orientationLock is supported.\n */\nexport async function supportsOrientationLockAsync(\n orientationLock: OrientationLock\n): Promise<boolean> {\n if (!ExpoScreenOrientation.supportsOrientationLockAsync) {\n throw new UnavailabilityError('ScreenOrientation', 'supportsOrientationLockAsync');\n }\n\n const orientationLocks = Object.values(OrientationLock);\n if (!orientationLocks.includes(orientationLock)) {\n throw new TypeError(`Invalid Orientation Lock: ${orientationLock}`);\n }\n\n return await ExpoScreenOrientation.supportsOrientationLockAsync(orientationLock);\n}\n\n// Determine the event name lazily so Jest can set up mocks in advance\nfunction getEventName(): string {\n return Platform.OS === 'ios' || Platform.OS === 'web'\n ? 'expoDidUpdateDimensions'\n : 'didUpdateDimensions';\n}\n\n// We rely on RN to emit `didUpdateDimensions`\n// If this method no longer works, it's possible that the underlying RN implementation has changed\n// see https://github.com/facebook/react-native/blob/c31f79fe478b882540d7fd31ee37b53ddbd60a17/ReactAndroid/src/main/java/com/facebook/react/modules/deviceinfo/DeviceInfoModule.java#L90\n// @needsAudit\n/**\n * Invokes the `listener` function when the screen orientation changes from `portrait` to `landscape`\n * or from `landscape` to `portrait`. For example, it won't be invoked when screen orientation\n * change from `portrait up` to `portrait down`, but it will be called when there was a change from\n * `portrait up` to `landscape left`.\n * @param listener Each orientation update will pass an object with the new [`OrientationChangeEvent`](#orientationchangeevent)\n * to the listener.\n */\nexport function addOrientationChangeListener(listener: OrientationChangeListener): Subscription {\n if (typeof listener !== 'function') {\n throw new TypeError(`addOrientationChangeListener cannot be called with ${listener}`);\n }\n const subscription = _orientationChangeEmitter.addListener(\n getEventName(),\n async (update: OrientationChangeEvent) => {\n let orientationInfo, orientationLock;\n if (Platform.OS === 'ios' || Platform.OS === 'web') {\n // For iOS, RN relies on statusBarOrientation (deprecated) to emit `didUpdateDimensions`\n // event, so we emit our own `expoDidUpdateDimensions` event instead\n orientationLock = update.orientationLock;\n orientationInfo = update.orientationInfo;\n } else {\n // We rely on the RN Dimensions to emit the `didUpdateDimensions` event on Android\n let orientation;\n [orientationLock, orientation] = await Promise.all([\n getOrientationLockAsync(),\n getOrientationAsync(),\n ]);\n orientationInfo = { orientation };\n }\n listener({ orientationInfo, orientationLock });\n }\n );\n _orientationChangeSubscribers.push(subscription);\n return subscription;\n}\n\n// We need to keep track of our own subscribers because EventEmitter uses a shared subscriber\n// from NativeEventEmitter that is registered to the same eventTypes as us. Directly calling\n// removeAllListeners(eventName) will remove other module's subscribers.\n// @needsAudit\n/**\n * Removes all listeners subscribed to orientation change updates.\n */\nexport function removeOrientationChangeListeners(): void {\n // Remove listener by subscription instead of eventType to avoid clobbering Dimension module's subscription of didUpdateDimensions\n let i = _orientationChangeSubscribers.length;\n while (i--) {\n const subscriber = _orientationChangeSubscribers[i];\n subscriber.remove();\n\n // remove after a successful unsubscribe\n _orientationChangeSubscribers.pop();\n }\n}\n\n// @needsAudit\n/**\n * Unsubscribes the listener associated with the `Subscription` object from all orientation change\n * updates.\n * @param subscription A subscription object that manages the updates passed to a listener function\n * on an orientation change.\n */\nexport function removeOrientationChangeListener(subscription: Subscription): void {\n if (!subscription || !subscription.remove) {\n throw new TypeError(`Must pass in a valid subscription`);\n }\n subscription.remove();\n _orientationChangeSubscribers = _orientationChangeSubscribers.filter(\n (sub) => sub !== subscription\n );\n}\n"]}
@@ -24,7 +24,7 @@ export declare enum Orientation {
24
24
  * An enum whose values can be passed to the [`lockAsync`](#screenorientationlockasyncorientationlock)
25
25
  * method.
26
26
  * > __Note:__ `OrientationLock.ALL` and `OrientationLock.PORTRAIT` are invalid on devices which
27
- * don't support `OrientationLock.PORTRAIT_DOWN`.
27
+ * > don't support `OrientationLock.PORTRAIT_DOWN`.
28
28
  */
29
29
  export declare enum OrientationLock {
30
30
  /**
@@ -81,7 +81,7 @@ export declare enum SizeClassIOS {
81
81
  /**
82
82
  * An enum representing the lock policies that can be applied on the web platform, modelled after
83
83
  * the [W3C specification](https://w3c.github.io/screen-orientation/#dom-orientationlocktype).
84
- * These values can be applied through the [`lockPlatformAsync`](#screenorientationlockplatformasyncplatforminfo)
84
+ * These values can be applied through the [`lockPlatformAsync`](#screenorientationlockplatformasyncoptions)
85
85
  * method.
86
86
  */
87
87
  export declare enum WebOrientationLock {
@@ -103,17 +103,20 @@ export declare enum WebOrientation {
103
103
  }
104
104
  export declare type PlatformOrientationInfo = {
105
105
  /**
106
- * __Android Only.__ A constant to set using the Android native [API](https://developer.android.com/reference/android/R.attr.html#screenOrientation).
106
+ * A constant to set using the Android native [API](https://developer.android.com/reference/android/R.attr.html#screenOrientation).
107
107
  * For example, in order to set the lock policy to [unspecified](https://developer.android.com/reference/android/content/pm/ActivityInfo.html#SCREEN_ORIENTATION_UNSPECIFIED),
108
108
  * `-1` should be passed in.
109
+ * @platform android
109
110
  */
110
111
  screenOrientationConstantAndroid?: number;
111
112
  /**
112
- * __iOS Only.__ An array of orientations to allow on the iOS platform.
113
+ * An array of orientations to allow on the iOS platform.
114
+ * @platform ios
113
115
  */
114
116
  screenOrientationArrayIOS?: Orientation[];
115
117
  /**
116
- * __Web Only.__ A web orientation lock to apply in the browser.
118
+ * A web orientation lock to apply in the browser.
119
+ * @platform web
117
120
  */
118
121
  screenOrientationLockWeb?: WebOrientationLock;
119
122
  };
@@ -123,13 +126,15 @@ export declare type ScreenOrientationInfo = {
123
126
  */
124
127
  orientation: Orientation;
125
128
  /**
126
- * __iOS Only.__ The [vertical size class](https://developer.apple.com/library/archive/featuredarticles/ViewControllerPGforiPhoneOS/TheAdaptiveModel.html)
129
+ * The [vertical size class](https://developer.apple.com/library/archive/featuredarticles/ViewControllerPGforiPhoneOS/TheAdaptiveModel.html)
127
130
  * of the device.
131
+ * @platform ios
128
132
  */
129
133
  verticalSizeClass?: SizeClassIOS;
130
134
  /**
131
- * __iOS Only.__ The [horizontal size class](https://developer.apple.com/library/archive/featuredarticles/ViewControllerPGforiPhoneOS/TheAdaptiveModel.html)
135
+ * The [horizontal size class](https://developer.apple.com/library/archive/featuredarticles/ViewControllerPGforiPhoneOS/TheAdaptiveModel.html)
132
136
  * of the device.
137
+ * @platform ios
133
138
  */
134
139
  horizontalSizeClass?: SizeClassIOS;
135
140
  };
@@ -27,7 +27,7 @@ export var Orientation;
27
27
  * An enum whose values can be passed to the [`lockAsync`](#screenorientationlockasyncorientationlock)
28
28
  * method.
29
29
  * > __Note:__ `OrientationLock.ALL` and `OrientationLock.PORTRAIT` are invalid on devices which
30
- * don't support `OrientationLock.PORTRAIT_DOWN`.
30
+ * > don't support `OrientationLock.PORTRAIT_DOWN`.
31
31
  */
32
32
  export var OrientationLock;
33
33
  (function (OrientationLock) {
@@ -88,7 +88,7 @@ export var SizeClassIOS;
88
88
  /**
89
89
  * An enum representing the lock policies that can be applied on the web platform, modelled after
90
90
  * the [W3C specification](https://w3c.github.io/screen-orientation/#dom-orientationlocktype).
91
- * These values can be applied through the [`lockPlatformAsync`](#screenorientationlockplatformasyncplatforminfo)
91
+ * These values can be applied through the [`lockPlatformAsync`](#screenorientationlockplatformasyncoptions)
92
92
  * method.
93
93
  */
94
94
  export var WebOrientationLock;
@@ -1 +1 @@
1
- {"version":3,"file":"ScreenOrientation.types.js","sourceRoot":"","sources":["../src/ScreenOrientation.types.ts"],"names":[],"mappings":"AAAA,cAAc;AACd,MAAM,CAAN,IAAY,WAqBX;AArBD,WAAY,WAAW;IACrB;;OAEG;IACH,mDAAW,CAAA;IACX;;OAEG;IACH,2DAAe,CAAA;IACf;;OAEG;IACH,+DAAiB,CAAA;IACjB;;OAEG;IACH,iEAAkB,CAAA;IAClB;;OAEG;IACH,mEAAmB,CAAA;AACrB,CAAC,EArBW,WAAW,KAAX,WAAW,QAqBtB;AAED,cAAc;AACd;;;;;GAKG;AACH,MAAM,CAAN,IAAY,eA0CX;AA1CD,WAAY,eAAe;IACzB;;;OAGG;IACH,2DAAW,CAAA;IACX;;OAEG;IACH,mDAAO,CAAA;IACP;;OAEG;IACH,6DAAY,CAAA;IACZ;;OAEG;IACH,mEAAe,CAAA;IACf;;OAEG;IACH,uEAAiB,CAAA;IACjB;;OAEG;IACH,+DAAa,CAAA;IACb;;OAEG;IACH,yEAAkB,CAAA;IAClB;;OAEG;IACH,2EAAmB,CAAA;IACnB;;OAEG;IACH,uDAAS,CAAA;IACT;;OAEG;IACH,2DAAW,CAAA;AACb,CAAC,EA1CW,eAAe,KAAf,eAAe,QA0C1B;AAED,cAAc;AACd;;;GAGG;AACH,MAAM,CAAN,IAAY,YAIX;AAJD,WAAY,YAAY;IACtB,qDAAW,CAAA;IACX,qDAAW,CAAA;IACX,qDAAW,CAAA;AACb,CAAC,EAJW,YAAY,KAAZ,YAAY,QAIvB;AAED,cAAc;AACd;;;;;GAKG;AACH,MAAM,CAAN,IAAY,kBAUX;AAVD,WAAY,kBAAkB;IAC5B,2DAAqC,CAAA;IACrC,+DAAyC,CAAA;IACzC,2CAAqB,CAAA;IACrB,6DAAuC,CAAA;IACvC,iEAA2C,CAAA;IAC3C,6CAAuB,CAAA;IACvB,iCAAW,CAAA;IACX,yCAAmB,CAAA;IACnB,yCAAmB,CAAA;AACrB,CAAC,EAVW,kBAAkB,KAAlB,kBAAkB,QAU7B;AAED,eAAe;AACf,MAAM,CAAN,IAAY,cAKX;AALD,WAAY,cAAc;IACxB,uDAAqC,CAAA;IACrC,2DAAyC,CAAA;IACzC,yDAAuC,CAAA;IACvC,6DAA2C,CAAA;AAC7C,CAAC,EALW,cAAc,KAAd,cAAc,QAKzB","sourcesContent":["// @needsAudit\nexport enum Orientation {\n /**\n * An unknown screen orientation. For example, the device is flat, perhaps on a table.\n */\n UNKNOWN = 0,\n /**\n * Right-side up portrait interface orientation.\n */\n PORTRAIT_UP = 1,\n /**\n * Upside down portrait interface orientation.\n */\n PORTRAIT_DOWN = 2,\n /**\n * Left landscape interface orientation.\n */\n LANDSCAPE_LEFT = 3,\n /**\n * Right landscape interface orientation.\n */\n LANDSCAPE_RIGHT = 4,\n}\n\n// @needsAudit\n/**\n * An enum whose values can be passed to the [`lockAsync`](#screenorientationlockasyncorientationlock)\n * method.\n * > __Note:__ `OrientationLock.ALL` and `OrientationLock.PORTRAIT` are invalid on devices which\n * don't support `OrientationLock.PORTRAIT_DOWN`.\n */\nexport enum OrientationLock {\n /**\n * The default orientation. On iOS, this will allow all orientations except `Orientation.PORTRAIT_DOWN`.\n * On Android, this lets the system decide the best orientation.\n */\n DEFAULT = 0,\n /**\n * All four possible orientations\n */\n ALL = 1,\n /**\n * Any portrait orientation.\n */\n PORTRAIT = 2,\n /**\n * Right-side up portrait only.\n */\n PORTRAIT_UP = 3,\n /**\n * Upside down portrait only.\n */\n PORTRAIT_DOWN = 4,\n /**\n * Any landscape orientation.\n */\n LANDSCAPE = 5,\n /**\n * Left landscape only.\n */\n LANDSCAPE_LEFT = 6,\n /**\n * Right landscape only.\n */\n LANDSCAPE_RIGHT = 7,\n /**\n * A platform specific orientation. This is not a valid policy that can be applied in [`lockAsync`](#screenorientationlockasyncorientationlock).\n */\n OTHER = 8,\n /**\n * An unknown screen orientation lock. This is not a valid policy that can be applied in [`lockAsync`](#screenorientationlockasyncorientationlock).\n */\n UNKNOWN = 9,\n}\n\n// @needsAudit\n/**\n * Each iOS device has a default set of [size classes](https://developer.apple.com/library/archive/featuredarticles/ViewControllerPGforiPhoneOS/TheAdaptiveModel.html)\n * that you can use as a guide when designing your interface.\n */\nexport enum SizeClassIOS {\n REGULAR = 0,\n COMPACT = 1,\n UNKNOWN = 2,\n}\n\n// @needsAudit\n/**\n * An enum representing the lock policies that can be applied on the web platform, modelled after\n * the [W3C specification](https://w3c.github.io/screen-orientation/#dom-orientationlocktype).\n * These values can be applied through the [`lockPlatformAsync`](#screenorientationlockplatformasyncplatforminfo)\n * method.\n */\nexport enum WebOrientationLock {\n PORTRAIT_PRIMARY = 'portrait-primary',\n PORTRAIT_SECONDARY = 'portrait-secondary',\n PORTRAIT = 'portrait',\n LANDSCAPE_PRIMARY = 'landscape-primary',\n LANDSCAPE_SECONDARY = 'landscape-secondary',\n LANDSCAPE = 'landscape',\n ANY = 'any',\n NATURAL = 'natural',\n UNKNOWN = 'unknown',\n}\n\n// @docsMissing\nexport enum WebOrientation {\n PORTRAIT_PRIMARY = 'portrait-primary',\n PORTRAIT_SECONDARY = 'portrait-secondary',\n LANDSCAPE_PRIMARY = 'landscape-primary',\n LANDSCAPE_SECONDARY = 'landscape-secondary',\n}\n\n// @needsAudit\nexport type PlatformOrientationInfo = {\n /**\n * __Android Only.__ A constant to set using the Android native [API](https://developer.android.com/reference/android/R.attr.html#screenOrientation).\n * For example, in order to set the lock policy to [unspecified](https://developer.android.com/reference/android/content/pm/ActivityInfo.html#SCREEN_ORIENTATION_UNSPECIFIED),\n * `-1` should be passed in.\n */\n screenOrientationConstantAndroid?: number;\n /**\n * __iOS Only.__ An array of orientations to allow on the iOS platform.\n */\n screenOrientationArrayIOS?: Orientation[];\n /**\n * __Web Only.__ A web orientation lock to apply in the browser.\n */\n screenOrientationLockWeb?: WebOrientationLock;\n};\n\n// @needsAudit\nexport type ScreenOrientationInfo = {\n /**\n * The current orientation of the device.\n */\n orientation: Orientation;\n /**\n * __iOS Only.__ The [vertical size class](https://developer.apple.com/library/archive/featuredarticles/ViewControllerPGforiPhoneOS/TheAdaptiveModel.html)\n * of the device.\n */\n verticalSizeClass?: SizeClassIOS;\n /**\n * __iOS Only.__ The [horizontal size class](https://developer.apple.com/library/archive/featuredarticles/ViewControllerPGforiPhoneOS/TheAdaptiveModel.html)\n * of the device.\n */\n horizontalSizeClass?: SizeClassIOS;\n};\n\nexport type OrientationChangeListener = (event: OrientationChangeEvent) => void;\n\n// @needsAudit\nexport type OrientationChangeEvent = {\n /**\n * The current `OrientationLock` of the device.\n */\n orientationLock: OrientationLock;\n /**\n * The current `ScreenOrientationInfo` of the device.\n */\n orientationInfo: ScreenOrientationInfo;\n};\n"]}
1
+ {"version":3,"file":"ScreenOrientation.types.js","sourceRoot":"","sources":["../src/ScreenOrientation.types.ts"],"names":[],"mappings":"AAAA,cAAc;AACd,MAAM,CAAN,IAAY,WAqBX;AArBD,WAAY,WAAW;IACrB;;OAEG;IACH,mDAAW,CAAA;IACX;;OAEG;IACH,2DAAe,CAAA;IACf;;OAEG;IACH,+DAAiB,CAAA;IACjB;;OAEG;IACH,iEAAkB,CAAA;IAClB;;OAEG;IACH,mEAAmB,CAAA;AACrB,CAAC,EArBW,WAAW,KAAX,WAAW,QAqBtB;AAED,cAAc;AACd;;;;;GAKG;AACH,MAAM,CAAN,IAAY,eA0CX;AA1CD,WAAY,eAAe;IACzB;;;OAGG;IACH,2DAAW,CAAA;IACX;;OAEG;IACH,mDAAO,CAAA;IACP;;OAEG;IACH,6DAAY,CAAA;IACZ;;OAEG;IACH,mEAAe,CAAA;IACf;;OAEG;IACH,uEAAiB,CAAA;IACjB;;OAEG;IACH,+DAAa,CAAA;IACb;;OAEG;IACH,yEAAkB,CAAA;IAClB;;OAEG;IACH,2EAAmB,CAAA;IACnB;;OAEG;IACH,uDAAS,CAAA;IACT;;OAEG;IACH,2DAAW,CAAA;AACb,CAAC,EA1CW,eAAe,KAAf,eAAe,QA0C1B;AAED,cAAc;AACd;;;GAGG;AACH,MAAM,CAAN,IAAY,YAIX;AAJD,WAAY,YAAY;IACtB,qDAAW,CAAA;IACX,qDAAW,CAAA;IACX,qDAAW,CAAA;AACb,CAAC,EAJW,YAAY,KAAZ,YAAY,QAIvB;AAED,cAAc;AACd;;;;;GAKG;AACH,MAAM,CAAN,IAAY,kBAUX;AAVD,WAAY,kBAAkB;IAC5B,2DAAqC,CAAA;IACrC,+DAAyC,CAAA;IACzC,2CAAqB,CAAA;IACrB,6DAAuC,CAAA;IACvC,iEAA2C,CAAA;IAC3C,6CAAuB,CAAA;IACvB,iCAAW,CAAA;IACX,yCAAmB,CAAA;IACnB,yCAAmB,CAAA;AACrB,CAAC,EAVW,kBAAkB,KAAlB,kBAAkB,QAU7B;AAED,eAAe;AACf,MAAM,CAAN,IAAY,cAKX;AALD,WAAY,cAAc;IACxB,uDAAqC,CAAA;IACrC,2DAAyC,CAAA;IACzC,yDAAuC,CAAA;IACvC,6DAA2C,CAAA;AAC7C,CAAC,EALW,cAAc,KAAd,cAAc,QAKzB","sourcesContent":["// @needsAudit\nexport enum Orientation {\n /**\n * An unknown screen orientation. For example, the device is flat, perhaps on a table.\n */\n UNKNOWN = 0,\n /**\n * Right-side up portrait interface orientation.\n */\n PORTRAIT_UP = 1,\n /**\n * Upside down portrait interface orientation.\n */\n PORTRAIT_DOWN = 2,\n /**\n * Left landscape interface orientation.\n */\n LANDSCAPE_LEFT = 3,\n /**\n * Right landscape interface orientation.\n */\n LANDSCAPE_RIGHT = 4,\n}\n\n// @needsAudit\n/**\n * An enum whose values can be passed to the [`lockAsync`](#screenorientationlockasyncorientationlock)\n * method.\n * > __Note:__ `OrientationLock.ALL` and `OrientationLock.PORTRAIT` are invalid on devices which\n * > don't support `OrientationLock.PORTRAIT_DOWN`.\n */\nexport enum OrientationLock {\n /**\n * The default orientation. On iOS, this will allow all orientations except `Orientation.PORTRAIT_DOWN`.\n * On Android, this lets the system decide the best orientation.\n */\n DEFAULT = 0,\n /**\n * All four possible orientations\n */\n ALL = 1,\n /**\n * Any portrait orientation.\n */\n PORTRAIT = 2,\n /**\n * Right-side up portrait only.\n */\n PORTRAIT_UP = 3,\n /**\n * Upside down portrait only.\n */\n PORTRAIT_DOWN = 4,\n /**\n * Any landscape orientation.\n */\n LANDSCAPE = 5,\n /**\n * Left landscape only.\n */\n LANDSCAPE_LEFT = 6,\n /**\n * Right landscape only.\n */\n LANDSCAPE_RIGHT = 7,\n /**\n * A platform specific orientation. This is not a valid policy that can be applied in [`lockAsync`](#screenorientationlockasyncorientationlock).\n */\n OTHER = 8,\n /**\n * An unknown screen orientation lock. This is not a valid policy that can be applied in [`lockAsync`](#screenorientationlockasyncorientationlock).\n */\n UNKNOWN = 9,\n}\n\n// @needsAudit\n/**\n * Each iOS device has a default set of [size classes](https://developer.apple.com/library/archive/featuredarticles/ViewControllerPGforiPhoneOS/TheAdaptiveModel.html)\n * that you can use as a guide when designing your interface.\n */\nexport enum SizeClassIOS {\n REGULAR = 0,\n COMPACT = 1,\n UNKNOWN = 2,\n}\n\n// @needsAudit\n/**\n * An enum representing the lock policies that can be applied on the web platform, modelled after\n * the [W3C specification](https://w3c.github.io/screen-orientation/#dom-orientationlocktype).\n * These values can be applied through the [`lockPlatformAsync`](#screenorientationlockplatformasyncoptions)\n * method.\n */\nexport enum WebOrientationLock {\n PORTRAIT_PRIMARY = 'portrait-primary',\n PORTRAIT_SECONDARY = 'portrait-secondary',\n PORTRAIT = 'portrait',\n LANDSCAPE_PRIMARY = 'landscape-primary',\n LANDSCAPE_SECONDARY = 'landscape-secondary',\n LANDSCAPE = 'landscape',\n ANY = 'any',\n NATURAL = 'natural',\n UNKNOWN = 'unknown',\n}\n\n// @docsMissing\nexport enum WebOrientation {\n PORTRAIT_PRIMARY = 'portrait-primary',\n PORTRAIT_SECONDARY = 'portrait-secondary',\n LANDSCAPE_PRIMARY = 'landscape-primary',\n LANDSCAPE_SECONDARY = 'landscape-secondary',\n}\n\n// @needsAudit\nexport type PlatformOrientationInfo = {\n /**\n * A constant to set using the Android native [API](https://developer.android.com/reference/android/R.attr.html#screenOrientation).\n * For example, in order to set the lock policy to [unspecified](https://developer.android.com/reference/android/content/pm/ActivityInfo.html#SCREEN_ORIENTATION_UNSPECIFIED),\n * `-1` should be passed in.\n * @platform android\n */\n screenOrientationConstantAndroid?: number;\n /**\n * An array of orientations to allow on the iOS platform.\n * @platform ios\n */\n screenOrientationArrayIOS?: Orientation[];\n /**\n * A web orientation lock to apply in the browser.\n * @platform web\n */\n screenOrientationLockWeb?: WebOrientationLock;\n};\n\n// @needsAudit\nexport type ScreenOrientationInfo = {\n /**\n * The current orientation of the device.\n */\n orientation: Orientation;\n /**\n * The [vertical size class](https://developer.apple.com/library/archive/featuredarticles/ViewControllerPGforiPhoneOS/TheAdaptiveModel.html)\n * of the device.\n * @platform ios\n */\n verticalSizeClass?: SizeClassIOS;\n /**\n * The [horizontal size class](https://developer.apple.com/library/archive/featuredarticles/ViewControllerPGforiPhoneOS/TheAdaptiveModel.html)\n * of the device.\n * @platform ios\n */\n horizontalSizeClass?: SizeClassIOS;\n};\n\nexport type OrientationChangeListener = (event: OrientationChangeEvent) => void;\n\n// @needsAudit\nexport type OrientationChangeEvent = {\n /**\n * The current `OrientationLock` of the device.\n */\n orientationLock: OrientationLock;\n /**\n * The current `ScreenOrientationInfo` of the device.\n */\n orientationInfo: ScreenOrientationInfo;\n};\n"]}
@@ -0,0 +1,8 @@
1
+ {
2
+ "name": "expo-screen-orientation",
3
+ "platforms": ["ios", "android"],
4
+ "ios": {
5
+ "appDelegateSubscribers": ["ScreenOrientationAppDelegate"],
6
+ "reactDelegateHandlers": ["ScreenOrientationReactDelegateHandler"]
7
+ }
8
+ }
@@ -2,7 +2,7 @@
2
2
 
3
3
  #import <UIKit/UIKit.h>
4
4
  #import <Foundation/Foundation.h>
5
- #import <ExpoModulesCore/EXSingletonModule.h>
5
+ #import <ExpoModulesCore/ExpoModulesCore.h>
6
6
 
7
7
  NS_ASSUME_NONNULL_BEGIN
8
8
 
@@ -35,7 +35,7 @@ NS_ASSUME_NONNULL_BEGIN
35
35
 
36
36
  @interface EXScreenOrientationRegistry : EXSingletonModule <UIApplicationDelegate, EXScreenOrientationEventEmitter, EXScreenOrientationRegistry>
37
37
 
38
- - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(nullable NSDictionary<UIApplicationLaunchOptionsKey,id> *)launchOptions;
38
+ - (void)updateCurrentScreenOrientation;
39
39
 
40
40
  - (UIInterfaceOrientationMask)requiredOrientationMask;
41
41
  - (void)traitCollectionDidChangeTo:(UITraitCollection *)traitCollection;
@@ -42,9 +42,9 @@ EX_REGISTER_SINGLETON_MODULE(ScreenOrientationRegistry)
42
42
  return self;
43
43
  }
44
44
 
45
- - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary<UIApplicationLaunchOptionsKey,id> *)launchOptions
45
+ - (void)updateCurrentScreenOrientation
46
46
  {
47
- // application:didFinishLaunchingWithOptions should be executed on the main thread.
47
+ // This should already be executed on the main thread.
48
48
  // However, it's safer to ensure that we are on a good thread.
49
49
  EX_WEAKIFY(self);
50
50
  [EXUtilities performSynchronouslyOnMainThread:^{
@@ -59,8 +59,6 @@ EX_REGISTER_SINGLETON_MODULE(ScreenOrientationRegistry)
59
59
  self.currentScreenOrientation = UIApplication.sharedApplication.statusBarOrientation;
60
60
  }
61
61
  }];
62
-
63
- return YES;
64
62
  }
65
63
 
66
64
  - (void)dealloc
@@ -9,4 +9,6 @@
9
9
 
10
10
  - (instancetype)initWithDefaultScreenOrientationMask:(UIInterfaceOrientationMask)defaultOrientationMask;
11
11
 
12
+ - (instancetype)initDefaultScreenOrientationFromPlist;
13
+
12
14
  @end
@@ -4,6 +4,9 @@
4
4
 
5
5
  #import <EXScreenOrientation/EXScreenOrientationViewController.h>
6
6
  #import <EXScreenOrientation/EXScreenOrientationRegistry.h>
7
+ #import <EXScreenOrientation/NSString+UIInterfaceOrientationMask.h>
8
+
9
+ NSString *const EXDefaultScreenOrientationMask = @"EXDefaultScreenOrientationMask";
7
10
 
8
11
  // copy of RNScreens protocol
9
12
  @protocol EXScreenOrientationRNSScreenWindowTraits
@@ -34,6 +37,20 @@
34
37
  return self;
35
38
  }
36
39
 
40
+ - (instancetype)initDefaultScreenOrientationFromPlist
41
+ {
42
+ NSString *plistValue = [NSBundle.mainBundle objectForInfoDictionaryKey:EXDefaultScreenOrientationMask];
43
+ if (plistValue != nil) {
44
+ @try {
45
+ UIInterfaceOrientationMask mask = [plistValue toUIInterfaceOrientationMask];
46
+ return [self initWithDefaultScreenOrientationMask:mask];
47
+ } @catch (NSException *exception) {
48
+ EXLogError(@"Invalid `%@` value in Info.plist, expected: one of `UIInterfaceOrientationMask` value, got: \"%@\".", EXDefaultScreenOrientationMask, plistValue);
49
+ }
50
+ }
51
+ return [self init];
52
+ }
53
+
37
54
  - (UIInterfaceOrientationMask)supportedInterfaceOrientations
38
55
  {
39
56
  if ([self shouldUseRNScreenOrientation]) {
@@ -0,0 +1,9 @@
1
+ // Copyright 2018-present 650 Industries. All rights reserved.
2
+
3
+ #import <UIKit/UIKit.h>
4
+
5
+ @interface NSString (UIInterfaceOrientationMask)
6
+
7
+ - (UIInterfaceOrientationMask)toUIInterfaceOrientationMask;
8
+
9
+ @end
@@ -0,0 +1,21 @@
1
+ // Copyright 2018-present 650 Industries. All rights reserved.
2
+
3
+ #import <EXScreenOrientation/NSString+UIInterfaceOrientationMask.h>
4
+
5
+ @implementation NSString (UIInterfaceOrientationMask)
6
+
7
+ - (UIInterfaceOrientationMask)toUIInterfaceOrientationMask
8
+ {
9
+ #define RETURN_VALUE_CHECKED(OPTION) if ([self isEqualToString:@#OPTION]) { return OPTION; }
10
+ RETURN_VALUE_CHECKED(UIInterfaceOrientationMaskPortrait)
11
+ RETURN_VALUE_CHECKED(UIInterfaceOrientationMaskLandscapeLeft)
12
+ RETURN_VALUE_CHECKED(UIInterfaceOrientationMaskLandscapeRight)
13
+ RETURN_VALUE_CHECKED(UIInterfaceOrientationMaskPortraitUpsideDown)
14
+ RETURN_VALUE_CHECKED(UIInterfaceOrientationMaskLandscape)
15
+ RETURN_VALUE_CHECKED(UIInterfaceOrientationMaskAll)
16
+ RETURN_VALUE_CHECKED(UIInterfaceOrientationMaskAllButUpsideDown)
17
+ #undef RETURN_VALUE_CHECKED
18
+ @throw [NSException exceptionWithName:NSInvalidArgumentException reason:@"Invalid UIInterfaceOrientationMask value" userInfo:nil];
19
+ }
20
+
21
+ @end
@@ -0,0 +1,12 @@
1
+ // Copyright 2018-present 650 Industries. All rights reserved.
2
+
3
+ import ExpoModulesCore
4
+
5
+ public class ScreenOrientationAppDelegate: ExpoAppDelegateSubscriber {
6
+ public func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
7
+ if let screenOrientationRegistry = ModuleRegistryProvider.getSingletonModule(for: EXScreenOrientationRegistry.self) as? EXScreenOrientationRegistry {
8
+ screenOrientationRegistry.updateCurrentScreenOrientation()
9
+ }
10
+ return true
11
+ }
12
+ }
@@ -0,0 +1,9 @@
1
+ // Copyright 2018-present 650 Industries. All rights reserved.
2
+
3
+ import ExpoModulesCore
4
+
5
+ public class ScreenOrientationReactDelegateHandler: ExpoReactDelegateHandler {
6
+ public override func createRootViewController(reactDelegate: ExpoReactDelegate) -> UIViewController? {
7
+ return EXScreenOrientationViewController(defaultScreenOrientationFromPlist: ());
8
+ }
9
+ }
@@ -11,16 +11,22 @@ Pod::Spec.new do |s|
11
11
  s.author = package['author']
12
12
  s.homepage = package['homepage']
13
13
  s.platform = :ios, '12.0'
14
+ s.swift_version = '5.4'
14
15
  s.source = { git: 'https://github.com/expo/expo.git' }
15
16
  s.static_framework = true
16
17
 
17
18
  s.dependency 'ExpoModulesCore'
18
19
  s.dependency 'React-Core'
19
20
 
21
+ # Swift/Objective-C compatibility
22
+ s.pod_target_xcconfig = {
23
+ 'DEFINES_MODULE' => 'YES'
24
+ }
25
+
20
26
  if !$ExpoUseSources&.include?(package['name']) && ENV['EXPO_USE_SOURCE'].to_i == 0 && File.exist?("#{s.name}.xcframework") && Gem::Version.new(Pod::VERSION) >= Gem::Version.new('1.10.0')
21
27
  s.source_files = "#{s.name}/**/*.h"
22
28
  s.vendored_frameworks = "#{s.name}.xcframework"
23
29
  else
24
- s.source_files = "#{s.name}/**/*.{h,m}"
30
+ s.source_files = "#{s.name}/**/*.{h,m,swift}"
25
31
  end
26
32
  end
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "expo-screen-orientation",
3
- "version": "4.0.1",
3
+ "version": "4.1.1",
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",
@@ -36,11 +36,13 @@
36
36
  "preset": "expo-module-scripts"
37
37
  },
38
38
  "dependencies": {
39
- "@expo/config-plugins": "^3.1.0",
40
- "expo-modules-core": "~0.4.2"
39
+ "@expo/config-plugins": "^4.0.2"
41
40
  },
42
41
  "devDependencies": {
43
42
  "expo-module-scripts": "^2.0.0"
44
43
  },
45
- "gitHead": "2718b696f4a6919905b0f47ebb24ff65b42d8ff9"
44
+ "peerDependencies": {
45
+ "expo": "*"
46
+ },
47
+ "gitHead": "cf8e7fde1b19e10dd9b74a8af0e9362ae8e14001"
46
48
  }
@@ -1,5 +1,22 @@
1
- import { ConfigPlugin } from '@expo/config-plugins';
2
- export declare function modifyObjcAppDelegate(contents: string, mask: string): string;
1
+ import { ConfigPlugin, InfoPlist } from '@expo/config-plugins';
2
+ import { ExpoConfig } from '@expo/config-types';
3
+ export declare const INITIAL_ORIENTATION_KEY = "EXDefaultScreenOrientationMask";
4
+ declare const OrientationLock: {
5
+ DEFAULT: string;
6
+ ALL: string;
7
+ PORTRAIT: string;
8
+ PORTRAIT_UP: string;
9
+ PORTRAIT_DOWN: string;
10
+ LANDSCAPE: string;
11
+ LANDSCAPE_LEFT: string;
12
+ LANDSCAPE_RIGHT: string;
13
+ };
14
+ declare type OrientationMasks = keyof typeof OrientationLock;
15
+ interface ExpoConfigWithInitialOrientation extends ExpoConfig {
16
+ initialOrientation?: OrientationMasks;
17
+ }
18
+ export declare function getInitialOrientation(config: Pick<ExpoConfigWithInitialOrientation, 'initialOrientation'>): OrientationMasks;
19
+ export declare function setInitialOrientation(config: Pick<ExpoConfigWithInitialOrientation, 'initialOrientation'>, infoPlist: InfoPlist): InfoPlist;
3
20
  declare const _default: ConfigPlugin<void | {
4
21
  initialOrientation?: "DEFAULT" | "ALL" | "PORTRAIT" | "PORTRAIT_UP" | "PORTRAIT_DOWN" | "LANDSCAPE" | "LANDSCAPE_LEFT" | "LANDSCAPE_RIGHT" | undefined;
5
22
  }>;
@@ -3,11 +3,12 @@ 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.modifyObjcAppDelegate = void 0;
6
+ exports.setInitialOrientation = exports.getInitialOrientation = exports.INITIAL_ORIENTATION_KEY = void 0;
7
7
  const config_plugins_1 = require("@expo/config-plugins");
8
8
  const assert_1 = __importDefault(require("assert"));
9
- const fs_1 = __importDefault(require("fs"));
10
9
  const pkg = require('expo-screen-orientation/package.json');
10
+ // This value must match the `EXDefaultScreenOrientationMask` string used in `expo-screen-orientation/ios/EXScreenOrientation/EXScreenOrientationViewController.m` (do not change).
11
+ exports.INITIAL_ORIENTATION_KEY = 'EXDefaultScreenOrientationMask';
11
12
  const OrientationLock = {
12
13
  DEFAULT: 'UIInterfaceOrientationMaskAllButUpsideDown',
13
14
  ALL: 'UIInterfaceOrientationMaskAll',
@@ -18,36 +19,32 @@ const OrientationLock = {
18
19
  LANDSCAPE_LEFT: 'UIInterfaceOrientationMaskLandscapeLeft',
19
20
  LANDSCAPE_RIGHT: 'UIInterfaceOrientationMaskLandscapeRight',
20
21
  };
21
- function modifyObjcAppDelegate(contents, mask) {
22
- // Add import
23
- if (!contents.includes('#import <EXScreenOrientation/EXScreenOrientationViewController.h>')) {
24
- contents = contents.replace(/#import "AppDelegate.h"/g, `#import "AppDelegate.h"
25
- #import <EXScreenOrientation/EXScreenOrientationViewController.h>`);
22
+ const withScreenOrientationViewController = (config, { initialOrientation = 'DEFAULT' } = {}) => {
23
+ config = (0, config_plugins_1.withInfoPlist)(config, (config) => {
24
+ const extendedConfig = {
25
+ ...config,
26
+ initialOrientation,
27
+ };
28
+ config.modResults = setInitialOrientation(extendedConfig, config.modResults);
29
+ return config;
30
+ });
31
+ return config;
32
+ };
33
+ function getInitialOrientation(config) {
34
+ var _a;
35
+ return (_a = config.initialOrientation) !== null && _a !== void 0 ? _a : 'DEFAULT';
36
+ }
37
+ exports.getInitialOrientation = getInitialOrientation;
38
+ function setInitialOrientation(config, infoPlist) {
39
+ const initialOrientation = getInitialOrientation(config);
40
+ (0, assert_1.default)(initialOrientation in OrientationLock, `Invalid initial orientation "${initialOrientation}" expected one of: ${Object.keys(OrientationLock).join(', ')}`);
41
+ if (initialOrientation === 'DEFAULT') {
42
+ delete infoPlist[exports.INITIAL_ORIENTATION_KEY];
26
43
  }
27
- // Change View Controller
28
- if (!contents.includes('[EXScreenOrientationViewController alloc]')) {
29
- contents = contents.replace(/UIViewController\s?\*\s?rootViewController\s?=\s?\[UIViewController new\];/g, `UIViewController *rootViewController = [[EXScreenOrientationViewController alloc] initWithDefaultScreenOrientationMask:${mask}];`);
44
+ else {
45
+ infoPlist[exports.INITIAL_ORIENTATION_KEY] = OrientationLock[initialOrientation];
30
46
  }
31
- return contents;
47
+ return infoPlist;
32
48
  }
33
- exports.modifyObjcAppDelegate = modifyObjcAppDelegate;
34
- const withScreenOrientationViewController = (config, { initialOrientation = 'DEFAULT' } = {}) => {
35
- assert_1.default(initialOrientation in OrientationLock, `Invalid initial orientation "${initialOrientation}" expected one of: ${Object.keys(OrientationLock).join(', ')}`);
36
- return config_plugins_1.withDangerousMod(config, [
37
- 'ios',
38
- async (config) => {
39
- const fileInfo = config_plugins_1.IOSConfig.Paths.getAppDelegate(config.modRequest.projectRoot);
40
- let contents = fs_1.default.readFileSync(fileInfo.path, { encoding: 'utf-8' });
41
- if (fileInfo.language === 'objc') {
42
- contents = modifyObjcAppDelegate(contents, OrientationLock[initialOrientation]);
43
- }
44
- else {
45
- // TODO: Support Swift
46
- throw new Error(`Cannot append screen orientation view controller to AppDelegate of language "${fileInfo.language}"`);
47
- }
48
- fs_1.default.writeFileSync(fileInfo.path, contents);
49
- return config;
50
- },
51
- ]);
52
- };
53
- exports.default = config_plugins_1.createRunOncePlugin(withScreenOrientationViewController, pkg.name, pkg.version);
49
+ exports.setInitialOrientation = setInitialOrientation;
50
+ exports.default = (0, config_plugins_1.createRunOncePlugin)(withScreenOrientationViewController, pkg.name, pkg.version);
@@ -1,14 +1,12 @@
1
- import {
2
- ConfigPlugin,
3
- createRunOncePlugin,
4
- IOSConfig,
5
- withDangerousMod,
6
- } from '@expo/config-plugins';
1
+ import { ConfigPlugin, createRunOncePlugin, InfoPlist, withInfoPlist } from '@expo/config-plugins';
2
+ import { ExpoConfig } from '@expo/config-types';
7
3
  import assert from 'assert';
8
- import fs from 'fs';
9
4
 
10
5
  const pkg = require('expo-screen-orientation/package.json');
11
6
 
7
+ // This value must match the `EXDefaultScreenOrientationMask` string used in `expo-screen-orientation/ios/EXScreenOrientation/EXScreenOrientationViewController.m` (do not change).
8
+ export const INITIAL_ORIENTATION_KEY = 'EXDefaultScreenOrientationMask';
9
+
12
10
  const OrientationLock = {
13
11
  DEFAULT: 'UIInterfaceOrientationMaskAllButUpsideDown',
14
12
  ALL: 'UIInterfaceOrientationMaskAll',
@@ -20,29 +18,39 @@ const OrientationLock = {
20
18
  LANDSCAPE_RIGHT: 'UIInterfaceOrientationMaskLandscapeRight',
21
19
  };
22
20
 
23
- export function modifyObjcAppDelegate(contents: string, mask: string): string {
24
- // Add import
25
- if (!contents.includes('#import <EXScreenOrientation/EXScreenOrientationViewController.h>')) {
26
- contents = contents.replace(
27
- /#import "AppDelegate.h"/g,
28
- `#import "AppDelegate.h"
29
- #import <EXScreenOrientation/EXScreenOrientationViewController.h>`
30
- );
31
- }
21
+ type OrientationMasks = keyof typeof OrientationLock;
32
22
 
33
- // Change View Controller
34
- if (!contents.includes('[EXScreenOrientationViewController alloc]')) {
35
- contents = contents.replace(
36
- /UIViewController\s?\*\s?rootViewController\s?=\s?\[UIViewController new\];/g,
37
- `UIViewController *rootViewController = [[EXScreenOrientationViewController alloc] initWithDefaultScreenOrientationMask:${mask}];`
38
- );
39
- }
40
- return contents;
23
+ // `initialOrientation` is not public in expo config yet, we just use it as an internal type.
24
+ interface ExpoConfigWithInitialOrientation extends ExpoConfig {
25
+ initialOrientation?: OrientationMasks;
41
26
  }
42
27
 
43
28
  const withScreenOrientationViewController: ConfigPlugin<{
44
29
  initialOrientation?: keyof typeof OrientationLock;
45
30
  } | void> = (config, { initialOrientation = 'DEFAULT' } = {}) => {
31
+ config = withInfoPlist(config, (config) => {
32
+ const extendedConfig = {
33
+ ...config,
34
+ initialOrientation,
35
+ };
36
+ config.modResults = setInitialOrientation(extendedConfig, config.modResults);
37
+ return config;
38
+ });
39
+ return config;
40
+ };
41
+
42
+ export function getInitialOrientation(
43
+ config: Pick<ExpoConfigWithInitialOrientation, 'initialOrientation'>
44
+ ): OrientationMasks {
45
+ return config.initialOrientation ?? 'DEFAULT';
46
+ }
47
+
48
+ export function setInitialOrientation(
49
+ config: Pick<ExpoConfigWithInitialOrientation, 'initialOrientation'>,
50
+ infoPlist: InfoPlist
51
+ ): InfoPlist {
52
+ const initialOrientation = getInitialOrientation(config);
53
+
46
54
  assert(
47
55
  initialOrientation in OrientationLock,
48
56
  `Invalid initial orientation "${initialOrientation}" expected one of: ${Object.keys(
@@ -50,24 +58,12 @@ const withScreenOrientationViewController: ConfigPlugin<{
50
58
  ).join(', ')}`
51
59
  );
52
60
 
53
- return withDangerousMod(config, [
54
- 'ios',
55
- async (config) => {
56
- const fileInfo = IOSConfig.Paths.getAppDelegate(config.modRequest.projectRoot);
57
- let contents = fs.readFileSync(fileInfo.path, { encoding: 'utf-8' });
58
- if (fileInfo.language === 'objc') {
59
- contents = modifyObjcAppDelegate(contents, OrientationLock[initialOrientation]);
60
- } else {
61
- // TODO: Support Swift
62
- throw new Error(
63
- `Cannot append screen orientation view controller to AppDelegate of language "${fileInfo.language}"`
64
- );
65
- }
66
- fs.writeFileSync(fileInfo.path, contents);
67
-
68
- return config;
69
- },
70
- ]);
71
- };
61
+ if (initialOrientation === 'DEFAULT') {
62
+ delete infoPlist[INITIAL_ORIENTATION_KEY];
63
+ } else {
64
+ infoPlist[INITIAL_ORIENTATION_KEY] = OrientationLock[initialOrientation];
65
+ }
66
+ return infoPlist;
67
+ }
72
68
 
73
69
  export default createRunOncePlugin(withScreenOrientationViewController, pkg.name, pkg.version);
@@ -34,12 +34,12 @@ let _lastOrientationLock: OrientationLock = OrientationLock.UNKNOWN;
34
34
  // @needsAudit
35
35
  /**
36
36
  * Lock the screen orientation to a particular `OrientationLock`.
37
- * @param orientationLock The orientation lock to apply. See the [`OrientationLock`](#screenorientationorientationlock)
37
+ * @param orientationLock The orientation lock to apply. See the [`OrientationLock`](#orientationlock)
38
38
  * enum for possible values.
39
39
  * @return Returns a promise with `void` value, which fulfils when the orientation is set.
40
40
  *
41
41
  * # Error codes
42
- * - `ERR_SCREEN_ORIENTATION_INVALID_ORIENTATION_LOCK` - An invalid [`OrientationLock`](#screenorientationorientationlock)
42
+ * - `ERR_SCREEN_ORIENTATION_INVALID_ORIENTATION_LOCK` - An invalid [`OrientationLock`](#orientationlock)
43
43
  * was passed in.
44
44
  * - `ERR_SCREEN_ORIENTATION_UNSUPPORTED_ORIENTATION_LOCK` - The platform does not support the
45
45
  * orientation lock policy.
@@ -72,13 +72,13 @@ export async function lockAsync(orientationLock: OrientationLock): Promise<void>
72
72
 
73
73
  // @needsAudit @docsMissing
74
74
  /**
75
- * @param options The platform specific lock to apply. See the [`PlatformOrientationInfo`](#screenorientationplatformorientationinfo)
75
+ * @param options The platform specific lock to apply. See the [`PlatformOrientationInfo`](#platformorientationinfo)
76
76
  * object type for the different platform formats.
77
77
  * @return Returns a promise with `void` value, resolving when the orientation is set and rejecting
78
78
  * if an invalid option or value is passed.
79
79
  *
80
80
  * # Error codes
81
- * - `ERR_SCREEN_ORIENTATION_INVALID_ORIENTATION_LOCK` - __iOS Only.__ An invalid [`OrientationLock`](#screenorientationorientationlock)
81
+ * - `ERR_SCREEN_ORIENTATION_INVALID_ORIENTATION_LOCK` - __iOS Only.__ An invalid [`OrientationLock`](#orientationlock)
82
82
  * was passed in.
83
83
  * - `ERR_SCREEN_ORIENTATION_UNSUPPORTED_ORIENTATION_LOCK` - The platform does not support the
84
84
  * orientation lock policy.
@@ -167,7 +167,7 @@ export async function getOrientationAsync(): Promise<Orientation> {
167
167
  // @needsAudit
168
168
  /**
169
169
  * Gets the current screen orientation lock type.
170
- * @return Returns a promise which fulfils with an [`OrientationLock`](#screenorientationorientationlock)
170
+ * @return Returns a promise which fulfils with an [`OrientationLock`](#orientationlock)
171
171
  * value.
172
172
  *
173
173
  * # Error codes
@@ -183,7 +183,7 @@ export async function getOrientationLockAsync(): Promise<OrientationLock> {
183
183
  // @needsAudit
184
184
  /**
185
185
  * Gets the platform specific screen orientation lock type.
186
- * @return Returns a promise which fulfils with a [`PlatformOrientationInfo`](#screenorientationplatformorientationinfo)
186
+ * @return Returns a promise which fulfils with a [`PlatformOrientationInfo`](#platformorientationinfo)
187
187
  * value.
188
188
  *
189
189
  * # Error codes
@@ -211,7 +211,7 @@ export async function getPlatformOrientationLockAsync(): Promise<PlatformOrienta
211
211
 
212
212
  // @needsAudit @docsMissing
213
213
  /**
214
- * Returns whether the [`OrientationLock`](#screenorientationorientationlock) policy is supported on
214
+ * Returns whether the [`OrientationLock`](#orientationlock) policy is supported on
215
215
  * the device.
216
216
  * @param orientationLock
217
217
  * @return Returns a promise that resolves to a `boolean` value that reflects whether or not the
@@ -248,7 +248,7 @@ function getEventName(): string {
248
248
  * or from `landscape` to `portrait`. For example, it won't be invoked when screen orientation
249
249
  * change from `portrait up` to `portrait down`, but it will be called when there was a change from
250
250
  * `portrait up` to `landscape left`.
251
- * @param listener Each orientation update will pass an object with the new [`OrientationChangeEvent`](#screenorientationorientationchangeevent)
251
+ * @param listener Each orientation update will pass an object with the new [`OrientationChangeEvent`](#orientationchangeevent)
252
252
  * to the listener.
253
253
  */
254
254
  export function addOrientationChangeListener(listener: OrientationChangeListener): Subscription {
@@ -27,7 +27,7 @@ export enum Orientation {
27
27
  * An enum whose values can be passed to the [`lockAsync`](#screenorientationlockasyncorientationlock)
28
28
  * method.
29
29
  * > __Note:__ `OrientationLock.ALL` and `OrientationLock.PORTRAIT` are invalid on devices which
30
- * don't support `OrientationLock.PORTRAIT_DOWN`.
30
+ * > don't support `OrientationLock.PORTRAIT_DOWN`.
31
31
  */
32
32
  export enum OrientationLock {
33
33
  /**
@@ -88,7 +88,7 @@ export enum SizeClassIOS {
88
88
  /**
89
89
  * An enum representing the lock policies that can be applied on the web platform, modelled after
90
90
  * the [W3C specification](https://w3c.github.io/screen-orientation/#dom-orientationlocktype).
91
- * These values can be applied through the [`lockPlatformAsync`](#screenorientationlockplatformasyncplatforminfo)
91
+ * These values can be applied through the [`lockPlatformAsync`](#screenorientationlockplatformasyncoptions)
92
92
  * method.
93
93
  */
94
94
  export enum WebOrientationLock {
@@ -114,17 +114,20 @@ export enum WebOrientation {
114
114
  // @needsAudit
115
115
  export type PlatformOrientationInfo = {
116
116
  /**
117
- * __Android Only.__ A constant to set using the Android native [API](https://developer.android.com/reference/android/R.attr.html#screenOrientation).
117
+ * A constant to set using the Android native [API](https://developer.android.com/reference/android/R.attr.html#screenOrientation).
118
118
  * For example, in order to set the lock policy to [unspecified](https://developer.android.com/reference/android/content/pm/ActivityInfo.html#SCREEN_ORIENTATION_UNSPECIFIED),
119
119
  * `-1` should be passed in.
120
+ * @platform android
120
121
  */
121
122
  screenOrientationConstantAndroid?: number;
122
123
  /**
123
- * __iOS Only.__ An array of orientations to allow on the iOS platform.
124
+ * An array of orientations to allow on the iOS platform.
125
+ * @platform ios
124
126
  */
125
127
  screenOrientationArrayIOS?: Orientation[];
126
128
  /**
127
- * __Web Only.__ A web orientation lock to apply in the browser.
129
+ * A web orientation lock to apply in the browser.
130
+ * @platform web
128
131
  */
129
132
  screenOrientationLockWeb?: WebOrientationLock;
130
133
  };
@@ -136,13 +139,15 @@ export type ScreenOrientationInfo = {
136
139
  */
137
140
  orientation: Orientation;
138
141
  /**
139
- * __iOS Only.__ The [vertical size class](https://developer.apple.com/library/archive/featuredarticles/ViewControllerPGforiPhoneOS/TheAdaptiveModel.html)
142
+ * The [vertical size class](https://developer.apple.com/library/archive/featuredarticles/ViewControllerPGforiPhoneOS/TheAdaptiveModel.html)
140
143
  * of the device.
144
+ * @platform ios
141
145
  */
142
146
  verticalSizeClass?: SizeClassIOS;
143
147
  /**
144
- * __iOS Only.__ The [horizontal size class](https://developer.apple.com/library/archive/featuredarticles/ViewControllerPGforiPhoneOS/TheAdaptiveModel.html)
148
+ * The [horizontal size class](https://developer.apple.com/library/archive/featuredarticles/ViewControllerPGforiPhoneOS/TheAdaptiveModel.html)
145
149
  * of the device.
150
+ * @platform ios
146
151
  */
147
152
  horizontalSizeClass?: SizeClassIOS;
148
153
  };
package/unimodule.json DELETED
@@ -1,4 +0,0 @@
1
- {
2
- "name": "expo-screen-orientation",
3
- "platforms": ["ios", "android"]
4
- }