@@ -9,6 +9,7 @@ import AnchorPoint from "../core/AnchorPoint";
99import { circulateIndex , clamp , getFlickingAttached } from "../utils" ;
1010import * as AXES from "../const/axes" ;
1111import * as ERROR from "../const/error" ;
12+ import { DIRECTION } from "../const/external" ;
1213
1314import Control from "./Control" ;
1415
@@ -120,12 +121,16 @@ class SnapControl extends Control {
120121 } ) ;
121122 }
122123
123- 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 ) ;
124129
125130 return this . _animateToPosition ( {
126- position : camera . clampToReachablePosition ( targetAnchor . position ) ,
131+ position : camera . clampToReachablePosition ( nextPosition ) ,
127132 duration,
128- newActivePanel : targetAnchor . panel ,
133+ newActivePanel : nextPanel ,
129134 axesEvent
130135 } ) ;
131136 }
@@ -138,14 +143,15 @@ class SnapControl extends Control {
138143 const currentPos = camera . position ;
139144
140145 const clampedPosition = camera . clampToReachablePosition ( position ) ;
146+ const nearestAnchor = camera . findNearestAnchor ( clampedPosition ) ;
141147 const anchorAtPosition = camera . findAnchorIncludePosition ( clampedPosition ) ;
142148
143- if ( ! anchorAtCamera || ! anchorAtPosition ) {
149+ if ( ! anchorAtCamera || ! anchorAtPosition || ! nearestAnchor ) {
144150 throw new FlickingError ( ERROR . MESSAGE . POSITION_NOT_REACHABLE ( position ) , ERROR . CODE . POSITION_NOT_REACHABLE ) ;
145151 }
146152
147153 if ( ! isFinite ( count ) ) {
148- return anchorAtPosition ;
154+ return nearestAnchor ;
149155 }
150156
151157 const panelCount = flicking . panelCount ;
0 commit comments