Use documentation for epubjs 0.3 and the layout-guide.png included in the repo to document yourself :).
Uses EPUB.js to parse and render epubs on iOS and Android using React Native.
To use the components in your own app install via npm or yarn
yarn add @sbrighiu/epubjs-rn
or
npm install --save @sbrighiu/epubjs-rn
then require the default reader
import EpubReader, { blockTextSelectionThemesObject, blockTextSelectionName } from '@sbrighiu/epubjs-rn';
then you can add the reader element in your code:
<EpubReader url={"https://s3.amazonaws.com/epubjs/books/moby-dick/OPS/package.opf"}
themes={blockTextSelectionThemesObject}
theme={blockTextSelectionName} />
url
: .opf or .epub url; The component will handle downloading and uncompressing the epub or just showing the opf content. Changing it will re-initialize the component.backgroundColor
: background color (default: '#FEFEFE'),themes
: JSON object of themes names and css properties to be applied (same as before)theme
: Name of the theme to apply, such aslight
(same as before)onBookChange
: callback returning the book when loaded and ready (similar to onReady); for table of contents objects see book.navigation.toc. For navigating to a location from toc, pass location state to EpubReader and use setLocation(tocObject.href) to execute the navigation. Toc objects can be nested under subitems key.onExternalLinkPress
: callback with the external url tapped (http://, https://)onShouldStartLoadWithRequest
: callback for underlying webview onShouldStartLoadWithRequestonNavigationStateChange
: callback for underlying webview onNavigationStateChangeonInitStart
: when url is present and initialization startsonInitEnd
: when url is present and initialization ends successfullyonReady
: same as onBookChange.onError
: when url is present and initialization fails; returns error string.retryState
: Ability to retry initialization without changing url. Use an useState variable and assign an unique value to retry initialization.
or you can go the original route and require the components
you need
import { Epub } from '@sbrighiu/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"} />
src
: the url of your epub to renderflow
:paginated
:scrolled
- (default to false, which presents a scrolling view)location
: Can be an EPUBCFI, Chapter Url or Spine PositiononLocationChange
: Function called on every page change, reports current CFIonLocationsReady
: Function called once the locations has been generated. Returns the locations object.onViewAdded
: Function called once a view has been added to the screen.beforeViewRemoved
: Function called before a view will be removed from the screen.width
: width (int) of the Epub Renditionheight
: height (int) of the Epub RenditiononReady
: Function called once book has been opened. Returns the book objectthemes
: JSON object of themes names and css properties to be appliedtheme
: Name of the theme to apply, such aslight
fontSize
: CSS override for font size of theme, needs a css unitfont
: CSS override for font familystylesheet
: Link to css stylesheet containing themesscript
: Url for a javascript file to be injected into the viewminSpreadWidth
: cut off width for spreadsgap
: gap (int) between columns / pagesonPress
: Single taponDlbPress
: double tap on the screenonLongPress
: Press and holdonSelected
: When the browser selects text
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 "@sbrighiu/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});
});
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
If React Native version is <0.60, 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
EPUB is a registered trademark of the IDPF.