futurepress/epubjs-rn

Remember last page

Opened this issue · 5 comments

mqtik commented

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

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 )

mqtik commented

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..

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?

@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.

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. 😞