|
@@ -1,6 +1,8 @@
|
|
|
import { Component, createRef } from "react";
|
|
|
import PropTypes from "prop-types";
|
|
|
-import gsap from "gsap";
|
|
|
+import { gsap, ScrollTrigger } from "gsap/all";
|
|
|
+import styled from "@emotion/styled";
|
|
|
+import { css } from "@emotion/react";
|
|
|
|
|
|
export default class Viewer extends Component {
|
|
|
constructor() {
|
|
@@ -42,6 +44,7 @@ export default class Viewer extends Component {
|
|
|
enterTween: PropTypes.func,
|
|
|
exitTween: PropTypes.func,
|
|
|
canvasSize: PropTypes.array,
|
|
|
+ pause: PropTypes.object,
|
|
|
children: PropTypes.object,
|
|
|
};
|
|
|
|
|
@@ -58,6 +61,10 @@ export default class Viewer extends Component {
|
|
|
this.initializeTimeline();
|
|
|
this.setTimeline();
|
|
|
}
|
|
|
+ if (!this.enterTimeline && this.props.enterTween) {
|
|
|
+ this.initializeEnterTween();
|
|
|
+ }
|
|
|
+ ScrollTrigger.refresh();
|
|
|
}
|
|
|
|
|
|
loadImage(index) {
|
|
@@ -66,6 +73,12 @@ export default class Viewer extends Component {
|
|
|
img.retried = 0;
|
|
|
img.src = this.getSourcePath(index);
|
|
|
img.ogSrc = img.src;
|
|
|
+
|
|
|
+ if (this.props.pause && index + "" in this.props.pause) {
|
|
|
+ for (var r = this.props.pause[index]; r--; ) {
|
|
|
+ this.sequence.push(img);
|
|
|
+ }
|
|
|
+ }
|
|
|
this.sequence.push(img);
|
|
|
|
|
|
img.onload = () => {
|
|
@@ -166,14 +179,16 @@ export default class Viewer extends Component {
|
|
|
ease: "none",
|
|
|
onUpdate: () => {
|
|
|
this.frame = Math.floor(this.floatFrame);
|
|
|
- if (this.lastFrame === this.frame || this.loadedRenderPool.length) {
|
|
|
+ if (this.lastFrame === this.frame || this.loadedRenderPool.length > 0) {
|
|
|
this.renderImageToCanvas(this.frame);
|
|
|
}
|
|
|
},
|
|
|
});
|
|
|
}
|
|
|
|
|
|
- initializeEnterTween() {}
|
|
|
+ initializeEnterTween() {
|
|
|
+ console.log("initializeEnterTween");
|
|
|
+ }
|
|
|
|
|
|
poolNewFrames(index) {
|
|
|
console.log("poolNewFrames", index);
|
|
@@ -214,23 +229,46 @@ export default class Viewer extends Component {
|
|
|
render() {
|
|
|
// process props
|
|
|
this.fullFrameCount = this.props.frameCount;
|
|
|
+ if (this.props.pause) {
|
|
|
+ Object.keys(this.props.pause).forEach((index) => {
|
|
|
+ this.fullFrameCount += this.props.pause[index];
|
|
|
+ });
|
|
|
+ }
|
|
|
+ const Wrapper = styled.div({
|
|
|
+ position: "relative",
|
|
|
+ margin: "auto",
|
|
|
+ textAlign: "center",
|
|
|
+ pointerEvents: "none",
|
|
|
+ maxWidth: "100vw",
|
|
|
+ });
|
|
|
return (
|
|
|
- <div ref={this.containerRef}>
|
|
|
- <div ref={this.viewerRef} style={{ height: this.props.height }}>
|
|
|
+ <>
|
|
|
+ <Wrapper
|
|
|
+ ref={this.containerRef}
|
|
|
+ style={{ height: this.props.height || "500vh" }}
|
|
|
+ >
|
|
|
<div>{this.props.name}</div>
|
|
|
<div className="loading-wrap" ref={this.loadingWrap}></div>
|
|
|
- <div className="canvas-container" ref={this.canvasContainerRef}>
|
|
|
- <canvas
|
|
|
- className="sequence-canvas"
|
|
|
- ref={this.canvasRef}
|
|
|
- width={500}
|
|
|
- height={500}
|
|
|
- ></canvas>
|
|
|
+
|
|
|
+ <div ref={this.viewerRef}>
|
|
|
+ <div style={{ overflow: "hidden" }}>
|
|
|
+ <canvas
|
|
|
+ css={css`
|
|
|
+ width: auto;
|
|
|
+ margin-left: 50%;
|
|
|
+ transform: translateX(-50%);
|
|
|
+ height: calc(var(--vh, 1vh) * 100);
|
|
|
+ `}
|
|
|
+ ref={this.canvasRef}
|
|
|
+ width={this.width}
|
|
|
+ height={this.height}
|
|
|
+ ></canvas>
|
|
|
+ </div>
|
|
|
</div>
|
|
|
|
|
|
<>{this.props.children}</>
|
|
|
- </div>
|
|
|
- </div>
|
|
|
+ </Wrapper>
|
|
|
+ </>
|
|
|
);
|
|
|
}
|
|
|
}
|