@egjs/react-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.
- package/declaration/CrossFlicking.d.ts +16 -3
- package/declaration/Flicking.d.ts +15 -1
- package/declaration/types.d.ts +0 -2
- package/dist/flicking.cjs.js +48 -31
- package/dist/flicking.cjs.js.map +1 -1
- package/dist/flicking.esm.js +94 -35
- package/dist/flicking.esm.js.map +1 -1
- package/dist/flicking.umd.js +48 -31
- package/dist/flicking.umd.js.map +1 -1
- package/package.json +2 -2
- package/src/react-flicking/CrossFlicking.tsx +93 -39
- package/src/react-flicking/Flicking.tsx +51 -35
- package/src/react-flicking/consts.ts +1 -0
- package/src/react-flicking/types.ts +1 -3
|
@@ -3,68 +3,83 @@
|
|
|
3
3
|
* egjs projects are licensed under the MIT license
|
|
4
4
|
*/
|
|
5
5
|
import * as React from "react";
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import VanillaFlicking, {
|
|
6
|
+
import ListDiffer from "@egjs/list-differ";
|
|
7
|
+
import {
|
|
9
8
|
CrossFlicking as VanillaCrossFlicking,
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
NormalRenderingStrategy,
|
|
10
|
+
CrossFlickingEvent,
|
|
11
|
+
HoldStartEvent,
|
|
12
|
+
HoldEndEvent,
|
|
13
|
+
MoveStartEvent,
|
|
14
|
+
MoveEvent,
|
|
15
|
+
MoveEndEvent,
|
|
16
|
+
WillChangeEvent,
|
|
17
|
+
ChangedEvent,
|
|
12
18
|
EVENTS,
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
getDefaultCameraTransform,
|
|
17
|
-
Plugin,
|
|
18
|
-
range,
|
|
19
|
-
NormalRenderingStrategy
|
|
19
|
+
SIDE_EVENTS,
|
|
20
|
+
CrossFlickingOptions,
|
|
21
|
+
FlickingOptions,
|
|
20
22
|
} from "@egjs/flicking";
|
|
21
23
|
|
|
22
24
|
import { DEFAULT_PROPS } from "./consts";
|
|
23
|
-
import {
|
|
25
|
+
import { FlickingProps } from "./types";
|
|
24
26
|
import ReactRenderer, { ReactRendererOptions } from "./ReactRenderer";
|
|
25
|
-
import StrictPanel from "./StrictPanel";
|
|
26
|
-
import NonStrictPanel from "./NonStrictPanel";
|
|
27
|
-
import ViewportSlot from "./ViewportSlot";
|
|
28
27
|
import ReactElementProvider from "./ReactElementProvider";
|
|
29
28
|
import Flicking from "./Flicking";
|
|
30
29
|
|
|
30
|
+
export interface CrossFlickingProps extends FlickingProps {
|
|
31
|
+
onSideHoldStart: (e: CrossFlickingEvent<HoldStartEvent<Flicking>>) => any;
|
|
32
|
+
onSideHoldEnd: (e: CrossFlickingEvent<HoldEndEvent<Flicking>>) => any;
|
|
33
|
+
onSideMoveStart: (e: CrossFlickingEvent<MoveStartEvent<Flicking>>) => any;
|
|
34
|
+
onSideMove: (e: CrossFlickingEvent<MoveEvent<Flicking>>) => any;
|
|
35
|
+
onSideMoveEnd: (e: CrossFlickingEvent<MoveEndEvent<Flicking>>) => any;
|
|
36
|
+
onSideWillChange: (e: CrossFlickingEvent<WillChangeEvent<Flicking>>) => any;
|
|
37
|
+
onSideChanged: (e: CrossFlickingEvent<ChangedEvent<Flicking>>) => any;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export const CROSSFLICKING_DEFAULT_PROPS: CrossFlickingProps = {
|
|
41
|
+
...DEFAULT_PROPS,
|
|
42
|
+
onSideHoldStart: (e: CrossFlickingEvent<HoldStartEvent>) => {},
|
|
43
|
+
onSideHoldEnd: (e: CrossFlickingEvent<HoldEndEvent>) => {},
|
|
44
|
+
onSideMoveStart: (e: CrossFlickingEvent<MoveStartEvent>) => {},
|
|
45
|
+
onSideMove: (e: CrossFlickingEvent<MoveEvent>) => {},
|
|
46
|
+
onSideMoveEnd: (e: CrossFlickingEvent<MoveEndEvent>) => {},
|
|
47
|
+
onSideWillChange: (e: CrossFlickingEvent<WillChangeEvent>) => {},
|
|
48
|
+
onSideChanged: (e: CrossFlickingEvent<ChangedEvent>) => {},
|
|
49
|
+
};
|
|
50
|
+
|
|
31
51
|
class CrossFlicking extends Flicking {
|
|
32
|
-
public static defaultProps: CrossFlickingProps =
|
|
52
|
+
public static defaultProps: CrossFlickingProps = CROSSFLICKING_DEFAULT_PROPS;
|
|
33
53
|
|
|
34
|
-
public constructor(
|
|
54
|
+
public constructor(
|
|
55
|
+
props: Partial<
|
|
56
|
+
FlickingProps &
|
|
57
|
+
FlickingOptions &
|
|
58
|
+
CrossFlickingOptions &
|
|
59
|
+
CrossFlickingProps
|
|
60
|
+
>
|
|
61
|
+
) {
|
|
35
62
|
super(props);
|
|
36
63
|
}
|
|
37
64
|
|
|
38
65
|
public componentDidMount() {
|
|
39
|
-
const props = this.props as Required<
|
|
66
|
+
const props = this.props as Required<CrossFlickingProps>;
|
|
40
67
|
const rendererOptions: ReactRendererOptions = {
|
|
41
68
|
reactFlicking: this,
|
|
42
69
|
strategy: new NormalRenderingStrategy({
|
|
43
|
-
providerCtor: ReactElementProvider
|
|
44
|
-
})
|
|
70
|
+
providerCtor: ReactElementProvider,
|
|
71
|
+
}),
|
|
45
72
|
};
|
|
46
73
|
|
|
47
|
-
const flicking = new VanillaCrossFlicking(
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
externalRenderer: new ReactRenderer(rendererOptions),
|
|
52
|
-
sideOptions: {
|
|
53
|
-
...props.sideOptions,
|
|
54
|
-
// externalRenderer: new ReactRenderer({
|
|
55
|
-
// reactFlicking: this,
|
|
56
|
-
// strategy: new NormalRenderingStrategy({
|
|
57
|
-
// providerCtor: ReactElementProvider
|
|
58
|
-
// })
|
|
59
|
-
// }),
|
|
60
|
-
}
|
|
61
|
-
},
|
|
62
|
-
);
|
|
74
|
+
const flicking = new VanillaCrossFlicking(this._viewportElement, {
|
|
75
|
+
...props,
|
|
76
|
+
externalRenderer: new ReactRenderer(rendererOptions),
|
|
77
|
+
});
|
|
63
78
|
|
|
64
79
|
this._vanillaFlicking = flicking;
|
|
65
80
|
|
|
66
81
|
const children = this._getChildren();
|
|
67
|
-
this._jsxDiffer = new ListDiffer(children, panel => panel.key!);
|
|
82
|
+
this._jsxDiffer = new ListDiffer(children, (panel) => panel.key!);
|
|
68
83
|
this._pluginsDiffer = new ListDiffer<any>();
|
|
69
84
|
this._prevChildren = children;
|
|
70
85
|
|
|
@@ -75,7 +90,46 @@ class CrossFlicking extends Flicking {
|
|
|
75
90
|
flicking.setStatus(props.status);
|
|
76
91
|
}
|
|
77
92
|
}
|
|
93
|
+
|
|
94
|
+
public render() {
|
|
95
|
+
const props = this.props;
|
|
96
|
+
const Viewport = props.viewportTag as any;
|
|
97
|
+
const Camera = props.cameraTag as any;
|
|
98
|
+
const attributes: { [key: string]: any } = {};
|
|
99
|
+
|
|
100
|
+
this.beforeRender();
|
|
101
|
+
|
|
102
|
+
for (const name in props) {
|
|
103
|
+
if (!(name in CROSSFLICKING_DEFAULT_PROPS) && !(name in VanillaCrossFlicking.prototype)) {
|
|
104
|
+
attributes[name] = props[name];
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
const { viewportClasses, cameraClasses, cameraProps } = this._getClasses(attributes, props);
|
|
109
|
+
|
|
110
|
+
const panels = this._getPanels();
|
|
111
|
+
|
|
112
|
+
return (
|
|
113
|
+
<Viewport {...attributes} className={viewportClasses.join(" ")} ref={(e?: HTMLElement) => {
|
|
114
|
+
e && (this._viewportElement = e);
|
|
115
|
+
}}>
|
|
116
|
+
<Camera className={cameraClasses.join(" ")} {...cameraProps}>
|
|
117
|
+
{ panels }
|
|
118
|
+
</Camera>
|
|
119
|
+
{ this._getViewportSlot() }
|
|
120
|
+
</Viewport>
|
|
121
|
+
);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
protected _bindEvents() {
|
|
125
|
+
super._bindEvents();
|
|
126
|
+
|
|
127
|
+
Object.keys(SIDE_EVENTS).forEach((eventKey: keyof typeof EVENTS) => {
|
|
128
|
+
const eventName = SIDE_EVENTS[eventKey];
|
|
129
|
+
this._bindEvent(eventName);
|
|
130
|
+
});
|
|
131
|
+
}
|
|
78
132
|
}
|
|
79
133
|
|
|
80
|
-
interface CrossFlicking extends Flicking {
|
|
134
|
+
interface CrossFlicking extends Flicking {}
|
|
81
135
|
export default CrossFlicking;
|
|
@@ -15,7 +15,8 @@ import VanillaFlicking, {
|
|
|
15
15
|
getDefaultCameraTransform,
|
|
16
16
|
Plugin,
|
|
17
17
|
range,
|
|
18
|
-
NormalRenderingStrategy
|
|
18
|
+
NormalRenderingStrategy,
|
|
19
|
+
FlickingEvents,
|
|
19
20
|
} from "@egjs/flicking";
|
|
20
21
|
|
|
21
22
|
import { DEFAULT_PROPS } from "./consts";
|
|
@@ -156,7 +157,6 @@ class Flicking extends React.Component<Partial<FlickingProps & FlickingOptions>>
|
|
|
156
157
|
const Viewport = props.viewportTag as any;
|
|
157
158
|
const Camera = props.cameraTag as any;
|
|
158
159
|
const attributes: { [key: string]: any } = {};
|
|
159
|
-
const flicking = this._vanillaFlicking;
|
|
160
160
|
|
|
161
161
|
this.beforeRender();
|
|
162
162
|
|
|
@@ -166,31 +166,7 @@ class Flicking extends React.Component<Partial<FlickingProps & FlickingOptions>>
|
|
|
166
166
|
}
|
|
167
167
|
}
|
|
168
168
|
|
|
169
|
-
const
|
|
170
|
-
const viewportClasses: string[] = ["flicking-viewport"];
|
|
171
|
-
const cameraClasses: string[] = ["flicking-camera"];
|
|
172
|
-
const isHorizontal = flicking
|
|
173
|
-
? flicking.horizontal
|
|
174
|
-
: props.horizontal ?? true;
|
|
175
|
-
|
|
176
|
-
if (!isHorizontal) {
|
|
177
|
-
viewportClasses.push("vertical");
|
|
178
|
-
}
|
|
179
|
-
if (props.hideBeforeInit && !initialized) {
|
|
180
|
-
viewportClasses.push("flicking-hidden");
|
|
181
|
-
}
|
|
182
|
-
if (attributes.className) {
|
|
183
|
-
viewportClasses.push(attributes.className);
|
|
184
|
-
}
|
|
185
|
-
if (props.cameraClass) {
|
|
186
|
-
cameraClasses.push(props.cameraClass);
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
const cameraProps = !initialized && props.firstPanelSize
|
|
190
|
-
? { style: {
|
|
191
|
-
transform: getDefaultCameraTransform(this.props.align, this.props.horizontal, this.props.firstPanelSize)
|
|
192
|
-
}}
|
|
193
|
-
: {};
|
|
169
|
+
const { viewportClasses, cameraClasses, cameraProps } = this._getClasses(attributes, props);
|
|
194
170
|
|
|
195
171
|
const panels = !!props.virtual && (props.panelsPerView ?? -1) > 0
|
|
196
172
|
? this._getVirtualPanels()
|
|
@@ -221,14 +197,7 @@ class Flicking extends React.Component<Partial<FlickingProps & FlickingOptions>>
|
|
|
221
197
|
|
|
222
198
|
Object.keys(EVENTS).forEach((eventKey: keyof typeof EVENTS) => {
|
|
223
199
|
const eventName = EVENTS[eventKey];
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
flicking.on(eventName, e => {
|
|
227
|
-
e.currentTarget = this;
|
|
228
|
-
|
|
229
|
-
const evtHandler = this.props[propName];
|
|
230
|
-
evtHandler(e);
|
|
231
|
-
});
|
|
200
|
+
this._bindEvent(eventName);
|
|
232
201
|
});
|
|
233
202
|
|
|
234
203
|
flicking.once(EVENTS.READY, () => {
|
|
@@ -236,6 +205,17 @@ class Flicking extends React.Component<Partial<FlickingProps & FlickingOptions>>
|
|
|
236
205
|
});
|
|
237
206
|
}
|
|
238
207
|
|
|
208
|
+
protected _bindEvent(eventName: keyof FlickingEvents) {
|
|
209
|
+
const propName = `on${eventName.charAt(0).toUpperCase() + eventName.slice(1)}`;
|
|
210
|
+
|
|
211
|
+
this._vanillaFlicking!.on(eventName, e => {
|
|
212
|
+
e.currentTarget = this;
|
|
213
|
+
|
|
214
|
+
const evtHandler = this.props[propName];
|
|
215
|
+
evtHandler(e);
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
|
|
239
219
|
protected _checkPlugins() {
|
|
240
220
|
const flicking = this._vanillaFlicking;
|
|
241
221
|
const { list, added, removed, prevList } = this._pluginsDiffer.update(this.props.plugins!) as DiffResult<Plugin>;
|
|
@@ -244,6 +224,42 @@ class Flicking extends React.Component<Partial<FlickingProps & FlickingOptions>>
|
|
|
244
224
|
flicking.removePlugins(...removed.map(index => prevList[index]));
|
|
245
225
|
}
|
|
246
226
|
|
|
227
|
+
protected _getClasses(attributes: { [key: string]: any }, props: typeof this.props) {
|
|
228
|
+
const flicking = this._vanillaFlicking;
|
|
229
|
+
|
|
230
|
+
const initialized = flicking && flicking.initialized;
|
|
231
|
+
const viewportClasses: string[] = ["flicking-viewport"];
|
|
232
|
+
const cameraClasses: string[] = ["flicking-camera"];
|
|
233
|
+
const isHorizontal = flicking
|
|
234
|
+
? flicking.horizontal
|
|
235
|
+
: props.horizontal ?? true;
|
|
236
|
+
|
|
237
|
+
if (!isHorizontal) {
|
|
238
|
+
viewportClasses.push("vertical");
|
|
239
|
+
}
|
|
240
|
+
if (props.hideBeforeInit && !initialized) {
|
|
241
|
+
viewportClasses.push("flicking-hidden");
|
|
242
|
+
}
|
|
243
|
+
if (attributes.className) {
|
|
244
|
+
viewportClasses.push(attributes.className);
|
|
245
|
+
}
|
|
246
|
+
if (props.cameraClass) {
|
|
247
|
+
cameraClasses.push(props.cameraClass);
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
const cameraProps = !initialized && props.firstPanelSize
|
|
251
|
+
? { style: {
|
|
252
|
+
transform: getDefaultCameraTransform(this.props.align, this.props.horizontal, this.props.firstPanelSize)
|
|
253
|
+
}}
|
|
254
|
+
: {};
|
|
255
|
+
|
|
256
|
+
return {
|
|
257
|
+
viewportClasses,
|
|
258
|
+
cameraClasses,
|
|
259
|
+
cameraProps,
|
|
260
|
+
};
|
|
261
|
+
}
|
|
262
|
+
|
|
247
263
|
private _hasSameChildren(prevChildren: React.ReactElement[], nextChildren: React.ReactElement[]) {
|
|
248
264
|
if (prevChildren.length !== nextChildren.length || prevChildren.length === 0) return false;
|
|
249
265
|
|