From e32f0e8bb8ec68f7371d34ae7acd0af082c9d228 Mon Sep 17 00:00:00 2001 From: Dermot Duffy Date: Sat, 23 Jul 2022 15:19:30 -0700 Subject: [PATCH] With Embla 7 special Safari treatment not necessary. --- src/components/carousel.ts | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/src/components/carousel.ts b/src/components/carousel.ts index 1645d493..175f6af1 100644 --- a/src/components/carousel.ts +++ b/src/components/carousel.ts @@ -122,12 +122,13 @@ export class FrigateCardCarousel extends LitElement { */ public getCarouselSelected(): CarouselSelect | null { const index = this._carousel?.selectedScrollSnap(); - const element = index !== undefined ? (this._carousel?.slideNodes()[index] ?? null) : null; + const element = + index !== undefined ? this._carousel?.slideNodes()[index] ?? null : null; if (index !== undefined && element) { return { index: index, element: element, - } + }; } return null; } @@ -150,10 +151,11 @@ export class FrigateCardCarousel extends LitElement { * ReInit the carousel. */ protected _carouselReInit(options?: EmblaOptionsType): void { + // Allow the browser a moment to paint components that are inflight, to + // ensure accurate measurements are taken during the carousel + // reinitialization. window.requestAnimationFrame(() => { - // Safari appears to not loop the carousel unless the options are passed - // back in during re-initialization. - this._carousel?.reInit({ ...this.carouselOptions, ...options }); + this._carousel?.reInit({ ...options }); }); } /** @@ -162,13 +164,9 @@ export class FrigateCardCarousel extends LitElement { protected _carouselReInitInPlaceInternal(): void { const selected = this.getCarouselSelected(); - // Safari appears to not loop the carousel unless the options are passed - // back in during re-initialization. - const options = { - ...this.carouselOptions, + this._carouselReInit({ ...(selected && { startIndex: selected.index }), - }; - this._carouselReInit(options); + }); } /** @@ -263,7 +261,7 @@ export class FrigateCardCarousel extends LitElement { this._reInitOnSettle = false; this._carouselReInitInPlace(); } - }) + }); this._carousel.on('settle', () => { const selected = this.getCarouselSelected(); if (selected) {