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

How to know if the navigator reached the end of the publication? #157

Open
cNille opened this issue Jul 17, 2019 · 4 comments
Open

How to know if the navigator reached the end of the publication? #157

cNille opened this issue Jul 17, 2019 · 4 comments

Comments

@cNille
Copy link

cNille commented Jul 17, 2019

Hi!

In our app we offer users to preview an ebook. We would like to know when the last page of the preview is reached so that we can show a popup offering the whole book.

Could you change notifyCurrentLocation in EPUBNavigatorViewController to allow us track when the user hits the last page? Because I guess that notifiedCurrentLocation == currentLocation in that case.

Either if the function is protected so that we could override it, or maybe add a function in the delegate protocol thats called within the else-statement.

What are your thoughts on how we solve our issue? :)

@mickael-menu-mantano
Copy link
Contributor

Hi,

Actually notifiedCurrentLocation == currentLocation doesn't mean that we reached the end of the book. This test is used only to make sure that we don't broadcast several times the current location if it didn't change.

There's currently no easy way to know that we are at the last page in the book, but it's an interesting use case, and we might need to add something either in the Navigator API or the Locator model.

A PR that is in review will make this a bit simpler (readium/r2-navigator-swift#65), by providing two ways to know if we're close to the end of the book:

  • Adding totalProgression to locator.locations. Unfortunately it will never reach 100%, because it will be the percent progression of the beginning of the last page.
  • Adding position to locator.locations and Publication.positionList. Using this index, you can determine if it's the last position in the list. However, a single position might encompass several "screen pages", so it's not guaranteed that it will be the real last page on the device.

Personally I don't think we should modify the Locator (which always target the beginning of the page and not the end), but we could add more information in the navigator API, for example some additional pagination context in navigator(_ navigator: Navigator, locationDidChange locator: Locator)

@cNille
Copy link
Author

cNille commented Jul 24, 2019

Hi!

Oh i see, so notifiedCurrentLocation is a no go then. totalProgression and positionList would be good help to determine when the last page is reached. Do you have any estimate on when it will be merged?

Adding more information in the navigator API would be optimal. Maybe we then could listen to if the user already is on the last page and tries to go to the next one. So that our popup allows the user to finish reading the whole preview first :) But until then the we'll probably go with positionList to solve our issue!

Thanks for the help!

@mickael-menu-mantano
Copy link
Contributor

@cNille Hi,

The positionList PR is merged into develop. 👍

For the rest, I'm keeping it in mind for the next evolution of the navigator API.

@mickael-menu-mantano mickael-menu-mantano self-assigned this Oct 28, 2019
@mickael-menu mickael-menu transferred this issue from readium/r2-navigator-swift Apr 12, 2021
@mickael-menu mickael-menu changed the title Last page reached How to know if the navigator reached the end of the publication? Apr 12, 2021
@mickael-menu
Copy link
Member

Moving this to architecture as it goes beyond the Swift project.

I'm considering maybe a simpler way to address this issue: since the navigator knows if it reached the end, it could modify the last Locator to set the totalProgression to 100% and the position to publication.positions.count.

This means that when reaching the last page, the locator would target the bottom of the page instead of the top like with the other locators. It's a bit incoherent so I'm on the fence, but it might be more practical/useful.

Any risk in this approach?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants