From 31f7931e89bab0ae64852479270c9495988e9cc9 Mon Sep 17 00:00:00 2001 From: Alec Winograd Date: Thu, 9 Apr 2020 12:21:18 -0500 Subject: [PATCH 1/3] [expo-screen-orientation][web] fix emitted expoDidUpdateDimensions payload --- .../expo-screen-orientation/build/ExpoScreenOrientation.web.js | 2 +- .../build/ExpoScreenOrientation.web.js.map | 2 +- .../expo-screen-orientation/src/ExpoScreenOrientation.web.ts | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/expo-screen-orientation/build/ExpoScreenOrientation.web.js b/packages/expo-screen-orientation/build/ExpoScreenOrientation.web.js index 367010d57fe42..5bbf858de4d06 100644 --- a/packages/expo-screen-orientation/build/ExpoScreenOrientation.web.js +++ b/packages/expo-screen-orientation/build/ExpoScreenOrientation.web.js @@ -27,7 +27,7 @@ async function emitOrientationEvent() { ]); SyntheticPlatformEmitter.emit('expoDidUpdateDimensions', { orientationLock, - orientation, + orientationInfo: { orientation }, }); } if (canUseEventListeners) { diff --git a/packages/expo-screen-orientation/build/ExpoScreenOrientation.web.js.map b/packages/expo-screen-orientation/build/ExpoScreenOrientation.web.js.map index 45a95246aba76..fd5370cad9e5b 100644 --- a/packages/expo-screen-orientation/build/ExpoScreenOrientation.web.js.map +++ b/packages/expo-screen-orientation/build/ExpoScreenOrientation.web.js.map @@ -1 +1 @@ -{"version":3,"file":"ExpoScreenOrientation.web.js","sourceRoot":"","sources":["../src/ExpoScreenOrientation.web.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,MAAM,kBAAkB,CAAC;AAC5D,OAAO,EAAE,cAAc,EAAE,oBAAoB,EAAE,MAAM,+BAA+B,CAAC;AAErF,OAAO,EAAE,uBAAuB,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AACnF,OAAO,EACL,WAAW,EAEX,kBAAkB,EAClB,cAAc,GACf,MAAM,2BAA2B,CAAC;AAEnC,MAAM,uBAAuB,GAEzB;IACF,OAAO,EAAE,k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AC7B;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 { SyntheticPlatformEmitter } from '@unimodules/core';\nimport { canUseViewport, canUseEventListeners } from 'fbjs/lib/ExecutionEnvironment';\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 DEFAULT: WebOrientationLock.NATURAL,\n ALL: WebOrientationLock.ANY,\n PORTRAIT: WebOrientationLock.PORTRAIT,\n PORTRAIT_UP: WebOrientationLock.PORTRAIT_PRIMARY,\n PORTRAIT_DOWN: WebOrientationLock.PORTRAIT_SECONDARY,\n LANDSCAPE: WebOrientationLock.LANDSCAPE,\n LANDSCAPE_LEFT: WebOrientationLock.LANDSCAPE_PRIMARY,\n 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 } = canUseViewport && window;\nconst orientation: ScreenOrientation | null =\n canUseViewport && (screen.orientation || (screen as any).msOrientation || null);\n\nasync function emitOrientationEvent() {\n const [orientationLock, orientation] = await Promise.all([\n getOrientationLockAsync(),\n getOrientationAsync(),\n ]);\n SyntheticPlatformEmitter.emit('expoDidUpdateDimensions', {\n orientationLock,\n orientation,\n });\n}\n\nif (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 {\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 if (screen.orientation && screen.orientation.lock) {\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 get name(): string {\n return 'ExpoScreenOrientation';\n },\n async supportsOrientationLockAsync(orientationLock: OrientationLock): Promise {\n return orientationLock in OrientationLockAPIToWeb;\n },\n async getPlatformOrientationLockAsync(): Promise {\n return _lastWebOrientationLock;\n },\n async getOrientationAsync(): Promise {\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 {\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 {\n await _lockAsync(webOrientationLock);\n _lastWebOrientationLock = webOrientationLock;\n },\n async unlockAsync(): Promise {\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"]} \ No newline at end of file +{"version":3,"file":"ExpoScreenOrientation.web.js","sourceRoot":"","sources":["../src/ExpoScreenOrientation.web.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,MAAM,kBAAkB,CAAC;AAC5D,OAAO,EAAE,cAAc,EAAE,oBAAoB,EAAE,MAAM,+BAA+B,CAAC;AAErF,OAAO,EAAE,uBAAuB,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAA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AAC,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 { SyntheticPlatformEmitter } from '@unimodules/core';\nimport { canUseViewport, canUseEventListeners } from 'fbjs/lib/ExecutionEnvironment';\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 DEFAULT: WebOrientationLock.NATURAL,\n ALL: WebOrientationLock.ANY,\n PORTRAIT: WebOrientationLock.PORTRAIT,\n PORTRAIT_UP: WebOrientationLock.PORTRAIT_PRIMARY,\n PORTRAIT_DOWN: WebOrientationLock.PORTRAIT_SECONDARY,\n LANDSCAPE: WebOrientationLock.LANDSCAPE,\n LANDSCAPE_LEFT: WebOrientationLock.LANDSCAPE_PRIMARY,\n 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 } = canUseViewport && window;\nconst orientation: ScreenOrientation | null =\n canUseViewport && (screen.orientation || (screen as any).msOrientation || null);\n\nasync function emitOrientationEvent() {\n const [orientationLock, orientation] = await Promise.all([\n getOrientationLockAsync(),\n getOrientationAsync(),\n ]);\n SyntheticPlatformEmitter.emit('expoDidUpdateDimensions', {\n orientationLock,\n orientationInfo: { orientation },\n });\n}\n\nif (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 {\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 if (screen.orientation && screen.orientation.lock) {\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 get name(): string {\n return 'ExpoScreenOrientation';\n },\n async supportsOrientationLockAsync(orientationLock: OrientationLock): Promise {\n return orientationLock in OrientationLockAPIToWeb;\n },\n async getPlatformOrientationLockAsync(): Promise {\n return _lastWebOrientationLock;\n },\n async getOrientationAsync(): Promise {\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 {\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 {\n await _lockAsync(webOrientationLock);\n _lastWebOrientationLock = webOrientationLock;\n },\n async unlockAsync(): Promise {\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"]} \ No newline at end of file diff --git a/packages/expo-screen-orientation/src/ExpoScreenOrientation.web.ts b/packages/expo-screen-orientation/src/ExpoScreenOrientation.web.ts index 28f6120a9f2b1..bfd70c693452e 100644 --- a/packages/expo-screen-orientation/src/ExpoScreenOrientation.web.ts +++ b/packages/expo-screen-orientation/src/ExpoScreenOrientation.web.ts @@ -44,7 +44,7 @@ async function emitOrientationEvent() { ]); SyntheticPlatformEmitter.emit('expoDidUpdateDimensions', { orientationLock, - orientation, + orientationInfo: { orientation }, }); } From c6214fed311d5ed2e122a1a39c9bf8056c0870bb Mon Sep 17 00:00:00 2001 From: Alec Winograd Date: Thu, 9 Apr 2020 12:28:08 -0500 Subject: [PATCH 2/3] [expo-screen-orientation][web] fix OrientationLockAPIToWeb keys --- .../build/ExpoScreenOrientation.web.js | 18 +++++++++--------- .../build/ExpoScreenOrientation.web.js.map | 2 +- .../src/ExpoScreenOrientation.web.ts | 16 ++++++++-------- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/packages/expo-screen-orientation/build/ExpoScreenOrientation.web.js b/packages/expo-screen-orientation/build/ExpoScreenOrientation.web.js index 5bbf858de4d06..a4a22511391e8 100644 --- a/packages/expo-screen-orientation/build/ExpoScreenOrientation.web.js +++ b/packages/expo-screen-orientation/build/ExpoScreenOrientation.web.js @@ -1,16 +1,16 @@ import { SyntheticPlatformEmitter } from '@unimodules/core'; import { canUseViewport, canUseEventListeners } from 'fbjs/lib/ExecutionEnvironment'; import { getOrientationLockAsync, getOrientationAsync } from './ScreenOrientation'; -import { Orientation, WebOrientationLock, WebOrientation, } from './ScreenOrientation.types'; +import { Orientation, OrientationLock, WebOrientationLock, WebOrientation, } from './ScreenOrientation.types'; const OrientationLockAPIToWeb = { - DEFAULT: WebOrientationLock.NATURAL, - ALL: WebOrientationLock.ANY, - PORTRAIT: WebOrientationLock.PORTRAIT, - PORTRAIT_UP: WebOrientationLock.PORTRAIT_PRIMARY, - PORTRAIT_DOWN: WebOrientationLock.PORTRAIT_SECONDARY, - LANDSCAPE: WebOrientationLock.LANDSCAPE, - LANDSCAPE_LEFT: WebOrientationLock.LANDSCAPE_PRIMARY, - LANDSCAPE_RIGHT: WebOrientationLock.LANDSCAPE_SECONDARY, + [OrientationLock.DEFAULT]: WebOrientationLock.NATURAL, + [OrientationLock.ALL]: WebOrientationLock.ANY, + [OrientationLock.PORTRAIT]: WebOrientationLock.PORTRAIT, + [OrientationLock.PORTRAIT_UP]: WebOrientationLock.PORTRAIT_PRIMARY, + [OrientationLock.PORTRAIT_DOWN]: WebOrientationLock.PORTRAIT_SECONDARY, + [OrientationLock.LANDSCAPE]: WebOrientationLock.LANDSCAPE, + [OrientationLock.LANDSCAPE_LEFT]: WebOrientationLock.LANDSCAPE_PRIMARY, + [OrientationLock.LANDSCAPE_RIGHT]: WebOrientationLock.LANDSCAPE_SECONDARY, }; const OrientationWebToAPI = { [WebOrientation.PORTRAIT_PRIMARY]: Orientation.PORTRAIT_UP, diff --git a/packages/expo-screen-orientation/build/ExpoScreenOrientation.web.js.map b/packages/expo-screen-orientation/build/ExpoScreenOrientation.web.js.map index fd5370cad9e5b..6584fb22cd13a 100644 --- a/packages/expo-screen-orientation/build/ExpoScreenOrientation.web.js.map +++ b/packages/expo-screen-orientation/build/ExpoScreenOrientation.web.js.map @@ -1 +1 @@ -{"version":3,"file":"ExpoScreenOrientation.web.js","sourceRoot":"","sources":["../src/ExpoScreenOrientation.web.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,MAAM,kBAAkB,CAAC;AAC5D,OAAO,EAAE,cAAc,EAAE,oBAAoB,EAAE,MAAM,+BAA+B,CAAC;AAErF,OAAO,EAAE,uBAAuB,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AACnF,OAAO,EACL,WAAW,EAEX,kBAAkB,EAClB,cAAc,GACf,MAAM,2BAA2B,CAAC;AAEnC,MAAM,uBAAuB,GAEzB;IACF,OAAO,EAAE,kBAAkB,CAAC,OAAO;IACnC,GAAG,EAAE,kBAAkB,CAAC,GAAG;IAC3B,QAAQ,EAAE,kBAAkB,CAAC,QAAQ;IACrC,WAAW,EAAE,kBAAkB,CAAC,gBAAgB;IAChD,aA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C,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 { SyntheticPlatformEmitter } from '@unimodules/core';\nimport { canUseViewport, canUseEventListeners } from 'fbjs/lib/ExecutionEnvironment';\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 DEFAULT: WebOrientationLock.NATURAL,\n ALL: WebOrientationLock.ANY,\n PORTRAIT: WebOrientationLock.PORTRAIT,\n PORTRAIT_UP: WebOrientationLock.PORTRAIT_PRIMARY,\n PORTRAIT_DOWN: WebOrientationLock.PORTRAIT_SECONDARY,\n LANDSCAPE: WebOrientationLock.LANDSCAPE,\n LANDSCAPE_LEFT: WebOrientationLock.LANDSCAPE_PRIMARY,\n 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 } = canUseViewport && window;\nconst orientation: ScreenOrientation | null =\n canUseViewport && (screen.orientation || (screen as any).msOrientation || null);\n\nasync function emitOrientationEvent() {\n const [orientationLock, orientation] = await Promise.all([\n getOrientationLockAsync(),\n getOrientationAsync(),\n ]);\n SyntheticPlatformEmitter.emit('expoDidUpdateDimensions', {\n orientationLock,\n orientationInfo: { orientation },\n });\n}\n\nif (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 {\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 if (screen.orientation && screen.orientation.lock) {\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 get name(): string {\n return 'ExpoScreenOrientation';\n },\n async supportsOrientationLockAsync(orientationLock: OrientationLock): Promise {\n return orientationLock in OrientationLockAPIToWeb;\n },\n async getPlatformOrientationLockAsync(): Promise {\n return _lastWebOrientationLock;\n },\n async getOrientationAsync(): Promise {\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 {\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 {\n await _lockAsync(webOrientationLock);\n _lastWebOrientationLock = webOrientationLock;\n },\n async unlockAsync(): Promise {\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"]} \ No newline at end of file +{"version":3,"file":"ExpoScreenOrientation.web.js","sourceRoot":"","sources":["../src/ExpoScreenOrientation.web.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,MAAM,kBAAkB,CAAC;AAC5D,OAAO,EAAE,cAAc,EAAE,oBAAoB,EAAE,MAAM,+BAA+B,CAAC;AAErF,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;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AW;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 { SyntheticPlatformEmitter } from '@unimodules/core';\nimport { canUseViewport, canUseEventListeners } from 'fbjs/lib/ExecutionEnvironment';\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 } = canUseViewport && window;\nconst orientation: ScreenOrientation | null =\n canUseViewport && (screen.orientation || (screen as any).msOrientation || null);\n\nasync function emitOrientationEvent() {\n const [orientationLock, orientation] = await Promise.all([\n getOrientationLockAsync(),\n getOrientationAsync(),\n ]);\n SyntheticPlatformEmitter.emit('expoDidUpdateDimensions', {\n orientationLock,\n orientationInfo: { orientation },\n });\n}\n\nif (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 {\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 if (screen.orientation && screen.orientation.lock) {\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 get name(): string {\n return 'ExpoScreenOrientation';\n },\n async supportsOrientationLockAsync(orientationLock: OrientationLock): Promise {\n return orientationLock in OrientationLockAPIToWeb;\n },\n async getPlatformOrientationLockAsync(): Promise {\n return _lastWebOrientationLock;\n },\n async getOrientationAsync(): Promise {\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 {\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 {\n await _lockAsync(webOrientationLock);\n _lastWebOrientationLock = webOrientationLock;\n },\n async unlockAsync(): Promise {\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"]} \ No newline at end of file diff --git a/packages/expo-screen-orientation/src/ExpoScreenOrientation.web.ts b/packages/expo-screen-orientation/src/ExpoScreenOrientation.web.ts index bfd70c693452e..537f77049f2fb 100644 --- a/packages/expo-screen-orientation/src/ExpoScreenOrientation.web.ts +++ b/packages/expo-screen-orientation/src/ExpoScreenOrientation.web.ts @@ -12,14 +12,14 @@ import { const OrientationLockAPIToWeb: { [lock: string]: WebOrientationLock; } = { - DEFAULT: WebOrientationLock.NATURAL, - ALL: WebOrientationLock.ANY, - PORTRAIT: WebOrientationLock.PORTRAIT, - PORTRAIT_UP: WebOrientationLock.PORTRAIT_PRIMARY, - PORTRAIT_DOWN: WebOrientationLock.PORTRAIT_SECONDARY, - LANDSCAPE: WebOrientationLock.LANDSCAPE, - LANDSCAPE_LEFT: WebOrientationLock.LANDSCAPE_PRIMARY, - LANDSCAPE_RIGHT: WebOrientationLock.LANDSCAPE_SECONDARY, + [OrientationLock.DEFAULT]: WebOrientationLock.NATURAL, + [OrientationLock.ALL]: WebOrientationLock.ANY, + [OrientationLock.PORTRAIT]: WebOrientationLock.PORTRAIT, + [OrientationLock.PORTRAIT_UP]: WebOrientationLock.PORTRAIT_PRIMARY, + [OrientationLock.PORTRAIT_DOWN]: WebOrientationLock.PORTRAIT_SECONDARY, + [OrientationLock.LANDSCAPE]: WebOrientationLock.LANDSCAPE, + [OrientationLock.LANDSCAPE_LEFT]: WebOrientationLock.LANDSCAPE_PRIMARY, + [OrientationLock.LANDSCAPE_RIGHT]: WebOrientationLock.LANDSCAPE_SECONDARY, }; const OrientationWebToAPI: { From d8add8bd7b808ae8db8e3e4d3739c59ccbbdad7c Mon Sep 17 00:00:00 2001 From: Alec Winograd Date: Thu, 9 Apr 2020 12:34:41 -0500 Subject: [PATCH 3/3] Update CHANGELOG --- packages/expo-screen-orientation/CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/expo-screen-orientation/CHANGELOG.md b/packages/expo-screen-orientation/CHANGELOG.md index 6a294c6841ff4..624e055af1f64 100644 --- a/packages/expo-screen-orientation/CHANGELOG.md +++ b/packages/expo-screen-orientation/CHANGELOG.md @@ -7,3 +7,6 @@ ### 🎉 New features ### 🐛 Bug fixes + +- Fixed `ScreenOrientation.addOrientationChangeListener` payload to match docs. ([#7774](https://github.com/expo/expo/pull/7774) by [@awinograd](https://github.com/awinograd)) +- Fixed `ScreenOrientation.lockAsync` to properly convert to web platform equivalent of chosen lock. ([#7774](https://github.com/expo/expo/pull/7774) by [@awinograd](https://github.com/awinograd))