futurepress / epubjs-rn

EpubJS React Native Example
Other
267 stars 151 forks source link

Epub.js React Native Components

Uses EPUB.js to parse and render epubs on iOS and Android using React Native.

Getting Started

To use the components in your own app install via npm or yarn

npm install --save epubjs-rn

then link the required libraries with

react-native link react-native-static-server && react-native link react-native-webview && react-native link react-native-zip-archive && RNFB_ANDROID_PERMISSIONS=true react-native link rn-fetch-blob && react-native link @lightbase/react-native-orientation && react-native link @react-native-community/async-storage

then require the components you need

import { Epub } from 'epubjs-rn';

Then you can add the reader element in your code:

<Epub src={"https://s3.amazonaws.com/epubjs/books/moby-dick/OPS/package.opf"}
          flow={"paginated"} />

Using a local file server

To unzip compressed epubs locally and use http to stream them to epubjs, you will want to use the Streamer class to manage the files and start a StaticServer.

An example of this method is provided in the example app.

import { Epub, Streamer } from "epubjs-rn";
let streamer = new Streamer();

streamer.start("8899")
    .then((origin) => {
        console.log("Served from:", origin)
        return this.streamer.get("https://s3.amazonaws.com/epubjs/books/moby-dick.epub");
    })
    .then((src) => {
        console.log("Loading from:", src);
        return this.setState({src});
    });

Running the example app

Install with yarn. (Don't use NPM unless you flatten the packages after install)

cd EpubReader/
yarn global add react-native-cli
yarn install 

Then start the iOS or Android App

yarn start
react-native run-ios
react-native run-android

Other

EPUB is a registered trademark of the IDPF.