expo-screen-orientation 8.0.0 → 8.0.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,12 @@
10
10
 
11
11
  ### 💡 Others
12
12
 
13
+ ## 8.0.1 — 2024-12-05
14
+
15
+ ### 🐛 Bug fixes
16
+
17
+ - Fixed event listeners on web. ([#33361](https://github.com/expo/expo/pull/33361) by [@aleqsio](https://github.com/aleqsio))
18
+
13
19
  ## 8.0.0 — 2024-10-22
14
20
 
15
21
  ### 🛠 Breaking changes
@@ -1,7 +1,7 @@
1
1
  apply plugin: 'com.android.library'
2
2
 
3
3
  group = 'host.exp.exponent'
4
- version = '8.0.0'
4
+ version = '8.0.1'
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 '8.0.0'
17
+ versionName '8.0.1'
18
18
  }
19
19
  }
@@ -1,11 +1,17 @@
1
- import { Orientation, OrientationLock, WebOrientationLock } from './ScreenOrientation.types';
2
- declare const _default: {
1
+ import { NativeModule } from 'expo-modules-core';
2
+ import { Orientation, OrientationLock, WebOrientationLock, ExpoOrientationEvents } from './ScreenOrientation.types';
3
+ declare class ExpoScreenOrientation extends NativeModule<ExpoOrientationEvents> {
4
+ orientation: ScreenOrientation | null;
5
+ emitOrientationEvent(): Promise<void>;
6
+ startObserving(): void;
7
+ stopObserving(): void;
3
8
  supportsOrientationLockAsync(orientationLock: OrientationLock): Promise<boolean>;
4
9
  getPlatformOrientationLockAsync(): Promise<WebOrientationLock>;
5
10
  getOrientationAsync(): Promise<Orientation>;
6
11
  lockAsync(orientationLock: OrientationLock): Promise<void>;
7
12
  lockPlatformAsync(webOrientationLock: WebOrientationLock): Promise<void>;
8
13
  unlockAsync(): Promise<void>;
9
- };
14
+ }
15
+ declare const _default: typeof ExpoScreenOrientation;
10
16
  export default _default;
11
17
  //# sourceMappingURL=ExpoScreenOrientation.web.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ExpoScreenOrientation.web.d.ts","sourceRoot":"","sources":["../src/ExpoScreenOrientation.web.ts"],"names":[],"mappings":"AAIA,OAAO,EACL,WAAW,EACX,eAAe,EACf,kBAAkB,EAEnB,MAAM,2BAA2B,CAAC;;kDAoGmB,eAAe,GAAG,QAAQ,OAAO,CAAC;uCAG7C,QAAQ,kBAAkB,CAAC;2BAGvC,QAAQ,WAAW,CAAC;+BAQhB,eAAe,GAAG,QAAQ,IAAI,CAAC;0CAOpB,kBAAkB,GAAG,QAAQ,IAAI,CAAC;mBAIzD,QAAQ,IAAI,CAAC;;AA1BpC,wBAiDE"}
