aboutsummaryrefslogtreecommitdiff
path: root/src/client/views/nodes/PDFBox.tsx
diff options
context:
space:
mode:
Diffstat (limited to 'src/client/views/nodes/PDFBox.tsx')
-rw-r--r--src/client/views/nodes/PDFBox.tsx23
1 files changed, 14 insertions, 9 deletions
diff --git a/src/client/views/nodes/PDFBox.tsx b/src/client/views/nodes/PDFBox.tsx
index a3c818c91..b9ccd79e4 100644
--- a/src/client/views/nodes/PDFBox.tsx
+++ b/src/client/views/nodes/PDFBox.tsx
@@ -30,20 +30,24 @@ export class PDFBox extends DocComponent<FieldViewProps, PdfDocument>(PdfDocumen
@observable private _alt = false;
@observable private _scrollY: number = 0;
+ private _reactionDisposer?: IReactionDisposer;
+ _targetDiv: any = undefined;
+
+ componentDidMount: () => void = () => {
+ if (this._reactionDisposer) this._reactionDisposer();
+ this._reactionDisposer = reaction(() => this.props.Document.scrollY, () =>
+ this._targetDiv && this._targetDiv.scrollTo({ top: NumCast(this.Document.scrollY), behavior: "smooth" })
+ );
+ }
loaded = (nw: number, nh: number) => {
if (this.props.Document) {
+ if (this.props.Document.nativeWidth && this.props.Document.nativeHeight) return;
let doc = this.props.Document.proto ? this.props.Document.proto : this.props.Document;
- let oldnw = NumCast(doc.nativeWidth);
+ let oldaspect = NumCast(doc.nativeHeight) / NumCast(doc.nativeWidth, 1);
doc.nativeWidth = nw;
- if (!doc.nativeHeight) {
- doc.nativeHeight = nh;
- }
- else {
- let oldnh = NumCast(doc.nativeHeight);
- let aspect = oldnh / oldnw;
- doc.nativeHeight = nw * aspect;
- }
+ if (doc.nativeHeight) doc.nativeHeight = nw * oldaspect;
+ else doc.nativeHeight = nh;
let ccv = this.props.ContainingCollectionView;
if (ccv) {
ccv.props.Document.pdfHeight = nh;
@@ -55,6 +59,7 @@ export class PDFBox extends DocComponent<FieldViewProps, PdfDocument>(PdfDocumen
@action
onScroll = (e: React.UIEvent<HTMLDivElement>) => {
if (e.currentTarget) {
+ this._targetDiv = e.currentTarget;
this._scrollY = e.currentTarget.scrollTop;
// e.currentTarget.scrollTo({ top: 1000, behavior: "smooth" });
let ccv = this.props.ContainingCollectionView;