Skip to content

Commit d0cfd64

Browse files
committed
fix: fix renderOnlyVIsible issue with #931
1 parent 5b155a4 commit d0cfd64

File tree

3 files changed

+17
-22
lines changed

3 files changed

+17
-22
lines changed

packages/react-flicking/src/react-flicking/Flicking.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -312,12 +312,12 @@ class Flicking extends React.Component<Partial<FlickingProps & FlickingOptions>>
312312
: {};
313313

314314
return renderingIndexes.map(idx => {
315-
return <div
316-
key={idx}
317-
data-element-index={idx}
318-
ref={this._panels[idx] as React.RefObject<HTMLDivElement>}
319-
className={panelClass}
320-
style={size} />
315+
return <StrictPanel key={idx} ref={this._panels[idx] as any}>
316+
<div
317+
data-element-index={idx}
318+
className={panelClass}
319+
style={size} />
320+
</StrictPanel>;
321321
});
322322
}
323323

packages/react-flicking/src/react-flicking/ReactElementProvider.ts

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,24 @@
55
import { ElementProvider } from "@egjs/flicking";
66
import StrictPanel from "./StrictPanel";
77
import NonStrictPanel from "./NonStrictPanel";
8+
import React from "react";
89

910
class ReactElementProvider implements ElementProvider {
10-
private _elRef: React.RefObject<HTMLElement>;
11+
private _el: StrictPanel;
1112

12-
public get element() { return this._elRef.current!; }
13-
public get rendered() { return this._elRef.current != null; }
13+
public get element() { return this._el?.nativeElement }
14+
public get rendered() { return this._el?.rendered; }
1415

15-
public constructor(el: StrictPanel | NonStrictPanel | HTMLDivElement) {
16-
this._elRef = el instanceof Element ? { current: el } : el.elRef;
16+
public constructor(el: StrictPanel) {
17+
this._el = el;
1718
}
1819

1920
public show() {
20-
if (this._elRef.current) {
21-
this._elRef.current.style.display = "";
22-
}
21+
this._el?.show();
2322
}
2423

2524
public hide() {
26-
if (this._elRef.current) {
27-
this._elRef.current.style.display = "none";
28-
}
25+
this._el?.hide();
2926
}
3027
}
3128

packages/react-flicking/src/react-flicking/ReactRenderer.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,15 +74,13 @@ class ReactRenderer extends ExternalRenderer {
7474
protected _collectPanels() {
7575
const flicking = getFlickingAttached(this._flicking);
7676
const reactFlicking = this._reactFlicking;
77-
const reactPanels = reactFlicking.reactPanels.map(panel => panel instanceof HTMLDivElement ? panel : panel.nativeElement);
77+
const reactPanels = reactFlicking.reactPanels;
7878

7979
this._panels = this._strategy.collectPanels(flicking, reactPanels);
8080
}
8181

82-
protected _createPanel(externalComponent: StrictPanel | NonStrictPanel | HTMLDivElement, options: PanelOptions) {
83-
const el = externalComponent instanceof HTMLDivElement ? externalComponent : externalComponent.nativeElement;
84-
85-
return this._strategy.createPanel(el, options);
82+
protected _createPanel(externalComponent: StrictPanel, options: PanelOptions) {
83+
return this._strategy.createPanel(externalComponent, options);
8684
}
8785
}
8886

0 commit comments

Comments
 (0)