1
+ {"version":3,"file":"ExpoScreenOrientation.web.d.ts","sourceRoot":"","sources":["../src/ExpoScreenOrientation.web.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAA+B,MAAM,mBAAmB,CAAC;AAG9E,OAAO,EACL,WAAW,EACX,eAAe,EACf,kBAAkB,EAElB,qBAAqB,EACtB,MAAM,2BAA2B,CAAC;AA6EnC,cAAM,qBAAsB,SAAQ,YAAY,CAAC,qBAAqB,CAAC;IACrE,WAAW,EAAE,iBAAiB,GAAG,IAAI,CAE5B;IACH,oBAAoB;IAU1B,cAAc;IAUd,aAAa,IAAI,IAAI;IASf,4BAA4B,CAAC,eAAe,EAAE,eAAe,GAAG,OAAO,CAAC,OAAO,CAAC;IAGhF,+BAA+B,IAAI,OAAO,CAAC,kBAAkB,CAAC;IAG9D,mBAAmB,IAAI,OAAO,CAAC,WAAW,CAAC;IAQ3C,SAAS,CAAC,eAAe,EAAE,eAAe,GAAG,OAAO,CAAC,IAAI,CAAC;IAO1D,iBAAiB,CAAC,kBAAkB,EAAE,kBAAkB,GAAG,OAAO,CAAC,IAAI,CAAC;IAIxE,WAAW,IAAI,OAAO,CAAC,IAAI,CAAC;CAuBnC;;AAED,wBAAwD"}
@@ -1,5 +1,4 @@
1
- import { Platform } from 'expo-modules-core';
2
- import { DeviceEventEmitter } from 'react-native';
1
+ import { NativeModule, Platform, registerWebModule } from 'expo-modules-core';
3
2
  import { getOrientationLockAsync, getOrientationAsync } from './ScreenOrientation';
4
3
  import { Orientation, OrientationLock, WebOrientationLock, WebOrientation, } from './ScreenOrientation.types';
5
4
  const OrientationLockAPIToWeb = {
@@ -19,27 +18,6 @@ const OrientationWebToAPI = {
19
18
  [WebOrientation.LANDSCAPE_SECONDARY]: Orientation.LANDSCAPE_RIGHT,
20
19
  };
21
20
  const screen = Platform.canUseViewport ? window.screen : {};
22
- const orientation = Platform.canUseViewport
23
- ? screen.orientation || screen.msOrientation || null
24
- : null;
25
- async function emitOrientationEvent() {
26
- const [orientationLock, orientation] = await Promise.all([
27
- getOrientationLockAsync(),
28
- getOrientationAsync(),
29
- ]);
30
- DeviceEventEmitter.emit('expoDidUpdateDimensions', {
31
- orientationLock,
32
- orientationInfo: { orientation },
33
- });
34
- }
35
- if (Platform.canUseEventListeners) {
36
- if (orientation && orientation.addEventListener) {
37
- orientation.addEventListener('change', emitOrientationEvent);
38
- }
39
- else {
40
- window.addEventListener('orientationchange', emitOrientationEvent);
41
- }
42
- }
43
21
  function _convertToLegacyOrientationLock(orientationLock) {
44
22
  switch (orientationLock) {
45
23
  case WebOrientationLock.UNKNOWN:
@@ -77,31 +55,65 @@ async function _lockAsync(webOrientationLock) {
77
55
  }
78
56
  }
79
57
  let _lastWebOrientationLock = WebOrientationLock.UNKNOWN;
80
- export default {
58
+ class ExpoScreenOrientation extends NativeModule {
59
+ orientation = Platform.canUseViewport
60
+ ? screen.orientation || screen.msOrientation || null
61
+ : null;
62
+ async emitOrientationEvent() {
63
+ const [orientationLock, orientation] = await Promise.all([
64
+ getOrientationLockAsync(),
65
+ getOrientationAsync(),
66
+ ]);
67
+ this.emit('expoDidUpdateDimensions', {
68
+ orientationLock,
69
+ orientationInfo: { orientation },
70
+ });
71
+ }
72
+ startObserving() {
73
+ this.listener = () => this.emitOrientationEvent();
74
+ if (Platform.canUseEventListeners) {
75
+ if (this.orientation && this.orientation.addEventListener) {
76
+ this.orientation.addEventListener('change', this.listener);
77
+ }
78
+ else {
79
+ window.addEventListener('orientationchange', this.listener);
80
+ }
81
+ }
82
+ }
83
+ stopObserving() {
84
+ if (Platform.canUseEventListeners) {
85
+ if (this.orientation && this.orientation.removeEventListener) {
86
+ this.orientation.removeEventListener('change', this.listener);
87
+ }
88
+ else {
89
+ window.removeEventListener('orientationchange', this.listener);
90
+ }
91
+ }
92
+ }
81
93
  async supportsOrientationLockAsync(orientationLock) {
82
94
  return orientationLock in OrientationLockAPIToWeb;
83
- },
95
+ }
84
96
  async getPlatformOrientationLockAsync() {
85
97
  return _lastWebOrientationLock;
86
- },
98
+ }
87
99
  async getOrientationAsync() {
88
100
  const webOrientation = screen['msOrientation'] || (screen.orientation || screen['mozOrientation'] || {}).type;
89
101
  if (!webOrientation) {
90
102
  return Orientation.UNKNOWN;
91
103
  }
92
104
  return OrientationWebToAPI[webOrientation];
93
- },
105
+ }
94
106
  async lockAsync(orientationLock) {
95
107
  const webOrientationLock = OrientationLockAPIToWeb[orientationLock];
96
108
  if (!webOrientationLock) {
97
109
  throw new TypeError(`Invalid Orientation Lock: ${orientationLock}`);
98
110
  }
99
111
  await _lockAsync(webOrientationLock);
100
- },
112
+ }
101
113
  async lockPlatformAsync(webOrientationLock) {
102
114
  await _lockAsync(webOrientationLock);
103
115
  _lastWebOrientationLock = webOrientationLock;
104
- },
116
+ }
105
117
  async unlockAsync() {
106
118
  if (screen.orientation && screen.orientation.unlock) {
107
119
  screen.orientation.unlock();
@@ -121,6 +133,7 @@ export default {
121
133
  else {
122
134
  throw new Error(`expo-screen-orientation: The browser doesn't support unlocking screen orientation.`);
123
135
  }
124
- },
125
- };
136
+ }
137
+ }
138
+ export default registerWebModule(ExpoScreenOrientation);
126
139
  //# sourceMappingURL=ExpoScreenOrientation.web.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"ExpoScreenOrientation.web.js","sourceRoot":"","sources":["../src/ExpoScreenOrientation.web.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAC7C,OAAO,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAElD,OAAO,EAAE,uBAAuB,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AACnF,OAAO,EACL,WAAW,EACX,eAAe,EACf,kBAAkB,EAClB,cAAc,GACf,MAAM,2BAA2B,CAAC;AAEnC,MAAM,uBAAuB,GAEzB;IACF,CAAC,eAAe,CAAC,OAAO,CAAC,EAAE,kBAAkB,CAAC,OAAO;IACrD,CAAC,eAAe,CAAC,GAAG,CAAC,EAAE,kBAAkB,CAAC,GAAG;IAC7C,CAAC,eAAe,CAAC,QAAQ,CAAC,EAAE,kBAAkB,CAAC,QAAQ;IACvD,CAAC,eAAe,CAAC,WAAW,CAAC,EAAE,kBAAkB,CAAC,gBAAgB;IAClE,CAAC,eAAe,CAAC,aAAa,CAAC,EAAE,kBAAkB,CAAC,kBAAkB;IACtE,CAAC,eAAe,CAAC,SAAS,CAAC,EAAE,kBAAkB,CAAC,SAAS;IACzD,CAAC,eAAe,CAAC,cAAc,CAAC,EAAE,kBAAkB,CAAC,iBAAiB;IACtE,CAAC,eAAe,CAAC,eAAe,CAAC,EAAE,kBAAkB,CAAC,mBAAmB;CAC1E,CAAC;AAEF,MAAM,mBAAmB,GAErB;IACF,CAAC,cAAc,CAAC,gBAAgB,CAAC,EAAE,WAAW,CAAC,WAAW;IAC1D,CAAC,cAAc,CAAC,kBAAkB,CAAC,EAAE,WAAW,CAAC,aAAa;IAC9D,CAAC,cAAc,CAAC,iBAAiB,CAAC,EAAE,WAAW,CAAC,cAAc;IAC9D,CAAC,cAAc,CAAC,mBAAmB,CAAC,EAA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CAAC,cAAc,EAAE;YACnB,OAAO,WAAW,CAAC,OAAO,CAAC;SAC5B;QACD,OAAO,mBAAmB,CAAC,cAAc,CAAC,CAAC;IAC7C,CAAC;IACD,KAAK,CAAC,SAAS,CAAC,eAAgC;QAC9C,MAAM,kBAAkB,GAAG,uBAAuB,CAAC,eAAe,CAAC,CAAC;QACpE,IAAI,CAAC,kBAAkB,EAAE;YACvB,MAAM,IAAI,SAAS,CAAC,6BAA6B,eAAe,EAAE,CAAC,CAAC;SACrE;QACD,MAAM,UAAU,CAAC,kBAAkB,CAAC,CAAC;IACvC,CAAC;IACD,KAAK,CAAC,iBAAiB,CAAC,kBAAsC;QAC5D,MAAM,UAAU,CAAC,kBAAkB,CAAC,CAAC;QACrC,uBAAuB,GAAG,kBAAkB,CAAC;IAC/C,CAAC;IACD,KAAK,CAAC,WAAW;QACf,IAAI,MAAM,CAAC,WAAW,IAAI,MAAM,CAAC,WAAW,CAAC,MAAM,EAAE;YACnD,MAAM,CAAC,WAAW,CAAC,MAAM,EAAE,CAAC;SAC7B;aAAM,IACL,MAAM,CAAC,mBAAmB,CAAC;YAC3B,MAAM,CAAC,sBAAsB,CAAC;YAC9B,MAAM,CAAC,qBAAqB,CAAC,EAC7B;YACA,MAAM,iBAAiB,GACrB,MAAM,CAAC,mBAAmB,CAAC;gBAC3B,MAAM,CAAC,sBAAsB,CAAC;gBAC9B,MAAM,CAAC,qBAAqB,CAAC,CAAC;YAChC,0FAA0F;YAC1F,MAAM,SAAS,GAAG,iBAAiB,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;YACjD,IAAI,CAAC,SAAS,EAAE;gBACd,MAAM,IAAI,KAAK,CAAC,mDAAmD,CAAC,CAAC;aACtE;SACF;aAAM;YACL,MAAM,IAAI,KAAK,CACb,oFAAoF,CACrF,CAAC;SACH;IACH,CAAC;CACF,CAAC","sourcesContent":["import { Platform } from 'expo-modules-core';\nimport { DeviceEventEmitter } from 'react-native';\n\nimport { getOrientationLockAsync, getOrientationAsync } from './ScreenOrientation';\nimport {\n Orientation,\n OrientationLock,\n WebOrientationLock,\n WebOrientation,\n} from './ScreenOrientation.types';\n\nconst OrientationLockAPIToWeb: {\n [lock: string]: WebOrientationLock;\n} = {\n [OrientationLock.DEFAULT]: WebOrientationLock.NATURAL,\n [OrientationLock.ALL]: WebOrientationLock.ANY,\n [OrientationLock.PORTRAIT]: WebOrientationLock.PORTRAIT,\n [OrientationLock.PORTRAIT_UP]: WebOrientationLock.PORTRAIT_PRIMARY,\n [OrientationLock.PORTRAIT_DOWN]: WebOrientationLock.PORTRAIT_SECONDARY,\n [OrientationLock.LANDSCAPE]: WebOrientationLock.LANDSCAPE,\n [OrientationLock.LANDSCAPE_LEFT]: WebOrientationLock.LANDSCAPE_PRIMARY,\n [OrientationLock.LANDSCAPE_RIGHT]: WebOrientationLock.LANDSCAPE_SECONDARY,\n};\n\nconst OrientationWebToAPI: {\n [orientationWeb: string]: Orientation;\n} = {\n [WebOrientation.PORTRAIT_PRIMARY]: Orientation.PORTRAIT_UP,\n [WebOrientation.PORTRAIT_SECONDARY]: Orientation.PORTRAIT_DOWN,\n [WebOrientation.LANDSCAPE_PRIMARY]: Orientation.LANDSCAPE_LEFT,\n [WebOrientation.LANDSCAPE_SECONDARY]: Orientation.LANDSCAPE_RIGHT,\n};\n\ndeclare const window: Window;\n\nconst screen: Screen = Platform.canUseViewport ? window.screen : ({} as Screen);\nconst orientation: ScreenOrientation | null = Platform.canUseViewport\n ? screen.orientation || (screen as any).msOrientation || null\n : null;\n\nasync function emitOrientationEvent() {\n const [orientationLock, orientation] = await Promise.all([\n getOrientationLockAsync(),\n getOrientationAsync(),\n ]);\n DeviceEventEmitter.emit('expoDidUpdateDimensions', {\n orientationLock,\n orientationInfo: { orientation },\n });\n}\n\nif (Platform.canUseEventListeners) {\n if (orientation && orientation.addEventListener) {\n orientation.addEventListener('change', emitOrientationEvent);\n } else {\n window.addEventListener('orientationchange', emitOrientationEvent);\n }\n}\n\nfunction _convertToLegacyOrientationLock(orientationLock: WebOrientationLock): string | string[] {\n switch (orientationLock) {\n case WebOrientationLock.UNKNOWN:\n throw new Error(\n `expo-screen-orientation: WebOrientationLock.UNKNOWN is not a valid lock to be converted.`\n );\n case WebOrientationLock.ANY:\n return ['portrait', 'landscape'];\n case WebOrientationLock.NATURAL:\n return 'default';\n default:\n return orientationLock;\n }\n}\n\nasync function _lockAsync(webOrientationLock: WebOrientationLock): Promise<void> {\n if (webOrientationLock === WebOrientationLock.UNKNOWN) {\n throw new Error(\n `expo-screen-orientation: WebOrientationLock.UNKNOWN is not a valid lock that can be applied to the device.`\n );\n }\n // @ts-ignore-error: This is missing in the TypeScript definitions\n if (screen.orientation && screen.orientation.lock) {\n // @ts-ignore-error\n await screen.orientation.lock(webOrientationLock);\n } else if (\n screen['lockOrientation'] ||\n screen['mozLockOrientation'] ||\n screen['msLockOrientation']\n ) {\n const legacyLock = _convertToLegacyOrientationLock(webOrientationLock);\n const lockOrientation =\n screen['lockOrientation'] || screen['mozLockOrientation'] || screen['msLockOrientation'];\n // correct `this` context must be passed in otherwise method call is disallowed by browser\n const isSuccess = lockOrientation.call(screen, legacyLock);\n if (!isSuccess) {\n throw new Error(\n `Applying orientation lock: ${JSON.stringify(webOrientationLock)} to device was denied`\n );\n }\n } else {\n throw new Error(\n `expo-screen-orientation: The browser doesn't support locking screen orientation.`\n );\n }\n}\n\nlet _lastWebOrientationLock: WebOrientationLock = WebOrientationLock.UNKNOWN;\n\nexport default {\n async supportsOrientationLockAsync(orientationLock: OrientationLock): Promise<boolean> {\n return orientationLock in OrientationLockAPIToWeb;\n },\n async getPlatformOrientationLockAsync(): Promise<WebOrientationLock> {\n return _lastWebOrientationLock;\n },\n async getOrientationAsync(): Promise<Orientation> {\n const webOrientation =\n screen['msOrientation'] || (screen.orientation || screen['mozOrientation'] || {}).type;\n if (!webOrientation) {\n return Orientation.UNKNOWN;\n }\n return OrientationWebToAPI[webOrientation];\n },\n async lockAsync(orientationLock: OrientationLock): Promise<void> {\n const webOrientationLock = OrientationLockAPIToWeb[orientationLock];\n if (!webOrientationLock) {\n throw new TypeError(`Invalid Orientation Lock: ${orientationLock}`);\n }\n await _lockAsync(webOrientationLock);\n },\n async lockPlatformAsync(webOrientationLock: WebOrientationLock): Promise<void> {\n await _lockAsync(webOrientationLock);\n _lastWebOrientationLock = webOrientationLock;\n },\n async unlockAsync(): Promise<void> {\n if (screen.orientation && screen.orientation.unlock) {\n screen.orientation.unlock();\n } else if (\n screen['unlockOrientation'] ||\n screen['mozUnlockOrientation'] ||\n screen['msUnlockOrientation']\n ) {\n const unlockOrientation =\n screen['unlockOrientation'] ||\n screen['mozUnlockOrientation'] ||\n screen['msUnlockOrientation'];\n // correct `this` context must be passed in otherwise method call is disallowed by browser\n const isSuccess = unlockOrientation.call(screen);\n if (!isSuccess) {\n throw new Error(`Unlocking screen orientation on device was denied`);\n }\n } else {\n throw new Error(\n `expo-screen-orientation: The browser doesn't support unlocking screen orientation.`\n );\n }\n },\n};\n"]}
