Reverted addEventListener for media query (hello iOS Safari, I'm looking at you)

This commit is contained in:
squidfunk
2020-09-27 21:01:16 +02:00
parent a127eec88d
commit 0c4ddfcd70
8 changed files with 12 additions and 11 deletions

View File

@@ -20,8 +20,8 @@
* IN THE SOFTWARE.
*/
import { Observable, fromEvent } from "rxjs"
import { map, shareReplay, startWith } from "rxjs/operators"
import { Observable } from "rxjs"
import { shareReplay, startWith } from "rxjs/operators"
/* ----------------------------------------------------------------------------
* Functions
@@ -36,9 +36,10 @@ import { map, shareReplay, startWith } from "rxjs/operators"
*/
export function watchMedia(query: string): Observable<boolean> {
const media = matchMedia(query)
return fromEvent<MediaQueryListEvent>(media, "change")
return new Observable<boolean>(subscriber => {
media.addListener(ev => subscriber.next(ev.matches))
})
.pipe(
map(ev => ev.matches),
startWith(media.matches),
shareReplay({ bufferSize: 1, refCount: true })
)

View File

@@ -83,7 +83,7 @@ export function patchScrollfix(
iif(isAppleDevice, els$, NEVER)
.pipe(
switchMap(els => merge(...els.map(el => (
fromEvent(el, "touchstart", { passive: true })
fromEvent(el, "touchstart")
.pipe(
mapTo(el)
)