Skip to content

feat: add getInstance function to swiper extension exports #97

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/libs/extensions/swiper/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ export {
isSwiperLoading,
updateSwiperInstance,
setSwiperLoadingStatus,
refreshSwiper
refreshSwiper,
getInstance
} from "./swiper.extension"
15 changes: 15 additions & 0 deletions src/libs/extensions/swiper/swiper.extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,21 @@ function addTilesUpdatedListener(id: string, getSlides?: (tiles: Record<string,

swiper?.update()
})

if (!swiper) {
console.warn("Swiper instance not found")
return
}

const observer = new MutationObserver(() => {
swiper.update()
sdk.querySelector(".tile-loading:not(.hidden)")?.classList.add("hidden")
})

observer.observe(sdk.querySelector(".ugc-tiles")!, {
childList: true,
subtree: true
})
}

export function initializeSwiper({
Expand Down
9 changes: 7 additions & 2 deletions src/widget-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,15 @@ export interface EnforcedWidgetSettings<C> extends Required<MyWidgetSettings<C>>
}

function loadMasonryCallbacks<C>(settings: EnforcedWidgetSettings<C>) {
settings.callbacks.onTilesUpdated.push(() => {
const tilesUpdatedObserver = new MutationObserver(() => {
renderMasonryLayout()
})

tilesUpdatedObserver.observe(sdk.querySelector(".ugc-tiles")!, {
childList: true,
subtree: true
})

settings.callbacks.onTileBgImgRenderComplete.push(() => {
handleAllTileImageRendered()
setTimeout(handleAllTileImageRendered, 1000)
Expand All @@ -143,7 +148,7 @@ function loadMasonryCallbacks<C>(settings: EnforcedWidgetSettings<C>) {

const grid = sdk.querySelector(".grid")
const observer = new ResizeObserver(() => {
renderMasonryLayout(false, true)
renderMasonryLayout()
})

observer.observe(grid)
Expand Down
Loading