From 1ba9f4ac8e9268c8bfd40d4ecf90805697d99dd1 Mon Sep 17 00:00:00 2001 From: Dani Palou Date: Wed, 26 Jan 2022 07:57:42 +0100 Subject: [PATCH] MMOBILE-3833 core: Fix watchOrientation in iOS 12 --- src/core/services/screen.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/core/services/screen.ts b/src/core/services/screen.ts index 6228f7700..04a0e6917 100644 --- a/src/core/services/screen.ts +++ b/src/core/services/screen.ts @@ -121,11 +121,16 @@ export class CoreScreenService { */ watchOrientation(): void { // Listen media orientation CSS queries. - window.matchMedia('(orientation: portrait)').addEventListener('change', (m) => { + const changeListener = (m: MediaQueryListEvent) => { const orientation = m.matches ? CoreScreenOrientation.PORTRAIT : CoreScreenOrientation.LANDSCAPE; CoreEvents.trigger(CoreEvents.ORIENTATION_CHANGE, { orientation }); - }); + }; + + const mql = window.matchMedia('(orientation: portrait)'); + mql.addEventListener ? + mql.addEventListener('change', changeListener) : + mql.addListener(changeListener); } /**