Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Sets the pdf scale after page render rather than on resize #178

Merged
merged 2 commits into from
Jun 26, 2017
Merged

Fix: Sets the pdf scale after page render rather than on resize #178

merged 2 commits into from
Jun 26, 2017

Conversation

pramodsum
Copy link
Contributor

@pramodsum pramodsum commented Jun 20, 2017

  • Fixes issue where the first device orientation change would disable some
    event listeners due to the scale not being set
  • On document load, the scale is set to auto. So when the phone's orientation is changed the first time, resize() is called and the new scale is set to the previous scale (auto). Then when the orientation is changed again, it'll have a scale value to set.

@@ -1038,6 +1039,7 @@ const MOBILE_MAX_CANVAS_SIZE = 2949120; // ~3MP 1920x1536
if (pageNumber) {
// Page rendered event
this.emit('pagerender', pageNumber);
this.setScale(this.pdfViewer.currentScale);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which event listeners don't get triggered? Do some not fire if the scale is auto?

Copy link
Contributor Author

@pramodsum pramodsum Jun 20, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The click handlers for all point annotations. I'm still looking into why exactly the scale affects the listeners because the listeners aren't being removed at any point...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It sounds like this solution is more of a stopgap than an actual fix. Am I wrong in thinking this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So I spent a while messing with this and when the device orientation changes, this handler is called and so therefore so is renderAnnotations(). The listeners are never unbound and I even went and looked at some of the point annotation icons and they still have the listeners attached to each button.

My conclusion is basically that when the page is re-rendered, the page listeners are attached on top of the annotations. So rather than triggering any point annotation listeners, it registers as a general page click. I'll update this accordingly

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason setScale was fixing the issue was that it forced a re-rendering of annotations after the page was rendered.

@@ -1038,6 +1038,7 @@ const MOBILE_MAX_CANVAS_SIZE = 2949120; // ~3MP 1920x1536
if (pageNumber) {
// Page rendered event
this.emit('pagerender', pageNumber);
this.setScale(this.pdfViewer.currentScale); // Set scale to current numerical scale
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moving setScale() to after hte page is rendered ensures that the annotations listeners will be on top of the document listeners.

Copy link
Contributor

@jeremypress jeremypress Jun 22, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can annotations listen to the pagerender event and then re render based on that? Calling setScale again could introduce unnecessary work.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It shouldn't be called any extra times because I moved it from the resize() method to after the the page is actually done rendering

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pagerendered gets called when scrolling to pages, not always resize/zoom related

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah forgot it's also called on scroll. But would re-rendering the annotations on 'pagerender' be any different than setting the scale itself in the pageRenderedHandler()? That would still get triggered on scroll right?

Copy link
Contributor Author

@pramodsum pramodsum Jun 26, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have it calling renderAnnotationsOnPage() based on which pages have emitted the 'pagerender' event in the document viewer (in the second commit)

@pramodsum pramodsum changed the title Fix: Sets the initial pdf scale on page render Fix: Sets the initial pdf scale after page render rather than on resize Jun 22, 2017
@pramodsum pramodsum changed the title Fix: Sets the initial pdf scale after page render rather than on resize Fix: Sets the pdf scale after page render rather than on resize Jun 22, 2017
- Waits for the page to be fully rendered before updating the
  annotations scale. This ensures that the annotations listeners are on
  top of the document and it's associated listeners.
- Fixes issue where the first device orientation change would result in
  some listeners being hidden underneath the document listeners,
  resulting in point annotations not triggering on mobile.
@pramodsum
Copy link
Contributor Author

@jeremypress let me know if this looks good! :)

- renderAnnotationsOnPage is triggered on the 'pagerender' event based
  on which pages have been rendered
- If no specific page has been rendered (or is an image file), renders
  all annotations on the file
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants