-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add function to polyfill missing matchMedia#addEventListener on iOS 13 devices
- Loading branch information
1 parent
0e4ef25
commit c55a9b3
Showing
2 changed files
with
39 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/** | ||
* Add change event listener to given MediaQueryList instance | ||
* @param mediaQuery | ||
* @param callback | ||
*/ | ||
export const addMediaQueryListChangeListener = (mediaQuery: MediaQueryList, callback: (event: MediaQueryListEvent) => void): void => { | ||
if (typeof mediaQuery.addEventListener === 'undefined') { | ||
mediaQuery.addListener(callback) | ||
} else { | ||
mediaQuery.addEventListener('change', callback); | ||
} | ||
}; | ||
|
||
/** | ||
* Remove change event listener from given MediaQueryList instance | ||
* @param mediaQuery | ||
* @param callback | ||
*/ | ||
export const removeMediaQueryListChangeListener = (mediaQuery: MediaQueryList, callback: (event: MediaQueryListEvent) => void): void => { | ||
if (typeof mediaQuery.removeEventListener === 'undefined') { | ||
mediaQuery.removeListener(callback) | ||
} else { | ||
mediaQuery.removeEventListener('change', callback); | ||
} | ||
}; |