MCPcopy
hub / github.com/MinJieLiu/react-photo-view / changeIndex

Function changeIndex

packages/react-photo-view/src/PhotoSlider.tsx:172–197  ·  view source on GitHub ↗
(nextIndex: number, isPause: boolean = false)

Source from the content-addressed store, hash-verified

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) => {

Callers 2

PhotoSliderFunction · 0.70
handleReachUpFunction · 0.70

Calls 1

limitNumberFunction · 0.90

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…