epubjs-rn icon indicating copy to clipboard operation
epubjs-rn copied to clipboard

Remember last page

Open mqtik opened this issue 5 years ago • 5 comments

Hi everyone.

I have a situation, where I need to be able to read an epub, go back, and then when open again, go to the page I was reading. And if it's the first time I open a book, I need to start from the very beginning.

Instead, it doesn't remember the last page, and whether I open it for the first time or so on, it goes to the same page. Which it's not the beginning, nor the remembered page.

Any solutions/workaround for this?

Thanks

mqtik avatar Apr 16 '19 16:04 mqtik

hey dude its easy its my code onLocationChange={(visibleLocation)=> { if(this.state.cfi !== visibleLocation.end.cfi){ console.log(visibleLocation); this._setNewPage(visibleLocation); this.setState({visibleLocation,cfi:visibleLocation.end.cfi}); } }} set new page is a func that we save visibleLocation.end.cfi in Asyncstorage and when we back we set that async storage value into epub location

    AsyncStorage.getItem(this.props.navigation.getParam("data").source).then(val=>{
        let dt = JSON.parse(val);
        dt.page = info.end.cfi;
        console.log("will be saved : "  , info.end.cfi);
        AsyncStorage.setItem(this.props.navigation.getParam("data").source,JSON.stringify(dt));
    });

this.props.navigation.getParam("data").source (is name of my asyncstorage for tis book )

veeyka avatar Apr 21 '19 08:04 veeyka

So, it saves in onLocationChange, but what method should I use to call function in render to actually go to the page?

There's a function, onRelocation, that I still don't know what it does..

mqtik avatar Apr 22 '19 13:04 mqtik

Also have this problem, I manage to store the location in AsyncStorage and fetch it in onReady/onLocationsReady but then when book finish loading it still resets from start of ebook. Is there another method being triggered after onReady/onLocationsReady?

milesscherrer avatar May 20 '19 12:05 milesscherrer

@veeyka The solution is fine. But I cannot find out why the onLocationChange is not firing on each page change. It is firing on every 4th page.

ashokkumar88 avatar Oct 12 '19 06:10 ashokkumar88

You can use the location prop to pass the index of the page you want to move. But I'm facing a problem that, I can't navigate between pages after the first epub render.

If I bind the location to the state and modify to change the page, it doesn't work. :disappointed:

vitorverasm avatar Feb 12 '20 14:02 vitorverasm