Skip to content

Commit 85c0206

Browse files
committed
fix: check all anchors at findAnchorIncludePosition
1 parent 0771ccd commit 85c0206

File tree

2 files changed

+6
-12
lines changed

2 files changed

+6
-12
lines changed

src/camera/mode/CameraMode.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,8 @@ abstract class CameraMode {
3333

3434
public findAnchorIncludePosition(position: number): AnchorPoint | null {
3535
const anchors = this._flicking.camera.anchorPoints;
36-
const anchorsIncludingPosition = anchors.filter(anchor => anchor.panel.includePosition(position, true));
3736

38-
return anchorsIncludingPosition.reduce((nearest: AnchorPoint | null, anchor) => {
37+
return anchors.reduce((nearest: AnchorPoint | null, anchor) => {
3938
if (!nearest) return anchor;
4039

4140
return Math.abs(nearest.position - position) < Math.abs(anchor.position - position)

src/control/SnapControl.ts

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -121,16 +121,12 @@ class SnapControl extends Control {
121121
});
122122
}
123123

124-
const nextPanel = targetAnchor.panel;
125-
const direction = (posDelta === 0 || activeAnchor === targetAnchor) ? DIRECTION.NONE : (posDelta > 0 ? DIRECTION.NEXT : DIRECTION.PREV);
126-
const nextPosition = this._getPosition(nextPanel, direction);
127-
128-
this._triggerIndexChangeEvent(nextPanel, position, axesEvent);
124+
this._triggerIndexChangeEvent(targetAnchor.panel, position, axesEvent);
129125

130126
return this._animateToPosition({
131-
position: camera.clampToReachablePosition(nextPosition),
127+
position: camera.clampToReachablePosition(targetAnchor.position),
132128
duration,
133-
newActivePanel: nextPanel,
129+
newActivePanel: targetAnchor.panel,
134130
axesEvent
135131
});
136132
}
@@ -143,15 +139,14 @@ class SnapControl extends Control {
143139
const currentPos = camera.position;
144140

145141
const clampedPosition = camera.clampToReachablePosition(position);
146-
const nearestAnchor = camera.findNearestAnchor(clampedPosition);
147142
const anchorAtPosition = camera.findAnchorIncludePosition(clampedPosition);
148143

149-
if (!anchorAtCamera || !anchorAtPosition || !nearestAnchor) {
144+
if (!anchorAtCamera || !anchorAtPosition) {
150145
throw new FlickingError(ERROR.MESSAGE.POSITION_NOT_REACHABLE(position), ERROR.CODE.POSITION_NOT_REACHABLE);
151146
}
152147

153148
if (!isFinite(count)) {
154-
return nearestAnchor;
149+
return anchorAtPosition;
155150
}
156151

157152
const panelCount = flicking.panelCount;

0 commit comments

Comments
 (0)