From 150b5433c0739f3fb93b09ae1606dfd000f49850 Mon Sep 17 00:00:00 2001 From: harshbaz <106158714+harshbaz@users.noreply.github.com> Date: Sat, 27 Aug 2022 15:10:49 +0530 Subject: [PATCH] Fix laggy swiping on iOS (#240) * Show next video, do not fade in into view * Fix laggy swiping. Add loading and no more slides --- .../src/components/video/VideoPlayer.svelte | 3 +- .../src/components/video/VideosSwiper.svelte | 40 +++++++++---------- 2 files changed, 21 insertions(+), 22 deletions(-) diff --git a/packages/web-client/src/components/video/VideoPlayer.svelte b/packages/web-client/src/components/video/VideoPlayer.svelte index bba850ee8..8bf6caae6 100644 --- a/packages/web-client/src/components/video/VideoPlayer.svelte +++ b/packages/web-client/src/components/video/VideoPlayer.svelte @@ -46,8 +46,7 @@ export async function stop() { diff --git a/packages/web-client/src/components/video/VideosSwiper.svelte b/packages/web-client/src/components/video/VideosSwiper.svelte index efdd32e60..1defd6b24 100644 --- a/packages/web-client/src/components/video/VideosSwiper.svelte +++ b/packages/web-client/src/components/video/VideosSwiper.svelte @@ -5,9 +5,7 @@ import { playerState } from '$stores/playerState'; import { onMount, tick } from 'svelte'; import VideoPlayer from './VideoPlayer.svelte'; import { Swiper, SwiperSlide } from 'swiper/svelte'; -import { Mousewheel } from 'swiper'; import 'swiper/css'; -import 'swiper/css/pagination'; import { debounce } from 'throttle-debounce'; export let fetchFromId: number = 0; @@ -33,6 +31,7 @@ async function fetchNextVideos() { fetchFromId = res.nextCount; moreVideos = res.videosLeft; loading = false; + // console.log('fetched', videos); } catch (e) { console.error(e); @@ -51,9 +50,12 @@ async function handleChange(e: CustomEvent) { updateURL(); } -const playVideo = debounce(50, async (index: number) => { - videoPlayers[index].play(); - currentPlayingIndex = index; +const playVideo = debounce(200, async (index: number) => { + if (!loading) { + videoPlayers[index].play(); + currentPlayingIndex = index; + videoPlayers[index + 1]?.stop(); + } }); function updateURL() { @@ -76,10 +78,8 @@ $: console.log({ currentVideoIndex }); observer slidesPerView="{1}" on:slideChange="{handleChange}" - speed="{500}" - mousewheel="{{ forceToAxis: true, sensitivity: 1, releaseOnEdges: true, thresholdDelta: 40 }}" - modules="{[Mousewheel]}" - class="mySwiper h-full w-full" + cssMode + class="h-full w-full" > {#each videos as video, i (i)} @@ -94,18 +94,18 @@ $: console.log({ currentVideoIndex }); {/each} {#if loading} -
-
Loading
-
+ +
+
Loading
+
+
{/if} {#if !moreVideos} -
- -
No more videos to display today
-
+ +
+ +
No more videos to display today
+
+
{/if}