Skip to content

Commit 92ef9cf

Browse files
committed
fix(images): adds a timeout threshold to enable transition
1 parent 6ac3cc8 commit 92ef9cf

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-8
lines changed

src/components/common/list/ListItem.vue

+19-5
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,9 @@ const onLoad = () => {
126126
imgLoaded.value = true;
127127
};
128128
129+
const transition = ref(false);
130+
const timeout = ref();
131+
129132
const getPosters = (_item: ListScrollItem) => {
130133
imgLoaded.value = false;
131134
if (_item.posterRef?.value) return;
@@ -136,6 +139,10 @@ const getPosters = (_item: ListScrollItem) => {
136139
query.type = 'show';
137140
delete query.episode;
138141
}
142+
setTimeout(() => {
143+
if (resolvedPoster.value) return;
144+
transition.value = true;
145+
}, 100);
139146
getImageUrl(query, 300, _item.posterRef);
140147
};
141148
@@ -152,6 +159,7 @@ onMounted(() => {
152159
});
153160
154161
onBeforeUnmount(() => {
162+
clearTimeout(timeout.value);
155163
if (!scrollIntoView.value) return;
156164
emit('onScrollOutOfView', {
157165
item: item?.value,
@@ -160,8 +168,6 @@ onBeforeUnmount(() => {
160168
});
161169
162170
const itemHeight = computed(() => (height?.value ? `${height.value}px` : undefined));
163-
164-
const ListScrollItemTypeLocal = ListScrollItemType;
165171
</script>
166172

167173
<template>
@@ -222,7 +228,7 @@ const ListScrollItemTypeLocal = ListScrollItemType;
222228
</template>
223229
</NFlex>
224230

225-
<slot v-if="item.type === ListScrollItemTypeLocal.placeholder">
231+
<slot v-if="item.type === ListScrollItemType.placeholder">
226232
<NFlex class="placeholder" align="center" justify="center" :wrap="false">
227233
<NEmpty size="large" :description="i18n('placeholder_empty')" />
228234
</NFlex>
@@ -234,12 +240,14 @@ const ListScrollItemTypeLocal = ListScrollItemType;
234240
:class="{
235241
episode,
236242
loading: !imgLoaded,
243+
transition,
237244
}"
238245
:object-fit="objectFit"
239246
width="100%"
240247
lazy
241248
preview-disabled
242249
:src="resolvedPoster"
250+
:fallback-src="PosterPlaceholder"
243251
:on-load="onLoad"
244252
/>
245253
<NImage
@@ -358,12 +366,18 @@ const ListScrollItemTypeLocal = ListScrollItemType;
358366
width: var(--poster-width, 5.3125rem);
359367
height: var(--poster-height, 8rem);
360368
opacity: 1;
361-
transition: opacity 0.5s var(--n-bezier);
362369
will-change: opacity;
363370
364371
&.loading {
365372
opacity: 0;
366-
transition: opacity 0.1s;
373+
}
374+
375+
&.transition {
376+
transition: opacity 0.5s var(--n-bezier);
377+
378+
&.loading {
379+
transition: opacity 0.1s;
380+
}
367381
}
368382
369383
&.episode {

src/components/common/list/ListScroll.vue

+1-3
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,6 @@ const onHover = ({ item, hover }: { item: ListScrollItem; hover: boolean }) => {
117117
const onLoadMore = (payload: { page: number; pageCount: number; pageSize: number }) => {
118118
emits('onloadMore', { listRef, ...payload });
119119
};
120-
121-
const ListScrollItemTypeLocal = ListScrollItemType;
122120
</script>
123121

124122
<template>
@@ -145,7 +143,7 @@ const ListScrollItemTypeLocal = ListScrollItemType;
145143
@vue:updated="onUpdatedHandler"
146144
>
147145
<template #default="{ item }">
148-
<slot v-if="item.type === ListScrollItemTypeLocal.loadMore" name="load-more">
146+
<slot v-if="item.type === ListScrollItemType.loadMore" name="load-more">
149147
<NFlex
150148
class="load-more"
151149
justify="center"

0 commit comments

Comments
 (0)