expo-screen-orientation 7.0.3 → 7.0.5

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,18 @@
10
10
 
11
11
  ### 💡 Others
12
12
 
13
+ ## 7.0.5 — 2024-05-14
14
+
15
+ ### 🐛 Bug fixes
16
+
17
+ - [Android] Fixed screen orientation change listener not firing. ([#28832](https://github.com/expo/expo/pull/28832) by [@lukmccall](https://github.com/lukmccall))
18
+
19
+ ## 7.0.4 — 2024-05-09
20
+
21
+ ### 🐛 Bug fixes
22
+
23
+ - Fix bug with weak var type causing dropped events. ([#28677](https://github.com/expo/expo/pull/28677) by [@aleqsio](https://github.com/aleqsio))
24
+
13
25
  ## 7.0.3 — 2024-05-01
14
26
 
15
27
  _This version does not introduce any user-facing changes._
@@ -1,7 +1,7 @@
1
1
  apply plugin: 'com.android.library'
2
2
 
3
3
  group = 'host.exp.exponent'
4
- version = '7.0.3'
4
+ version = '7.0.5'
5
5
 
6
6
  def expoModulesCorePlugin = new File(project(":expo-modules-core").projectDir.absolutePath, "ExpoModulesCorePlugin.gradle")
7
7
  apply from: expoModulesCorePlugin
@@ -14,6 +14,6 @@ android {
14
14
  namespace "expo.modules.screenorientation"
15
15
  defaultConfig {
16
16
  versionCode 7
17
- versionName '7.0.3'
17
+ versionName '7.0.5'
18
18
  }
19
19
  }
@@ -1 +1 @@
1
- {"version":3,"file":"ScreenOrientation.d.ts","sourceRoot":"","sources":["../src/ScreenOrientation.ts"],"names":[],"mappings":"AAAA,OAAO,EAA0B,YAAY,EAAuB,MAAM,mBAAmB,CAAC;AAG9F,OAAO,EACL,WAAW,EACX,sBAAsB,EACtB,yBAAyB,EACzB,eAAe,EACf,uBAAuB,EACvB,kBAAkB,EAClB,cAAc,EACd,YAAY,EACZ,qBAAqB,EACtB,MAAM,2BAA2B,CAAC;AAEnC,OAAO,EACL,WAAW,EACX,eAAe,EACf,uBAAuB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;AAEnC,OAAO,EACL,WAAW,EACX,eAAe,EACf,uBAAuB,EACvB,yBAAyB,EACzB,sBAAsB,EACtB,kBAAkB,EAClB,cAAc,EACd,YAAY,EACZ,qBAAqB,EACrB,YAAY,GACb,CAAC;AAQF;;;;;;;;;;;;GAYG;AACH,wBAAsB,SAAS,CAAC,eAAe,EAAE,eAAe,GAAG,OAAO,CAAC,IAAI,CAAC,CAgB/E;AAGD;;;;;GAKG;AACH,wBAAsB,iBAAiB,CAAC,OAAO,EAAE,uBAAuB,GAAG,OAAO,CAAC,IAAI,CAAC,CA4CvF;AAGD;;;GAGG;AACH,wBAAsB,WAAW,IAAI,OAAO,CAAC,IAAI,CAAC,CAKjD;AAGD;;;;GAIG;AACH,wBAAsB,mBAAmB,IAAI,OAAO,CAAC,WAAW,CAAC,CAKhE;AAGD;;;;GAIG;AACH,wBAAsB,uBAAuB,IAAI,OAAO,CAAC,eAAe,CAAC,CAKxE;AAGD;;;;GAIG;AACH,wBAAsB,+BAA+B,IAAI,OAAO,CAAC,uBAAuB,CAAC,CAiBxF;AAGD;;;;;;GAMG;AACH,wBAAsB,4BAA4B,CAChD,eAAe,EAAE,eAAe,GAC/B,OAAO,CAAC,OAAO,CAAC,CAWlB;AAKD;;;;;;;GAOG;AACH,wBAAgB,4BAA4B,CAAC,QAAQ,EAAE,yBAAyB,GAAG,YAAY,CAQ9F;AAMD;;GAEG;AACH,wBAAgB,gCAAgC,IAAI,IAAI,CAUvD;AAGD;;;;;GAKG;AACH,wBAAgB,+BAA+B,CAAC,YAAY,EAAE,YAAY,GAAG,IAAI,CAQhF"}
@@ -1,4 +1,5 @@
1
1
  import { EventEmitter, Platform, UnavailabilityError } from 'expo-modules-core';
2
+ import { Dimensions } from 'react-native';
2
3
  import ExpoScreenOrientation from './ExpoScreenOrientation';
3
4
  import { Orientation, OrientationLock, WebOrientationLock, WebOrientation, SizeClassIOS, } from './ScreenOrientation.types';
4
5
  export { Orientation, OrientationLock, WebOrientationLock, WebOrientation, SizeClassIOS, };
@@ -157,12 +158,6 @@ export async function supportsOrientationLockAsync(orientationLock) {
157
158
  }
158
159
  return await ExpoScreenOrientation.supportsOrientationLockAsync(orientationLock);
159
160
  }
160
- // Determine the event name lazily so Jest can set up mocks in advance
161
- function getEventName() {
162
- return Platform.OS === 'ios' || Platform.OS === 'web'
163
- ? 'expoDidUpdateDimensions'
164
- : 'didUpdateDimensions';
165
- }
166
161
  // We rely on RN to emit `didUpdateDimensions`
167
162
  // If this method no longer works, it's possible that the underlying RN implementation has changed
168
163
  // see https://github.com/facebook/react-native/blob/c31f79fe478b882540d7fd31ee37b53ddbd60a17/ReactAndroid/src/main/java/com/facebook/react/modules/deviceinfo/DeviceInfoModule.java#L90
@@ -179,25 +174,7 @@ export function addOrientationChangeListener(listener) {
179
174
  if (typeof listener !== 'function') {
180
175
  throw new TypeError(`addOrientationChangeListener cannot be called with ${listener}`);
181
176
  }
182
- const subscription = _orientationChangeEmitter.addListener(getEventName(), async (update) => {
183
- let orientationInfo, orientationLock;
184
- if (Platform.OS === 'ios' || Platform.OS === 'web') {
185
- // For iOS, RN relies on statusBarOrientation (deprecated) to emit `didUpdateDimensions`
186
- // event, so we emit our own `expoDidUpdateDimensions` event instead
187
- orientationLock = update.orientationLock;
188
- orientationInfo = update.orientationInfo;
189
- }
190
- else {
191
- // We rely on the RN Dimensions to emit the `didUpdateDimensions` event on Android
192
- let orientation;
193
- [orientationLock, orientation] = await Promise.all([
194
- getOrientationLockAsync(),
195
- getOrientationAsync(),
196
- ]);
197
- orientationInfo = { orientation };
198
- }
199
- listener({ orientationInfo, orientationLock });
200
- });
177
+ const subscription = createDidUpdateDimensionsSubscription(listener);
201
178
  _orientationChangeSubscribers.push(subscription);
202
179
  return subscription;
203
180
  }
@@ -232,4 +209,19 @@ export function removeOrientationChangeListener(subscription) {
232
209
  subscription.remove();
233
210
  _orientationChangeSubscribers = _orientationChangeSubscribers.filter((sub) => sub !== subscription);
234
211
  }
212
+ function createDidUpdateDimensionsSubscription(listener) {
213
+ if (Platform.OS === 'web' || Platform.OS === 'ios') {
214
+ return _orientationChangeEmitter.addListener('expoDidUpdateDimensions', async (update) => {
215
+ listener(update);
216
+ });
217
+ }
218
+ // We rely on the RN Dimensions to emit the `didUpdateDimensions` event on Android
219
+ return Dimensions.addEventListener('change', async () => {
220
+ const [orientationLock, orientation] = await Promise.all([
221
+ getOrientationLockAsync(),
222
+ getOrientationAsync(),
223
+ ]);
224
+ listener({ orientationInfo: { orientation }, orientationLock });
225
+ });
226
+ }
235
227
  //# sourceMappingURL=ScreenOrientation.js.map
@@ -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,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;;;;;;;;;;;;GAYG;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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ACxC,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`](#orientationlock)\n * enum for possible values.\n * @return Returns a promise with `void` value, which fulfils when the orientation is set.\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 */\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 */\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`](#orientation)\n * value that reflects the current screen orientation.\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 */\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 */\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"]}
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;AAC9F,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE1C,OAAO,qBAAqB,MAAM,yBAAyB,CAAC;AAC5D,OAAO,EACL,WAAW,EAGX,eAAe,EAEf,kBAAkB,EAClB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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;AAED,SAAS,qCAAqC,CAAC,QAAmC;IAChF,IAAI,QAAQ,CAAC,EAAE,KAAK,KAAK,IAAI,QAAQ,CAAC,EAAE,KAAK,KAAK,EAAE;QAClD,OAAO,yBAAyB,CAAC,WAAW,CAC1C,yBAAyB,EACzB,KAAK,EAAE,MAA8B,EAAE,EAAE;YACvC,QAAQ,CAAC,MAAM,CAAC,CAAC;QACnB,CAAC,CACF,CAAC;KACH;IAED,kFAAkF;IAClF,OAAO,UAAU,CAAC,gBAAgB,CAAC,QAAQ,EAAE,KAAK,IAAI,EAAE;QACtD,MAAM,CAAC,eAAe,EAAE,WAAW,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC;YACvD,uBAAuB,EAAE;YACzB,mBAAmB,EAAE;SACtB,CAAC,CAAC;QACH,QAAQ,CAAC,EAAE,eAAe,EAAE,EAAE,WAAW,EAAE,EAAE,eAAe,EAAE,CAAC,CAAC;IAClE,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["import { EventEmitter, Platform, Subscription, UnavailabilityError } from 'expo-modules-core';\nimport { Dimensions } from 'react-native';\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 * @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 */\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 */\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`](#orientation)\n * value that reflects the current screen orientation.\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 */\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 */\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// 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\n const subscription = createDidUpdateDimensionsSubscription(listener);\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\nfunction createDidUpdateDimensionsSubscription(listener: OrientationChangeListener): Subscription {\n if (Platform.OS === 'web' || Platform.OS === 'ios') {\n return _orientationChangeEmitter.addListener(\n 'expoDidUpdateDimensions',\n async (update: OrientationChangeEvent) => {\n listener(update);\n }\n );\n }\n\n // We rely on the RN Dimensions to emit the `didUpdateDimensions` event on Android\n return Dimensions.addEventListener('change', async () => {\n const [orientationLock, orientation] = await Promise.all([\n getOrientationLockAsync(),\n getOrientationAsync(),\n ]);\n listener({ orientationInfo: { orientation }, orientationLock });\n });\n}\n"]}
@@ -18,7 +18,7 @@ public class ScreenOrientationRegistry: NSObject, UIApplicationDelegate {
18
18
  var orientationControllers: [ScreenOrientationController] = []
19
19
  var controllerInterfaceMasks: [ObjectIdentifier: UIInterfaceOrientationMask] = [:]
20
20
  @objc
21
- public weak var currentTraitCollection: UITraitCollection?
21
+ public var currentTraitCollection: UITraitCollection?
22
22
  var lastOrientationMask: UIInterfaceOrientationMask
23
23
  var rootViewController: UIViewController? {
24
24
  let keyWindow = UIApplication
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "expo-screen-orientation",
3
- "version": "7.0.3",
3
+ "version": "7.0.5",
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": "87bd0dfa8b784a834191195ca174a00dd30ee5b7"
44
+ "gitHead": "e4943670c15e4d9b305c80f8c000b2e141fc9a25"
45
45
  }
@@ -1,4 +1,5 @@
1
1
  import { EventEmitter, Platform, Subscription, UnavailabilityError } from 'expo-modules-core';
2
+ import { Dimensions } from 'react-native';
2
3
 
3
4
  import ExpoScreenOrientation from './ExpoScreenOrientation';
4
5
  import {
@@ -201,14 +202,6 @@ export async function supportsOrientationLockAsync(
201
202
 
202
203
  return await ExpoScreenOrientation.supportsOrientationLockAsync(orientationLock);
203
204
  }
204
-
205
- // Determine the event name lazily so Jest can set up mocks in advance
206
- function getEventName(): string {
207
- return Platform.OS === 'ios' || Platform.OS === 'web'
208
- ? 'expoDidUpdateDimensions'
209
- : 'didUpdateDimensions';
210
- }
211
-
212
205
  // We rely on RN to emit `didUpdateDimensions`
213
206
  // If this method no longer works, it's possible that the underlying RN implementation has changed
214
207
  // see https://github.com/facebook/react-native/blob/c31f79fe478b882540d7fd31ee37b53ddbd60a17/ReactAndroid/src/main/java/com/facebook/react/modules/deviceinfo/DeviceInfoModule.java#L90
@@ -225,27 +218,8 @@ export function addOrientationChangeListener(listener: OrientationChangeListener
225
218
  if (typeof listener !== 'function') {
226
219
  throw new TypeError(`addOrientationChangeListener cannot be called with ${listener}`);
227
220
  }
228
- const subscription = _orientationChangeEmitter.addListener(
229
- getEventName(),
230
- async (update: OrientationChangeEvent) => {
231
- let orientationInfo, orientationLock;
232
- if (Platform.OS === 'ios' || Platform.OS === 'web') {
233
- // For iOS, RN relies on statusBarOrientation (deprecated) to emit `didUpdateDimensions`
234
- // event, so we emit our own `expoDidUpdateDimensions` event instead
235
- orientationLock = update.orientationLock;
236
- orientationInfo = update.orientationInfo;
237
- } else {
238
- // We rely on the RN Dimensions to emit the `didUpdateDimensions` event on Android
239
- let orientation;
240
- [orientationLock, orientation] = await Promise.all([
241
- getOrientationLockAsync(),
242
- getOrientationAsync(),
243
- ]);
244
- orientationInfo = { orientation };
245
- }
246
- listener({ orientationInfo, orientationLock });
247
- }
248
- );
221
+
222
+ const subscription = createDidUpdateDimensionsSubscription(listener);
249
223
  _orientationChangeSubscribers.push(subscription);
250
224
  return subscription;
251
225
  }
@@ -285,3 +259,23 @@ export function removeOrientationChangeListener(subscription: Subscription): voi
285
259
  (sub) => sub !== subscription
286
260
  );
287
261
  }
262
+
263
+ function createDidUpdateDimensionsSubscription(listener: OrientationChangeListener): Subscription {
264
+ if (Platform.OS === 'web' || Platform.OS === 'ios') {
265
+ return _orientationChangeEmitter.addListener(
266
+ 'expoDidUpdateDimensions',
267
+ async (update: OrientationChangeEvent) => {
268
+ listener(update);
269
+ }
270
+ );
271
+ }
272
+
273
+ // We rely on the RN Dimensions to emit the `didUpdateDimensions` event on Android
274
+ return Dimensions.addEventListener('change', async () => {
275
+ const [orientationLock, orientation] = await Promise.all([
276
+ getOrientationLockAsync(),
277
+ getOrientationAsync(),
278
+ ]);
279
+ listener({ orientationInfo: { orientation }, orientationLock });
280
+ });
281
+ }