Skip to content

Commit

Permalink
feat: Emit events for scroll to begin and end of list (#364)
Browse files Browse the repository at this point in the history
Co-authored-by: Guillaume Chau <guillaume.b.chau@gmail.com>
  • Loading branch information
davidarico and Akryum authored Oct 14, 2022
1 parent 6b623b5 commit 2a7bfd4
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,8 @@ When the user scrolls inside RecycleScroller, the views are mostly just moved ar
- `visible`: emitted when the scroller considers itself to be visible in the page.
- `hidden`: emitted when the scroller is hidden in the page.
- `update (startIndex, endIndex, visibleStartIndex, visibleEndIndex)`: emitted each time the views are updated, only if `emitUpdate` prop is `true`
- `scroll-start`: emitted when the first item is rendered.
- `scroll-end`: emitted when the last item is rendered.

### Default scoped slot props

Expand Down
10 changes: 10 additions & 0 deletions docs-src/src/components/RecycleScrollerDemo.vue
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@
@update="onUpdate"
@visible="onVisible"
@hidden="onHidden"
@scroll-start="onScrollStart"
@scroll-end="onScrollEnd"
>
<template v-slot="props">
<div
Expand Down Expand Up @@ -206,6 +208,14 @@ export default {
onHidden () {
console.log('hidden')
},
onScrollStart () {
console.log('scroll start')
},
onScrollEnd () {
console.log('scroll end')
},
},
}
</script>
Expand Down
3 changes: 3 additions & 0 deletions src/components/RecycleScroller.vue
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,9 @@ export default {
// No view assigned to item
if (!view) {
if (i === items.length - 1) this.$emit('scroll-end')
if (i === 0) this.$emit('scroll-start')
type = item[typeField]
unusedPool = unusedViews.get(type)
Expand Down

0 comments on commit 2a7bfd4

Please sign in to comment.