architecture icon indicating copy to clipboard operation
architecture copied to clipboard

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

Open xNilsson opened this issue 6 years ago • 4 comments

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? :)

xNilsson avatar Jul 17 '19 15:07 xNilsson

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 (https://github.com/readium/r2-navigator-swift/pull/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)

mickael-menu-mantano avatar Jul 17 '19 16:07 mickael-menu-mantano

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!

xNilsson avatar Jul 24 '19 13:07 xNilsson

@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 avatar Oct 28 '19 09:10 mickael-menu-mantano

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?

mickael-menu avatar Apr 12 '21 12:04 mickael-menu