(nextIndex: number, isPause: boolean = false)
| 170 | onClose(evt); |
| 171 | }, |
| 172 | changeIndex(nextIndex: number, isPause: boolean = false) { |
| 173 | // 当前索引 |
| 174 | const currentIndex = enableLoop ? virtualIndexRef.current + (nextIndex - index) : nextIndex; |
| 175 | const max = imageLength - 1; |
| 176 | // 虚拟 index |
| 177 | // 非循环模式,限制区间 |
| 178 | const limitIndex = limitNumber(currentIndex, 0, max); |
| 179 | const nextVirtualIndex = enableLoop ? currentIndex : limitIndex; |
| 180 | // 单个屏幕宽度 |
| 181 | const singlePageWidth = innerWidth + horizontalOffset; |
| 182 | |
| 183 | updateState({ |
| 184 | touched: false, |
| 185 | lastCX: undefined, |
| 186 | lastCY: undefined, |
| 187 | x: -singlePageWidth * nextVirtualIndex, |
| 188 | pause: isPause, |
| 189 | }); |
| 190 | |
| 191 | virtualIndexRef.current = nextVirtualIndex; |
| 192 | // 更新真实的 index |
| 193 | const realLoopIndex = nextIndex < 0 ? max : nextIndex > max ? 0 : nextIndex; |
| 194 | if (onIndexChange) { |
| 195 | onIndexChange(enableLoop ? realLoopIndex : limitIndex); |
| 196 | } |
| 197 | }, |
| 198 | }); |
| 199 | |
| 200 | useEventListener('keydown', (evt: KeyboardEvent) => { |
no test coverage detected
searching dependent graphs…