1
+ {"version":3,"file":"ExpoScreenOrientation.web.js","sourceRoot":"","sources":["../src/ExpoScreenOrientation.web.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAE9E,OAAO,EAAE,uBAAuB,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AACnF,OAAO,EACL,WAAW,EACX,eAAe,EACf,kBAAkB,EAClB,cAAc,GAEf,MAAM,2BAA2B,CAAC;AAEnC,MAAM,uBAAuB,GAEzB;IACF,CAAC,eAAe,CAAC,OAAO,CAAC,EAAE,kBAAkB,CAAC,OAAO;IACrD,CAAC,eAAe,CAAC,GAAG,CAAC,EAAE,kBAAkB,CAAC,GAAG;IAC7C,CAAC,eAAe,CAAC,QAAQ,CAAC,EAAE,kBAAkB,CAAC,QAAQ;IACvD,CAAC,eAAe,CAAC,WAAW,CAAC,EAAE,kBAAkB,CAAC,gBAAgB;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,CAAC,eAAe,CAAC,CAAC;QACpE,IAAI,CAAC,kBAAkB,EAAE;YACvB,MAAM,IAAI,SAAS,CAAC,6BAA6B,eAAe,EAAE,CAAC,CAAC;SACrE;QACD,MAAM,UAAU,CAAC,kBAAkB,CAAC,CAAC;IACvC,CAAC;IACD,KAAK,CAAC,iBAAiB,CAAC,kBAAsC;QAC5D,MAAM,UAAU,CAAC,kBAAkB,CAAC,CAAC;QACrC,uBAAuB,GAAG,kBAAkB,CAAC;IAC/C,CAAC;IACD,KAAK,CAAC,WAAW;QACf,IAAI,MAAM,CAAC,WAAW,IAAI,MAAM,CAAC,WAAW,CAAC,MAAM,EAAE;YACnD,MAAM,CAAC,WAAW,CAAC,MAAM,EAAE,CAAC;SAC7B;aAAM,IACL,MAAM,CAAC,mBAAmB,CAAC;YAC3B,MAAM,CAAC,sBAAsB,CAAC;YAC9B,MAAM,CAAC,qBAAqB,CAAC,EAC7B;YACA,MAAM,iBAAiB,GACrB,MAAM,CAAC,mBAAmB,CAAC;gBAC3B,MAAM,CAAC,sBAAsB,CAAC;gBAC9B,MAAM,CAAC,qBAAqB,CAAC,CAAC;YAChC,0FAA0F;YAC1F,MAAM,SAAS,GAAG,iBAAiB,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;YACjD,IAAI,CAAC,SAAS,EAAE;gBACd,MAAM,IAAI,KAAK,CAAC,mDAAmD,CAAC,CAAC;aACtE;SACF;aAAM;YACL,MAAM,IAAI,KAAK,CACb,oFAAoF,CACrF,CAAC;SACH;IACH,CAAC;CACF;AAED,eAAe,iBAAiB,CAAC,qBAAqB,CAAC,CAAC","sourcesContent":["import { NativeModule, Platform, registerWebModule } from 'expo-modules-core';\n\nimport { getOrientationLockAsync, getOrientationAsync } from './ScreenOrientation';\nimport {\n Orientation,\n OrientationLock,\n WebOrientationLock,\n WebOrientation,\n ExpoOrientationEvents,\n} from './ScreenOrientation.types';\n\nconst OrientationLockAPIToWeb: {\n [lock: string]: WebOrientationLock;\n} = {\n [OrientationLock.DEFAULT]: WebOrientationLock.NATURAL,\n [OrientationLock.ALL]: WebOrientationLock.ANY,\n [OrientationLock.PORTRAIT]: WebOrientationLock.PORTRAIT,\n [OrientationLock.PORTRAIT_UP]: WebOrientationLock.PORTRAIT_PRIMARY,\n [OrientationLock.PORTRAIT_DOWN]: WebOrientationLock.PORTRAIT_SECONDARY,\n [OrientationLock.LANDSCAPE]: WebOrientationLock.LANDSCAPE,\n [OrientationLock.LANDSCAPE_LEFT]: WebOrientationLock.LANDSCAPE_PRIMARY,\n [OrientationLock.LANDSCAPE_RIGHT]: WebOrientationLock.LANDSCAPE_SECONDARY,\n};\n\nconst OrientationWebToAPI: {\n [orientationWeb: string]: Orientation;\n} = {\n [WebOrientation.PORTRAIT_PRIMARY]: Orientation.PORTRAIT_UP,\n [WebOrientation.PORTRAIT_SECONDARY]: Orientation.PORTRAIT_DOWN,\n [WebOrientation.LANDSCAPE_PRIMARY]: Orientation.LANDSCAPE_LEFT,\n [WebOrientation.LANDSCAPE_SECONDARY]: Orientation.LANDSCAPE_RIGHT,\n};\n\ndeclare const window: Window;\n\nconst screen: Screen = Platform.canUseViewport ? window.screen : ({} as Screen);\n\nfunction _convertToLegacyOrientationLock(orientationLock: WebOrientationLock): string | string[] {\n switch (orientationLock) {\n case WebOrientationLock.UNKNOWN:\n throw new Error(\n `expo-screen-orientation: WebOrientationLock.UNKNOWN is not a valid lock to be converted.`\n );\n case WebOrientationLock.ANY:\n return ['portrait', 'landscape'];\n case WebOrientationLock.NATURAL:\n return 'default';\n default:\n return orientationLock;\n }\n}\n\nasync function _lockAsync(webOrientationLock: WebOrientationLock): Promise<void> {\n if (webOrientationLock === WebOrientationLock.UNKNOWN) {\n throw new Error(\n `expo-screen-orientation: WebOrientationLock.UNKNOWN is not a valid lock that can be applied to the device.`\n );\n }\n // @ts-ignore-error: This is missing in the TypeScript definitions\n if (screen.orientation && screen.orientation.lock) {\n // @ts-ignore-error\n await screen.orientation.lock(webOrientationLock);\n } else if (\n screen['lockOrientation'] ||\n screen['mozLockOrientation'] ||\n screen['msLockOrientation']\n ) {\n const legacyLock = _convertToLegacyOrientationLock(webOrientationLock);\n const lockOrientation =\n screen['lockOrientation'] || screen['mozLockOrientation'] || screen['msLockOrientation'];\n // correct `this` context must be passed in otherwise method call is disallowed by browser\n const isSuccess = lockOrientation.call(screen, legacyLock);\n if (!isSuccess) {\n throw new Error(\n `Applying orientation lock: ${JSON.stringify(webOrientationLock)} to device was denied`\n );\n }\n } else {\n throw new Error(\n `expo-screen-orientation: The browser doesn't support locking screen orientation.`\n );\n }\n}\n\nlet _lastWebOrientationLock: WebOrientationLock = WebOrientationLock.UNKNOWN;\n\nclass ExpoScreenOrientation extends NativeModule<ExpoOrientationEvents> {\n orientation: ScreenOrientation | null = Platform.canUseViewport\n ? screen.orientation || (screen as any).msOrientation || null\n : null;\n async emitOrientationEvent() {\n const [orientationLock, orientation] = await Promise.all([\n getOrientationLockAsync(),\n getOrientationAsync(),\n ]);\n this.emit('expoDidUpdateDimensions', {\n orientationLock,\n orientationInfo: { orientation },\n });\n }\n startObserving() {\n this.listener = () => this.emitOrientationEvent();\n if (Platform.canUseEventListeners) {\n if (this.orientation && this.orientation.addEventListener) {\n this.orientation.addEventListener('change', this.listener);\n } else {\n window.addEventListener('orientationchange', this.listener);\n }\n }\n }\n stopObserving(): void {\n if (Platform.canUseEventListeners) {\n if (this.orientation && this.orientation.removeEventListener) {\n this.orientation.removeEventListener('change', this.listener);\n } else {\n window.removeEventListener('orientationchange', this.listener);\n }\n }\n }\n async supportsOrientationLockAsync(orientationLock: OrientationLock): Promise<boolean> {\n return orientationLock in OrientationLockAPIToWeb;\n }\n async getPlatformOrientationLockAsync(): Promise<WebOrientationLock> {\n return _lastWebOrientationLock;\n }\n async getOrientationAsync(): Promise<Orientation> {\n const webOrientation =\n screen['msOrientation'] || (screen.orientation || screen['mozOrientation'] || {}).type;\n if (!webOrientation) {\n return Orientation.UNKNOWN;\n }\n return OrientationWebToAPI[webOrientation];\n }\n async lockAsync(orientationLock: OrientationLock): Promise<void> {\n const webOrientationLock = OrientationLockAPIToWeb[orientationLock];\n if (!webOrientationLock) {\n throw new TypeError(`Invalid Orientation Lock: ${orientationLock}`);\n }\n await _lockAsync(webOrientationLock);\n }\n async lockPlatformAsync(webOrientationLock: WebOrientationLock): Promise<void> {\n await _lockAsync(webOrientationLock);\n _lastWebOrientationLock = webOrientationLock;\n }\n async unlockAsync(): Promise<void> {\n if (screen.orientation && screen.orientation.unlock) {\n screen.orientation.unlock();\n } else if (\n screen['unlockOrientation'] ||\n screen['mozUnlockOrientation'] ||\n screen['msUnlockOrientation']\n ) {\n const unlockOrientation =\n screen['unlockOrientation'] ||\n screen['mozUnlockOrientation'] ||\n screen['msUnlockOrientation'];\n // correct `this` context must be passed in otherwise method call is disallowed by browser\n const isSuccess = unlockOrientation.call(screen);\n if (!isSuccess) {\n throw new Error(`Unlocking screen orientation on device was denied`);\n }\n } else {\n throw new Error(\n `expo-screen-orientation: The browser doesn't support unlocking screen orientation.`\n );\n }\n }\n}\n\nexport default registerWebModule(ExpoScreenOrientation);\n"]}
@@ -149,4 +149,7 @@ export type OrientationChangeEvent = {
149
149
  */
150
150
  orientationInfo: ScreenOrientationInfo;
151
151
  };
152
+ export type ExpoOrientationEvents = {
153
+ expoDidUpdateDimensions: OrientationChangeListener;
154
+ };
152
155
  //# sourceMappingURL=ScreenOrientation.types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ScreenOrientation.types.d.ts","sourceRoot":"","sources":["../src/ScreenOrientation.types.ts"],"names":[],"mappings":"AACA,oBAAY,WAAW;IACrB;;OAEG;IACH,OAAO,IAAI;IACX;;OAEG;IACH,WAAW,IAAI;IACf;;OAEG;IACH,aAAa,IAAI;IACjB;;OAEG;IACH,cAAc,IAAI;IAClB;;OAEG;IACH,eAAe,IAAI;CACpB;AAGD;;;;;GAKG;AACH,oBAAY,eAAe;IACzB;;;OAGG;IACH,OAAO,IAAI;IACX;;OA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ACH,eAAe,EAAE,eAAe,CAAC;IACjC;;OAEG;IACH,eAAe,EAAE,qBAAqB,CAAC;CACxC,CAAC"}
1
+ {"version":3,"file":"ScreenOrientation.types.d.ts","sourceRoot":"","sources":["../src/ScreenOrientation.types.ts"],"names":[],"mappings":"AACA,oBAAY,WAAW;IACrB;;OAEG;IACH,OAAO,IAAI;IACX;;OAEG;IACH,WAAW,IAAI;IACf;;OAEG;IACH,aAAa,IAAI;IACjB;;OAEG;IACH,cAAc,IAAI;IAClB;;OAEG;IACH,eAAe,IAAI;CACpB;AAGD;;;;;GAKG;AACH,oBAAY,eAAe;IACzB;;;OAGG;IACH,OAAO,IAAI;IACX;;OAEG;IACH,GAAG,IAAI;IACP;;OAEG;IACH,QAAQ,IAAI;IACZ;;OAEG;IACH,WAAW,IAAI;IACf;;OAEG;IACH,aAAa,IAAI;IACjB;;OAEG;IACH,SAAS,IAAI;IACb;;OAEG;IACH,cAAc,IAAI;IAClB;;OAEG;IACH,eAAe,IAAI;IACnB;;OAEG;IACH,KAAK,IAAI;IACT;;OAEG;IACH,OAAO,IAAI;CACZ;AAGD;;;GAGG;AACH,oBAAY,YAAY;IACtB,OAAO,IAAI;IACX,OAAO,IAAI;IACX,OAAO,IAAI;CACZ;AAGD;;;;;GAKG;AACH,oBAAY,kBAAkB;IAC5B,gBAAgB,qBAAqB;IACrC,kBAAkB,uBAAuB;IACzC,QAAQ,aAAa;IACrB,iBAAiB,sBAAsB;IACvC,mBAAmB,wBAAwB;IAC3C,SAAS,cAAc;IACvB,GAAG,QAAQ;IACX,OAAO,YAAY;IACnB,OAAO,YAAY;CACpB;AAGD,oBAAY,cAAc;IACxB,gBAAgB,qBAAqB;IACrC,kBAAkB,uBAAuB;IACzC,iBAAiB,sBAAsB;IACvC,mBAAmB,wBAAwB;CAC5C;AAGD,MAAM,MAAM,uBAAuB,GAAG;IACpC;;;;;OAKG;IACH,gCAAgC,CAAC,EAAE,MAAM,CAAC;IAC1C;;;OAGG;IACH,yBAAyB,CAAC,EAAE,WAAW,EAAE,CAAC;IAC1C;;;OAGG;IACH,wBAAwB,CAAC,EAAE,kBAAkB,CAAC;CAC/C,CAAC;AAGF,MAAM,MAAM,qBAAqB,GAAG;IAClC;;OAEG;IACH,WAAW,EAAE,WAAW,CAAC;IACzB;;;;OAIG;IACH,iBAAiB,CAAC,EAAE,YAAY,CAAC;IACjC;;;;OAIG;IACH,mBAAmB,CAAC,EAAE,YAAY,CAAC;CACpC,CAAC;AAEF,MAAM,MAAM,yBAAyB,GAAG,CAAC,KAAK,EAAE,sBAAsB,KAAK,IAAI,CAAC;AAGhF,MAAM,MAAM,sBAAsB,GAAG;IACnC;;OAEG;IACH,eAAe,EAAE,eAAe,CAAC;IACjC;;OAEG;IACH,eAAe,EAAE,qBAAqB,CAAC;CACxC,CAAC;AAEF,MAAM,MAAM,qBAAqB,GAAG;IAClC,uBAAuB,EAAE,yBAAyB,CAAC;CACpD,CAAC"}
@@ -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/documentation/uikit/uiuserinterfacesizeclass)\n * that you can use as a guide when designing your interface.\n */\nexport enum SizeClassIOS {\n UNKNOWN = 0,\n COMPACT = 1,\n REGULAR = 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#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/documentation/uikit/uitraitcollection/1623513-verticalsizeclass)\n * of the device.\n * @platform ios\n */\n verticalSizeClass?: SizeClassIOS;\n /**\n * The [horizontal size class](https://developer.apple.com/documentation/uikit/uitraitcollection/1623508-horizontalsizeclass)\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"]}
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/documentation/uikit/uiuserinterfacesizeclass)\n * that you can use as a guide when designing your interface.\n */\nexport enum SizeClassIOS {\n UNKNOWN = 0,\n COMPACT = 1,\n REGULAR = 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#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/documentation/uikit/uitraitcollection/1623513-verticalsizeclass)\n * of the device.\n * @platform ios\n */\n verticalSizeClass?: SizeClassIOS;\n /**\n * The [horizontal size class](https://developer.apple.com/documentation/uikit/uitraitcollection/1623508-horizontalsizeclass)\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\nexport type ExpoOrientationEvents = {\n expoDidUpdateDimensions: OrientationChangeListener;\n};\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "expo-screen-orientation",
3
- "version": "8.0.0",
3
+ "version": "8.0.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",
@@ -42,5 +42,5 @@
42
42
  "expo": "*",
43
43
  "react-native": "*"
44
44
  },
