Skip to content

Commit

Permalink
review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
hshoja committed Nov 6, 2024
1 parent af3ab4c commit a7effba
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 21 deletions.
10 changes: 10 additions & 0 deletions docs/api/virtualizer.md
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,16 @@ This option allows you to specify the duration to wait after the last scroll eve

The implementation of this option is driven by the need for a reliable mechanism to handle scrolling behavior across different browsers. Until all browsers uniformly support the scrollEnd event.

### `useScrollendEvent`

```tsx
useScrollendEvent: boolean
```

This option allows you to switch to use debounced fallback to reset the isScrolling instance property after `isScrollingResetDelay` milliseconds. The default value is `true`.

The implementation of this option is driven by the need for a reliable mechanism to handle scrolling behavior across different browsers. Until all browsers uniformly support the scrollEnd event.

### `isRtl`

```tsx
Expand Down
36 changes: 15 additions & 21 deletions packages/virtual-core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,6 @@ const supportsScrollend =
export const observeElementOffset = <T extends Element>(
instance: Virtualizer<T, any>,
cb: (offset: number, isScrolling: boolean) => void,
debounceFallbackEnabled = false,
) => {
const element = instance.scrollElement
if (!element) {
Expand All @@ -146,7 +145,7 @@ export const observeElementOffset = <T extends Element>(

let offset = 0
const fallback =
!debounceFallbackEnabled && supportsScrollend
instance.options.useScrollendEvent && supportsScrollend
? () => undefined
: debounce(
targetWindow,
Expand Down Expand Up @@ -294,9 +293,7 @@ export interface VirtualizerOptions<
observeElementOffset: (
instance: Virtualizer<TScrollElement, TItemElement>,
cb: (offset: number, isScrolling: boolean) => void,
debounceFallbackEnabled?: boolean,
) => void | (() => void)

// Optional
debug?: boolean
initialRect?: Rect
Expand Down Expand Up @@ -324,6 +321,7 @@ export interface VirtualizerOptions<
initialMeasurementsCache?: Array<VirtualItem>
lanes?: number
isScrollingResetDelay?: number
useScrollendEvent?: boolean
enabled?: boolean
isRtl?: boolean
}
Expand All @@ -337,7 +335,6 @@ export class Virtualizer<
scrollElement: TScrollElement | null = null
targetWindow: (Window & typeof globalThis) | null = null
isScrolling = false
debounceFallbackEnabled = false
private scrollToIndexTimeoutId: number | null = null
measurementsCache: Array<VirtualItem> = []
private itemSizeCache = new Map<Key, number>()
Expand Down Expand Up @@ -416,6 +413,7 @@ export class Virtualizer<
isScrollingResetDelay: 150,
enabled: true,
isRtl: false,
useScrollendEvent: true,
...opts,
}
}
Expand Down Expand Up @@ -500,22 +498,18 @@ export class Virtualizer<
)

this.unsubs.push(
this.options.observeElementOffset(
this,
(offset, isScrolling) => {
this.scrollAdjustments = 0
this.scrollDirection = isScrolling
? this.getScrollOffset() < offset
? 'forward'
: 'backward'
: null
this.scrollOffset = offset
this.isScrolling = isScrolling

this.maybeNotify()
},
this.debounceFallbackEnabled,
),
this.options.observeElementOffset(this, (offset, isScrolling) => {
this.scrollAdjustments = 0
this.scrollDirection = isScrolling
? this.getScrollOffset() < offset
? 'forward'
: 'backward'
: null
this.scrollOffset = offset
this.isScrolling = isScrolling

this.maybeNotify()
}),
)
}
}
Expand Down

0 comments on commit a7effba

Please sign in to comment.