@egjs/flicking 4.12.1-beta.1 → 4.12.1-beta.3

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.
@@ -11,7 +11,9 @@ class AutoResizer {
11
11
  private _resizeTimer: number;
12
12
  private _maxResizeDebounceTimer: number;
13
13
 
14
- public get enabled() { return this._enabled; }
14
+ public get enabled() {
15
+ return this._enabled;
16
+ }
15
17
 
16
18
  public constructor(flicking: Flicking) {
17
19
  this._flicking = flicking;
@@ -33,14 +35,14 @@ class AutoResizer {
33
35
  const viewportSizeNot0 = viewport.width !== 0 || viewport.height !== 0;
34
36
 
35
37
  const resizeObserver = viewportSizeNot0
36
- ? new ResizeObserver(this._skipFirstResize)
37
- : new ResizeObserver(this._onResize);
38
+ ? new ResizeObserver((entries: ResizeObserverEntry[]) => this._skipFirstResize(entries))
39
+ : new ResizeObserver((entries: ResizeObserverEntry[]) => this._onResize(entries));
38
40
 
39
41
  resizeObserver.observe(flicking.viewport.element);
40
42
 
41
43
  this._resizeObserver = resizeObserver;
42
44
  } else {
43
- window.addEventListener("resize", this._onResize);
45
+ window.addEventListener("resize", () => this._onResize([]));
44
46
  }
45
47
 
46
48
  this._enabled = true;
@@ -56,7 +58,7 @@ class AutoResizer {
56
58
  resizeObserver.disconnect();
57
59
  this._resizeObserver = null;
58
60
  } else {
59
- window.removeEventListener("resize", this._onResize);
61
+ window.removeEventListener("resize", () => this._onResize([]));
60
62
  }
61
63
 
62
64
  this._enabled = false;
@@ -64,17 +66,41 @@ class AutoResizer {
64
66
  return this;
65
67
  }
66
68
 
67
- private _onResize = () => {
69
+ private _onResize = (entries: ResizeObserverEntry[]) => {
68
70
  const flicking = this._flicking;
69
71
  const resizeDebounce = flicking.resizeDebounce;
70
72
  const maxResizeDebounce = flicking.maxResizeDebounce;
71
73
 
74
+ if (entries.length) {
75
+ const resizeEntryInfo = entries[0].contentRect;
76
+ const beforeSize = {
77
+ width: flicking.viewport.width,
78
+ height: flicking.viewport.height
79
+ };
80
+
81
+ const afterSize = {
82
+ width: resizeEntryInfo.width,
83
+ height: resizeEntryInfo.height
84
+ };
85
+
86
+ // resize 이벤트가 발생했으나 이전과 width, height의 변화가 없다면 이후 로직을 진행하지 않는다.
87
+ if (
88
+ beforeSize.height === afterSize.height &&
89
+ beforeSize.width === afterSize.width
90
+ ) {
91
+ return;
92
+ }
93
+ }
94
+
72
95
  if (resizeDebounce <= 0) {
73
96
  void flicking.resize();
74
97
  } else {
75
98
  if (this._maxResizeDebounceTimer <= 0) {
76
99
  if (maxResizeDebounce > 0 && maxResizeDebounce >= resizeDebounce) {
77
- this._maxResizeDebounceTimer = window.setTimeout(this._doScheduledResize, maxResizeDebounce);
100
+ this._maxResizeDebounceTimer = window.setTimeout(
101
+ this._doScheduledResize,
102
+ maxResizeDebounce
103
+ );
78
104
  }
79
105
  }
80
106
 
@@ -83,7 +109,10 @@ class AutoResizer {
83
109
  this._resizeTimer = 0;
84
110
  }
85
111
 
86
- this._resizeTimer = window.setTimeout(this._doScheduledResize, resizeDebounce);
112
+ this._resizeTimer = window.setTimeout(
113
+ this._doScheduledResize,
114
+ resizeDebounce
115
+ );
87
116
  }
88
117
  };
89
118
 
@@ -101,13 +130,13 @@ class AutoResizer {
101
130
  private _skipFirstResize = (() => {
102
131
  let isFirstResize = true;
103
132
 
104
- return (() => {
133
+ return (entries) => {
105
134
  if (isFirstResize) {
106
135
  isFirstResize = false;
107
136
  return;
108
137
  }
109
- this._onResize();
110
- });
138
+ this._onResize(entries);
139
+ };
111
140
  })();
112
141
  }
113
142