45
- "gitHead": "685ebb8a213326cb33c80281ca8756b374ccb63d"
45
+ "gitHead": "26675b98e703230441234a1fcc149e38309a59e1"
46
46
  }
@@ -1,5 +1,4 @@
1
- import { Platform } from 'expo-modules-core';
2
- import { DeviceEventEmitter } from 'react-native';
1
+ import { NativeModule, Platform, registerWebModule } from 'expo-modules-core';
3
2
 
4
3
  import { getOrientationLockAsync, getOrientationAsync } from './ScreenOrientation';
5
4
  import {
@@ -7,6 +6,7 @@ import {
7
6
  OrientationLock,
8
7
  WebOrientationLock,
9
8
  WebOrientation,
9
+ ExpoOrientationEvents,
10
10
  } from './ScreenOrientation.types';
11
11
 
12
12
  const OrientationLockAPIToWeb: {
@@ -34,28 +34,6 @@ const OrientationWebToAPI: {
34
34
  declare const window: Window;
35
35
 
36
36
  const screen: Screen = Platform.canUseViewport ? window.screen : ({} as Screen);
37
- const orientation: ScreenOrientation | null = Platform.canUseViewport
38
- ? screen.orientation || (screen as any).msOrientation || null
39
- : null;
40
-
41
- async function emitOrientationEvent() {
42
- const [orientationLock, orientation] = await Promise.all([
43
- getOrientationLockAsync(),
44
- getOrientationAsync(),
45
- ]);
46
- DeviceEventEmitter.emit('expoDidUpdateDimensions', {
47
- orientationLock,
48
- orientationInfo: { orientation },
49
- });
50
- }
51
-
52
- if (Platform.canUseEventListeners) {
53
- if (orientation && orientation.addEventListener) {
54
- orientation.addEventListener('change', emitOrientationEvent);
55
- } else {
56
- window.addEventListener('orientationchange', emitOrientationEvent);
57
- }
58
- }
59
37
 
60
38
  function _convertToLegacyOrientationLock(orientationLock: WebOrientationLock): string | string[] {
61
39
  switch (orientationLock) {
@@ -106,13 +84,45 @@ async function _lockAsync(webOrientationLock: WebOrientationLock): Promise<void>
106
84
 
107
85
  let _lastWebOrientationLock: WebOrientationLock = WebOrientationLock.UNKNOWN;
108
86
 
109
- export default {
87
+ class ExpoScreenOrientation extends NativeModule<ExpoOrientationEvents> {
88
+ orientation: ScreenOrientation | null = Platform.canUseViewport
89
+ ? screen.orientation || (screen as any).msOrientation || null
90
+ : null;
91
+ async emitOrientationEvent() {
92
+ const [orientationLock, orientation] = await Promise.all([
93
+ getOrientationLockAsync(),
94
+ getOrientationAsync(),
95
+ ]);
96
+ this.emit('expoDidUpdateDimensions', {
97
+ orientationLock,
98
+ orientationInfo: { orientation },
99
+ });
100
+ }
101
+ startObserving() {
102
+ this.listener = () => this.emitOrientationEvent();
103
+ if (Platform.canUseEventListeners) {
104
+ if (this.orientation && this.orientation.addEventListener) {
105
+ this.orientation.addEventListener('change', this.listener);
106
+ } else {
107
+ window.addEventListener('orientationchange', this.listener);
108
+ }
109
+ }
110
+ }
111
+ stopObserving(): void {
112
+ if (Platform.canUseEventListeners) {
113
+ if (this.orientation && this.orientation.removeEventListener) {
114
+ this.orientation.removeEventListener('change', this.listener);
115
+ } else {
116
+ window.removeEventListener('orientationchange', this.listener);
117
+ }
118
+ }
119
+ }
110
120
  async supportsOrientationLockAsync(orientationLock: OrientationLock): Promise<boolean> {
111
121
  return orientationLock in OrientationLockAPIToWeb;
112
- },
122
+ }
113
123
  async getPlatformOrientationLockAsync(): Promise<WebOrientationLock> {
114
124
  return _lastWebOrientationLock;
115
- },
125
+ }
116
126
  async getOrientationAsync(): Promise<Orientation> {
117
127
  const webOrientation =
118
128
  screen['msOrientation'] || (screen.orientation || screen['mozOrientation'] || {}).type;
@@ -120,18 +130,18 @@ export default {
120
130
  return Orientation.UNKNOWN;
121
131
  }
122
132
  return OrientationWebToAPI[webOrientation];
123
- },
133
+ }
124
134
  async lockAsync(orientationLock: OrientationLock): Promise<void> {
125
135
  const webOrientationLock = OrientationLockAPIToWeb[orientationLock];
126
136
  if (!webOrientationLock) {
127
137
  throw new TypeError(`Invalid Orientation Lock: ${orientationLock}`);
128
138
  }
129
139
  await _lockAsync(webOrientationLock);
130
- },
140
+ }
131
141
  async lockPlatformAsync(webOrientationLock: WebOrientationLock): Promise<void> {
132
142
  await _lockAsync(webOrientationLock);
133
143
  _lastWebOrientationLock = webOrientationLock;
134
- },
144
+ }
135
145
  async unlockAsync(): Promise<void> {
136
146
  if (screen.orientation && screen.orientation.unlock) {
137
147
  screen.orientation.unlock();
@@ -154,5 +164,7 @@ export default {
154
164
  `expo-screen-orientation: The browser doesn't support unlocking screen orientation.`
155
165
  );
156
166
  }
157
- },
158
- };
167
+ }
168
+ }
169
+
170
+ export default registerWebModule(ExpoScreenOrientation);
@@ -165,3 +165,7 @@ export type OrientationChangeEvent = {
165
165
  */
166
166
  orientationInfo: ScreenOrientationInfo;
167
167
  };
168
+
169
+ export type ExpoOrientationEvents = {
170
+ expoDidUpdateDimensions: OrientationChangeListener;
171
+ };