| 113 | } |
| 114 | |
| 115 | export const observeWindowRect = ( |
| 116 | instance: Virtualizer<Window, any>, |
| 117 | cb: (rect: Rect) => void, |
| 118 | ) => { |
| 119 | const element = instance.scrollElement |
| 120 | if (!element) { |
| 121 | return |
| 122 | } |
| 123 | |
| 124 | const handler = () => { |
| 125 | cb({ width: element.innerWidth, height: element.innerHeight }) |
| 126 | } |
| 127 | handler() |
| 128 | |
| 129 | element.addEventListener('resize', handler, addEventListenerOptions) |
| 130 | |
| 131 | return () => { |
| 132 | element.removeEventListener('resize', handler) |
| 133 | } |
| 134 | } |
| 135 | |
| 136 | const supportsScrollend = |
| 137 | typeof window == 'undefined' ? true : 'onscrollend' in window |