@egjs/flicking 4.12.0-beta.7 → 4.12.0-beta.9

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.
@@ -2,43 +2,52 @@
2
2
  * Copyright (c) 2015 NAVER Corp.
3
3
  * egjs projects are licensed under the MIT license
4
4
  */
5
-
6
- import Flicking, { FlickingOptions } from "./Flicking";
7
- import { ChangedEvent, MoveEndEvent, MoveEvent } from "./type/event";
5
+ import { ComponentEvent } from "@egjs/component";
6
+ import { EventKey } from "@egjs/component/declaration/types";
7
+
8
+ import Flicking, { FlickingEvents, FlickingOptions } from "./Flicking";
9
+ import {
10
+ ChangedEvent,
11
+ HoldEndEvent,
12
+ HoldStartEvent,
13
+ MoveEndEvent,
14
+ MoveEvent,
15
+ MoveStartEvent,
16
+ WillChangeEvent
17
+ } from "./type/event";
8
18
  import { LiteralUnion, ValueOf } from "./type/internal";
9
19
  import { CLASS, EVENTS, MOVE_DIRECTION } from "./const/external";
10
20
  import { getDataAttributes, includes, toArray } from "./utils";
11
21
 
12
- /**
13
- * @interface
14
- */
15
- export interface CrossFlickingEvents {
16
- // FlickingEvent 들을 확장하자...
22
+ export const SIDE_EVENTS = {
23
+ HOLD_START: "sideHoldStart",
24
+ HOLD_END: "sideHoldEnd",
25
+ MOVE_START: "sideMoveStart",
26
+ MOVE: "sideMove",
27
+ MOVE_END: "sideMoveEnd",
28
+ WILL_CHANGE: "sideWillChange",
29
+ CHANGED: "sideChanged"
30
+ } as const;
31
+
32
+ export type CrossFlickingEvent<T> = { mainIndex: number } & T;
33
+
34
+ export interface CrossFlickingEvents extends FlickingEvents {
35
+ [SIDE_EVENTS.HOLD_START]: CrossFlickingEvent<HoldStartEvent>;
36
+ [SIDE_EVENTS.HOLD_END]: CrossFlickingEvent<HoldEndEvent>;
37
+ [SIDE_EVENTS.MOVE_START]: CrossFlickingEvent<MoveStartEvent>;
38
+ [SIDE_EVENTS.MOVE]: CrossFlickingEvent<MoveEvent>;
39
+ [SIDE_EVENTS.MOVE_END]: CrossFlickingEvent<MoveEndEvent>;
40
+ [SIDE_EVENTS.WILL_CHANGE]: CrossFlickingEvent<WillChangeEvent>;
41
+ [SIDE_EVENTS.CHANGED]: CrossFlickingEvent<ChangedEvent>;
17
42
  }
18
43
 
19
- /**
20
- * @interface
21
- */
22
44
  export interface CrossFlickingOptions extends FlickingOptions {
23
45
  sideOptions: Partial<FlickingOptions> | undefined;
24
- // 한쪽 움직이면 다른 한쪽 움직임을 막을지 여부
25
- // 이전 패널 기억 여부
46
+ preserveIndex: boolean | undefined;
47
+ disableSlideOnHold: boolean | undefined;
48
+ disableIndexSync: boolean | undefined;
26
49
  }
27
50
 
28
- /**
29
- * Flicking Status returned by {@link Flicking#getStatus}
30
- * @ko {@link Flicking#getStatus}에 의해 반환된 Flicking 상태 객체
31
- * @interface
32
- * @property {number} index An index of the active panel<ko>활성화된 패널의 인덱스</ko>
33
- * @property {object} position A info to restore camera {@link Camera#position position}<ko>카메라 {@link Camera#position position}을 설정하기 위한 정보들</ko>
34
- * @property {number} [position.panel] An index of the panel camera is located at<ko>카메라가 위치한 패널의 인덱스</ko>
35
- * @property {number} [position.progressInPanel] A progress of the camera position inside the panel<ko>패널 내에서의 카메라 위치의 진행도</ko>
36
- * @property {number} visibleOffset An offset to visible panel's original index. This value is available only when `visiblePanelsOnly` is `true`
37
- * <ko>현재 보이는 패널들을 저장했을 때, 원래의 인덱스 대비 offset. `visiblePanelsOnly` 옵션을 사용했을 때만 사용 가능합니다</ko>
38
- * @property {object[]} panels A data array of panels<ko>패널의 정보를 담은 배열</ko>
39
- * @property {index} [panels.index] An index of the panel<ko>패널의 인덱스</ko>
40
- * @property {string | undefined} [panels.html] An `outerHTML` of the panel element<ko>패널 엘리먼트의 `outerHTML`</ko>
41
- */
42
51
  export interface SideState {
43
52
  key: string;
44
53
  start: number;
@@ -46,18 +55,15 @@ export interface SideState {
46
55
  element: HTMLElement;
47
56
  }
48
57
 
49
- /**
50
- * @extends Component
51
- * @support {"ie": "9+(with polyfill)", "ch" : "latest", "ff" : "latest", "sf" : "latest", "edge" : "latest", "ios" : "7+", "an" : "4.X+"}
52
- * @requires {@link https://github.com/naver/egjs-component|@egjs/component}
53
- * @requires {@link https://github.com/naver/egjs-axes|@egjs/axes}
54
- */
55
58
  export class CrossFlicking extends Flicking {
56
59
  // Core components
57
60
  private _sideFlicking: Flicking[];
58
61
 
59
62
  // Options
60
63
  private _sideOptions: CrossFlickingOptions["sideOptions"];
64
+ private _preserveIndex: CrossFlickingOptions["preserveIndex"];
65
+ private _disableSlideOnHold: CrossFlickingOptions["disableSlideOnHold"];
66
+ private _disableIndexSync: CrossFlickingOptions["disableIndexSync"];
61
67
 
62
68
  // Internal State
63
69
  private _sideState: SideState[];
@@ -65,90 +71,75 @@ export class CrossFlicking extends Flicking {
65
71
  private _nextIndex: number;
66
72
 
67
73
  // Components
68
- /**
69
- * {@link Control} instance of the Flicking
70
- * @ko 현재 Flicking에 활성화된 {@link Control} 인스턴스
71
- * @type {Control}
72
- * @default SnapControl
73
- * @readonly
74
- * @see Control
75
- * @see SnapControl
76
- * @see FreeControl
77
- */
78
74
  public get sideFlicking() {
79
75
  return this._sideFlicking;
80
76
  }
81
77
 
82
- // Internal States
83
- /**
84
- * Whether Flicking's {@link Flicking#init init()} is called.
85
- * This is `true` when {@link Flicking#init init()} is called, and is `false` after calling {@link Flicking#destroy destroy()}.
86
- * @ko Flicking의 {@link Flicking#init init()}이 호출되었는지를 나타내는 멤버 변수.
87
- * 이 값은 {@link Flicking#init init()}이 호출되었으면 `true`로 변하고, {@link Flicking#destroy destroy()}호출 이후에 다시 `false`로 변경됩니다.
88
- * @type {boolean}
89
- * @default false
90
- * @readonly
91
- */
92
78
  public get sideState() {
93
79
  return this._sideState;
94
80
  }
95
81
 
96
82
  // Options Getter
97
- /**
98
- * Change active panel index on mouse/touch hold while animating.
99
- * `index` of the `willChange`/`willRestore` event will be used as new index.
100
- * @ko 애니메이션 도중 마우스/터치 입력시 현재 활성화된 패널의 인덱스를 변경합니다.
101
- * `willChange`/`willRestore` 이벤트의 `index`값이 새로운 인덱스로 사용될 것입니다.
102
- * @type {FlickingOptions}
103
- * @default undefined
104
- * @see {@link https://naver.github.io/egjs-flicking/Options#changeonhold changeOnHold ( Options )}
105
- */
106
- public get sideOptions() {
107
- return this._sideOptions;
108
- }
83
+ public get sideOptions() { return this._sideOptions; }
84
+
85
+ public get preserveIndex() { return this._preserveIndex; }
86
+
87
+ public get disableSlideOnHold() { return this._disableSlideOnHold; }
88
+
89
+ public get disableIndexSync() { return this._disableIndexSync; }
109
90
 
110
91
  // Options Setter
111
- // public set align(val: FlickingOptions["align"]) {
112
- // this._align = val;
113
- // }
92
+ public set sideOptions(val: CrossFlickingOptions["sideOptions"]) {
93
+ this._sideOptions = val;
94
+ }
95
+
96
+ public set preserveIndex(val: CrossFlickingOptions["preserveIndex"]) {
97
+ this._preserveIndex = val;
98
+ }
99
+
100
+ public set disableSlideOnHold(val: CrossFlickingOptions["disableSlideOnHold"]) {
101
+ this._disableSlideOnHold = val;
102
+ }
103
+
104
+ public set disableIndexSync(val: CrossFlickingOptions["disableIndexSync"]) {
105
+ this._disableIndexSync = val;
106
+ }
114
107
 
115
108
  public constructor(
116
109
  root: HTMLElement | string,
117
- options: Partial<CrossFlickingOptions> = {}
110
+ options: Partial<CrossFlickingOptions>
118
111
  ) {
119
112
  super(root, options);
113
+ const {
114
+ sideOptions = {},
115
+ preserveIndex = true,
116
+ disableSlideOnHold = true,
117
+ disableIndexSync = false
118
+ } = options;
120
119
 
121
120
  // Internal states
122
- this._sideState = this._createSideState();
123
121
  this._moveDirection = null;
124
122
  this._nextIndex = 0;
125
123
 
126
124
  // Bind options
127
- this._sideOptions = options.sideOptions;
128
-
129
- // Create core components
130
- this._sideFlicking = this._createSideFlicking();
125
+ this._sideOptions = sideOptions;
126
+ this._preserveIndex = preserveIndex;
127
+ this._disableSlideOnHold = disableSlideOnHold;
128
+ this._disableIndexSync = disableIndexSync;
131
129
  }
132
130
 
133
- /**
134
- * Initialize Flicking and move to the default index
135
- * This is automatically called on Flicking's constructor when `autoInit` is true(default)
136
- * @ko Flicking을 초기화하고, 디폴트 인덱스로 이동합니다
137
- * 이 메소드는 `autoInit` 옵션이 true(default)일 경우 Flicking이 생성될 때 자동으로 호출됩니다
138
- * @fires Flicking#ready
139
- * @return {Promise<void>}
140
- */
141
131
  public init(): Promise<void> {
142
- return super.init().then(() => this._addComponentEvents());
132
+ return super.init().then(() => {
133
+ this._sideState = this._createSideState();
134
+ this._sideFlicking = this._createSideFlicking();
135
+ this._addComponentEvents();
136
+ });
143
137
  }
144
138
 
145
- /**
146
- * Destroy Flicking and remove all event handlers
147
- * @ko Flicking과 하위 컴포넌트들을 초기 상태로 되돌리고, 부착된 모든 이벤트 핸들러를 제거합니다
148
- * @return {void}
149
- */
150
139
  public destroy(): void {
151
- // TODO 모든 child flicking destroy
140
+ this._sideFlicking.forEach((flicking) => {
141
+ flicking.destroy();
142
+ });
152
143
  super.destroy();
153
144
  }
154
145
 
@@ -157,140 +148,151 @@ export class CrossFlicking extends Flicking {
157
148
  this.on(EVENTS.MOVE, this._onHorizontalMove);
158
149
  this.on(EVENTS.MOVE_END, this._onHorizontalMoveEnd);
159
150
 
160
- this._sideFlicking.forEach((flicking) => {
151
+ this._sideFlicking.forEach((flicking, mainIndex) => {
161
152
  flicking.on(EVENTS.HOLD_START, this._onSideHoldStart);
162
153
  flicking.on(EVENTS.MOVE, this._onSideMove);
163
154
  flicking.on(EVENTS.MOVE_END, this._onSideMoveEnd);
164
155
  flicking.on(EVENTS.CHANGED, this._onSideChanged);
156
+
157
+ Object.keys(SIDE_EVENTS).forEach((name: EventKey<FlickingEvents>) => {
158
+ flicking.on(EVENTS[name], (event) => {
159
+ this.trigger(
160
+ new ComponentEvent(SIDE_EVENTS[name], {
161
+ mainIndex,
162
+ ...event
163
+ })
164
+ );
165
+ });
166
+ });
165
167
  });
166
168
  }
167
169
 
168
170
  private _createSideState(): SideState[] {
169
- // data-index로 분류하기 전에 임시로 모든 children에 대해 side flicking으로 해보자.
170
- // panels에 data-attributes가 붙어있을 때와 안 붙어있을 때를 다르게 처리
171
- // 붙어있다면 가상의 viewport들을 index 갯수만큼 만들어줘야 한다
172
171
  const viewportEl = this.element;
173
172
  const cameraEl = this.camera.element;
174
173
  const panels = toArray(cameraEl.children) as HTMLElement[];
174
+ const isCrossStructure = getDataAttributes(
175
+ viewportEl,
176
+ "data-cross-"
177
+ ).structure;
175
178
  let sideState: SideState[] = [];
176
- let sidePanels: string = "";
177
179
 
178
- // check data attribute exists
179
- const groupKeys: string[] = [];
180
- const groupPanels: Record<string, HTMLElement[]> = {};
180
+ if (!isCrossStructure) {
181
+ const groupPanels = this._getGroupFromAttribute(panels);
182
+ const groupKeys = Object.keys(groupPanels);
183
+
184
+ if (groupKeys.length) {
185
+ sideState = this._getSideStateFromGroup(groupPanels);
186
+ this.remove(0, this.panelCount - groupKeys.length);
187
+ } else {
188
+ sideState = this._getSideStateFromPanels(panels);
189
+ }
190
+
191
+ this._createCrossStructure(sideState);
192
+ } else {
193
+ sideState = this._getSideStateFromCrossStructure(panels);
194
+ }
195
+
196
+ void this.resize();
197
+
198
+ return sideState;
199
+ }
200
+
201
+ private _createCrossStructure(sideState: SideState[]) {
181
202
  const sideCamera = document.createElement("div");
203
+ let sidePanels: string = "";
204
+
182
205
  sideCamera.classList.add(CLASS.CAMERA);
206
+ sideState.forEach((state, i) => {
207
+ const panel = this.camera.children[i];
208
+ sidePanels += state.element.innerHTML;
209
+ Array.from(panel.attributes).forEach((attribute) =>
210
+ panel.removeAttribute(attribute.name)
211
+ );
212
+ });
183
213
 
184
- const isCrossStructure = getDataAttributes(viewportEl, "data-cross-").structure;
214
+ sideCamera.innerHTML = sidePanels;
185
215
 
186
- if (!isCrossStructure) {
187
- viewportEl.setAttribute("data-cross-structure", "true");
188
-
189
- panels.forEach((panel) => {
190
- const groupKey = getDataAttributes(panel, "data-cross-").groupkey;
191
- if (groupKey && !includes(groupKeys, groupKey)) {
192
- groupKeys.push(groupKey);
193
- groupPanels[groupKey] = [panel];
194
- } else if (groupKey) {
195
- groupPanels[groupKey].push(panel);
216
+ sideState.forEach((_, i) => {
217
+ const panel = this.camera.children[i];
218
+ [CLASS.VIEWPORT, CLASS.VERTICAL].forEach((className) => {
219
+ if (!panel.classList.contains(className)) {
220
+ panel.classList.add(className);
196
221
  }
197
222
  });
223
+ panel.innerHTML = sideCamera.outerHTML;
224
+ });
198
225
 
199
- if (groupKeys.length) {
200
- sideState = groupKeys.reduce(
201
- (state: SideState[], key: string) => {
202
- const start = state.length ? +state[state.length - 1].end + 1 : 0;
203
- const element = groupPanels[key].reduce(
204
- (el: HTMLElement, panel: HTMLElement) => {
205
- sidePanels += panel.outerHTML;
206
- el.innerHTML += panel.outerHTML;
207
- return el;
208
- },
209
- document.createElement("div")
210
- );
211
- return [
212
- ...state,
213
- {
214
- key,
215
- start,
216
- end: start + groupPanels[key].length - 1,
217
- element: element
218
- }
219
- ];
220
- },
221
- []
222
- );
226
+ this.element.setAttribute("data-cross-structure", "true");
227
+ }
223
228
 
224
- this.remove(0, this.panelCount - groupKeys.length);
225
- sideState.forEach((_, i) => {
226
- const panel = this.camera.children[i];
227
- Array.from(panel.attributes).forEach(attribute => panel.removeAttribute(attribute.name));
228
- });
229
- } else {
230
- sideState = panels.reduce(
231
- (state: SideState[], panel: HTMLElement, i: number) => {
232
- const start = state.length ? +state[state.length - 1].end + 1 : 0;
233
- sidePanels += panel.innerHTML;
234
- return [
235
- ...state,
236
- {
237
- key: i.toString(),
238
- start,
239
- end: start + panel.children.length - 1,
240
- element: panel
241
- }
242
- ];
243
- },
244
- []
245
- );
229
+ private _getGroupFromAttribute(
230
+ panels: HTMLElement[]
231
+ ): Record<string, HTMLElement[]> {
232
+ const groupKeys: string[] = [];
233
+ const groupPanels: Record<string, HTMLElement[]> = {};
234
+
235
+ panels.forEach((panel) => {
236
+ const groupKey = getDataAttributes(panel, "data-cross-").groupkey;
237
+ if (groupKey && !includes(groupKeys, groupKey)) {
238
+ groupKeys.push(groupKey);
239
+ groupPanels[groupKey] = [panel];
240
+ } else if (groupKey) {
241
+ groupPanels[groupKey].push(panel);
246
242
  }
243
+ });
247
244
 
248
- sideCamera.innerHTML = sidePanels;
249
- sideState.forEach((_, i) => {
250
- const panel = this.camera.children[i];
251
- [CLASS.VIEWPORT, CLASS.VERTICAL].forEach((className) => {
252
- if (!panel.classList.contains(className)) {
253
- panel.classList.add(className);
245
+ return groupPanels;
246
+ }
247
+
248
+ private _getSideStateFromGroup(
249
+ groupPanels: Record<string, HTMLElement[]>
250
+ ): SideState[] {
251
+ return Object.keys(groupPanels).reduce(
252
+ (state: SideState[], key: string) => {
253
+ const start = state.length ? +state[state.length - 1].end + 1 : 0;
254
+ const element = groupPanels[key].reduce(
255
+ (el: HTMLElement, panel: HTMLElement) => {
256
+ el.innerHTML += panel.outerHTML;
257
+ return el;
258
+ },
259
+ document.createElement("div")
260
+ );
261
+ return [
262
+ ...state,
263
+ {
264
+ key,
265
+ start,
266
+ end: start + groupPanels[key].length - 1,
267
+ element: element
254
268
  }
255
- });
256
- panel.innerHTML = sideCamera.outerHTML;
257
- });
258
- } else {
259
- (toArray(panels[0].children[0].children) as HTMLElement[]).forEach((panel) => {
260
- const groupKey = getDataAttributes(panel, "data-cross-").groupkey;
261
- if (groupKey && !includes(groupKeys, groupKey)) {
262
- groupKeys.push(groupKey);
263
- groupPanels[groupKey] = [panel];
264
- } else if (groupKey) {
265
- groupPanels[groupKey].push(panel);
266
- }
267
- });
269
+ ];
270
+ },
271
+ []
272
+ );
273
+ }
268
274
 
269
- sideState = groupKeys.reduce(
270
- (state: SideState[], key: string) => {
271
- const start = state.length ? +state[state.length - 1].end + 1 : 0;
272
- const element = groupPanels[key].reduce(
273
- (el: HTMLElement, panel: HTMLElement) => {
274
- el.innerHTML += panel.outerHTML;
275
- return el;
276
- },
277
- document.createElement("div")
278
- );
279
- return [
280
- ...state,
281
- {
282
- key,
283
- start,
284
- end: start + groupPanels[key].length - 1,
285
- element: element
286
- }
287
- ];
288
- },
289
- []
290
- );
291
- }
275
+ private _getSideStateFromPanels(panels: HTMLElement[]): SideState[] {
276
+ return panels.reduce(
277
+ (state: SideState[], panel: HTMLElement, i: number) => {
278
+ const start = state.length ? +state[state.length - 1].end + 1 : 0;
279
+ return [
280
+ ...state,
281
+ {
282
+ key: i.toString(),
283
+ start,
284
+ end: start + panel.children.length - 1,
285
+ element: panel
286
+ }
287
+ ];
288
+ },
289
+ []
290
+ );
291
+ }
292
292
 
293
- return sideState;
293
+ private _getSideStateFromCrossStructure(panels: HTMLElement[]): SideState[] {
294
+ const groupPanels = this._getGroupFromAttribute(panels);
295
+ return this._getSideStateFromGroup(groupPanels);
294
296
  }
295
297
 
296
298
  private _createSideFlicking(): Flicking[] {
@@ -304,7 +306,11 @@ export class CrossFlicking extends Flicking {
304
306
  });
305
307
  }
306
308
 
307
- private _syncToCategory(index: number, outerIndex: number): void {
309
+ private _syncToCategory = (index: number, outerIndex: number): void => {
310
+ if (this._disableIndexSync) {
311
+ return;
312
+ }
313
+
308
314
  this.stopAnimation();
309
315
  this._sideFlicking.forEach((child, i) => {
310
316
  const { start, end } = this._sideState[i];
@@ -315,18 +321,61 @@ export class CrossFlicking extends Flicking {
315
321
  void this.moveTo(i, 0);
316
322
  }
317
323
  });
318
- }
324
+ };
325
+
326
+ private _setDraggable = (
327
+ direction: ValueOf<typeof MOVE_DIRECTION>,
328
+ draggable: boolean
329
+ ): void => {
330
+ if (!this._disableSlideOnHold) {
331
+ return;
332
+ }
333
+
334
+ const threshold = draggable
335
+ ? this.dragThreshold && this.dragThreshold >= 10
336
+ ? this.dragThreshold
337
+ : 10
338
+ : Infinity;
339
+
340
+ if ((direction === MOVE_DIRECTION.HORIZONTAL) === this.horizontal) {
341
+ this.dragThreshold = threshold;
342
+ } else if ((direction === MOVE_DIRECTION.VERTICAL) === this.horizontal) {
343
+ this._sideFlicking.forEach((child) => {
344
+ child.dragThreshold = threshold;
345
+ });
346
+ }
347
+ };
348
+
349
+ private _setPreviousSideIndex = () => {
350
+ this._sideFlicking.forEach((child, i) => {
351
+ const { start, end } = this._sideState[i];
352
+
353
+ if (this._preserveIndex) {
354
+ if (this._nextIndex !== i) {
355
+ if (child.index < start) {
356
+ child.stopAnimation();
357
+ void child.moveTo(start, 0);
358
+ } else if (child.index > end) {
359
+ child.stopAnimation();
360
+ void child.moveTo(end, 0);
361
+ }
362
+ }
363
+ } else {
364
+ if (this._nextIndex !== i) {
365
+ void child.moveTo(start, 0);
366
+ }
367
+ }
368
+ });
369
+ };
319
370
 
320
371
  private _onHorizontalHoldStart = (): void => {
321
- this.dragThreshold = 10;
372
+ this._setDraggable(MOVE_DIRECTION.HORIZONTAL, true);
322
373
  this._moveDirection = null;
323
374
  };
324
375
 
325
376
  private _onHorizontalMove = (e: MoveEvent): void => {
326
377
  if (e.isTrusted && !this._moveDirection) {
327
- this._sideFlicking.forEach((child) => {
328
- child.dragThreshold = Infinity;
329
- });
378
+ this._setDraggable(MOVE_DIRECTION.VERTICAL, false);
330
379
  this._moveDirection = MOVE_DIRECTION.HORIZONTAL;
331
380
  }
332
381
  };
@@ -334,11 +383,6 @@ export class CrossFlicking extends Flicking {
334
383
  private _onHorizontalMoveEnd = (e: MoveEndEvent): void => {
335
384
  const visiblePanels = this.visiblePanels;
336
385
 
337
- this._sideFlicking.forEach((child) => {
338
- child.dragThreshold = 10;
339
- });
340
- this._moveDirection = null;
341
-
342
386
  if (visiblePanels.length > 1) {
343
387
  this._nextIndex =
344
388
  e.direction === "NEXT"
@@ -348,20 +392,11 @@ export class CrossFlicking extends Flicking {
348
392
  this._nextIndex = visiblePanels[0].index;
349
393
  }
350
394
 
351
- // _syncToCategory에서 완전히 가로 이동이 이루어지기 전에 세로 방향 index가 변하는 경우가 있어 timeout으로 처리
352
- this._sideFlicking.forEach((child, i) => {
353
- if (this._nextIndex !== i) {
354
- const { start, end } = this._sideState[i];
395
+ this._setDraggable(MOVE_DIRECTION.VERTICAL, true);
396
+ this._moveDirection = null;
355
397
 
356
- if (child.index < start) {
357
- child.stopAnimation();
358
- void child.moveTo(start, 0);
359
- } else if (child.index > end) {
360
- child.stopAnimation();
361
- void child.moveTo(end, 0);
362
- }
363
- }
364
- });
398
+ // _syncToCategory에서 완전히 가로 이동이 이루어지기 전에 세로 방향 index 변하는 경우가 있어 requestAnimationFrame 처리
399
+ requestAnimationFrame(() => this._setPreviousSideIndex());
365
400
 
366
401
  if (e.isTrusted) {
367
402
  this._syncToCategory(
@@ -372,27 +407,25 @@ export class CrossFlicking extends Flicking {
372
407
  };
373
408
 
374
409
  private _onSideHoldStart = (): void => {
375
- this._sideFlicking.forEach((child) => {
376
- child.dragThreshold = 10;
377
- });
410
+ this._setDraggable(MOVE_DIRECTION.VERTICAL, true);
378
411
  this._moveDirection = null;
379
412
  };
380
413
 
381
414
  private _onSideMove = (e: MoveEvent): void => {
382
415
  if (e.isTrusted && !this._moveDirection) {
383
- this.dragThreshold = Infinity;
416
+ this._setDraggable(MOVE_DIRECTION.HORIZONTAL, false);
384
417
  this._moveDirection = MOVE_DIRECTION.VERTICAL;
385
418
  }
386
419
  };
387
420
 
388
421
  private _onSideMoveEnd = (): void => {
389
- this.dragThreshold = 10;
422
+ this._setDraggable(MOVE_DIRECTION.HORIZONTAL, true);
390
423
  this._moveDirection = null;
391
424
  };
392
425
 
393
426
  private _onSideChanged = (e: ChangedEvent): void => {
394
- // this.visiblePanels.length 2보다 크다면 가로 방향 Flicking이 조작 중이라는 것을 의미합니다.
395
- // 경우 가로 방향 Flicking의 이동이 완전히 끝난 _onHorizontalMoveEnd 에서 syncToCategory할 것이므로 여기서는 하지 않습니다.
427
+ // If this.visiblePanels.length >= 2, it means that horizontal flicking is being dragged.
428
+ // In this case, syncToCategory in _onHorizontalMoveEnd will fire after moving finishes, so we don't fire it here.
396
429
  if (
397
430
  this.visiblePanels.length < 2 &&
398
431
  this._sideFlicking[this.index] === e.currentTarget