@egjs/flicking 4.12.1-beta.2 → 4.12.1-beta.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@egjs/flicking",
3
- "version": "4.12.1-beta.2",
3
+ "version": "4.12.1-beta.4",
4
4
  "description": "Everyday 30 million people experience. It's reliable, flexible and extendable carousel.",
5
5
  "main": "dist/flicking.cjs.js",
6
6
  "module": "dist/flicking.esm.js",
@@ -397,7 +397,7 @@ abstract class Control {
397
397
  }
398
398
  }
399
399
 
400
- private _getPosition(panel: Panel, direction: ValueOf<typeof DIRECTION> = DIRECTION.NONE) {
400
+ protected _getPosition(panel: Panel, direction: ValueOf<typeof DIRECTION> = DIRECTION.NONE) {
401
401
  const flicking = getFlickingAttached(this._flicking);
402
402
  const camera = flicking.camera;
403
403
 
@@ -9,6 +9,7 @@ import AnchorPoint from "../core/AnchorPoint";
9
9
  import { circulateIndex, clamp, getFlickingAttached } from "../utils";
10
10
  import * as AXES from "../const/axes";
11
11
  import * as ERROR from "../const/error";
12
+ import { DIRECTION } from "../const/external";
12
13
 
13
14
  import Control from "./Control";
14
15
 
@@ -111,7 +112,6 @@ class SnapControl extends Control {
111
112
  targetAnchor = this._findSnappedAnchor(position, anchorAtCamera);
112
113
  } else if (absPosDelta >= flicking.threshold && absPosDelta > 0 && anchorAtCamera === activeAnchor) {
113
114
  // Move to the adjacent panel
114
- // console.log("moveToPosition anchorAtCamera activeAnchor absPosDelta", camera.position, anchorAtCamera, activeAnchor, absPosDelta, snapThreshold)
115
115
  targetAnchor = this._findAdjacentAnchor(position, posDelta, anchorAtCamera);
116
116
  } else {
117
117
  // Fallback to nearest panel from current camera
@@ -121,12 +121,16 @@ class SnapControl extends Control {
121
121
  });
122
122
  }
123
123
 
124
- this._triggerIndexChangeEvent(targetAnchor.panel, position, axesEvent);
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);
125
129
 
126
130
  return this._animateToPosition({
127
- position: camera.clampToReachablePosition(targetAnchor.position),
131
+ position: camera.clampToReachablePosition(nextPosition),
128
132
  duration,
129
- newActivePanel: targetAnchor.panel,
133
+ newActivePanel: nextPanel,
130
134
  axesEvent
131
135
  });
132
136
  }
@@ -139,14 +143,15 @@ class SnapControl extends Control {
139
143
  const currentPos = camera.position;
140
144
 
141
145
  const clampedPosition = camera.clampToReachablePosition(position);
146
+ const nearestAnchor = camera.findNearestAnchor(clampedPosition);
142
147
  const anchorAtPosition = camera.findAnchorIncludePosition(clampedPosition);
143
148
 
144
- if (!anchorAtCamera || !anchorAtPosition) {
149
+ if (!anchorAtCamera || !anchorAtPosition || !nearestAnchor) {
145
150
  throw new FlickingError(ERROR.MESSAGE.POSITION_NOT_REACHABLE(position), ERROR.CODE.POSITION_NOT_REACHABLE);
146
151
  }
147
152
 
148
153
  if (!isFinite(count)) {
149
- return anchorAtPosition;
154
+ return nearestAnchor;
150
155
  }
151
156
 
152
157
  const panelCount = flicking.panelCount;
@@ -206,7 +211,6 @@ class SnapControl extends Control {
206
211
  }
207
212
  }
208
213
 
209
- // console.log("_findAdjacentAnchor", position, posDelta, anchorAtCamera)
210
214
  const adjacentAnchor = (posDelta > 0 ? camera.getNextAnchor(anchorAtCamera) : camera.getPrevAnchor(anchorAtCamera)) ?? anchorAtCamera;
211
215
 
212
216
  return adjacentAnchor;