Skip to content

Commit 184e3a9

Browse files
committed
fix: check all anchors at findAnchorIncludePosition
1 parent 0771ccd commit 184e3a9

File tree

3 files changed

+7
-14
lines changed

3 files changed

+7
-14
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/Control.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ abstract class Control {
397397
}
398398
}
399399

400-
protected _getPosition(panel: Panel, direction: ValueOf<typeof DIRECTION> = DIRECTION.NONE) {
400+
private _getPosition(panel: Panel, direction: ValueOf<typeof DIRECTION> = DIRECTION.NONE) {
401401
const flicking = getFlickingAttached(this._flicking);
402402
const camera = flicking.camera;
403403

src/control/SnapControl.ts

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import AnchorPoint from "../core/AnchorPoint";
99
import { circulateIndex, clamp, getFlickingAttached } from "../utils";
1010
import * as AXES from "../const/axes";
1111
import * as ERROR from "../const/error";
12-
import { DIRECTION } from "../const/external";
1312

1413
import Control from "./Control";
1514

@@ -121,16 +120,12 @@ class SnapControl extends Control {
121120
});
122121
}
123122

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);
123+
this._triggerIndexChangeEvent(targetAnchor.panel, position, axesEvent);
129124

130125
return this._animateToPosition({
131-
position: camera.clampToReachablePosition(nextPosition),
126+
position: camera.clampToReachablePosition(targetAnchor.position),
132127
duration,
133-
newActivePanel: nextPanel,
128+
newActivePanel: targetAnchor.panel,
134129
axesEvent
135130
});
136131
}
@@ -143,15 +138,14 @@ class SnapControl extends Control {
143138
const currentPos = camera.position;
144139

145140
const clampedPosition = camera.clampToReachablePosition(position);
146-
const nearestAnchor = camera.findNearestAnchor(clampedPosition);
147141
const anchorAtPosition = camera.findAnchorIncludePosition(clampedPosition);
148142

149-
if (!anchorAtCamera || !anchorAtPosition || !nearestAnchor) {
143+
if (!anchorAtCamera || !anchorAtPosition) {
150144
throw new FlickingError(ERROR.MESSAGE.POSITION_NOT_REACHABLE(position), ERROR.CODE.POSITION_NOT_REACHABLE);
151145
}
152146

153147
if (!isFinite(count)) {
154-
return nearestAnchor;
148+
return anchorAtPosition;
155149
}
156150

157151
const panelCount = flicking.panelCount;

0 commit comments

Comments
 (0)