Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

react-native-readium

5-stones295MIT3.0.1TypeScript support: included

A react-native wrapper for https://readium.org/

react-native, ios, android, readium, ebook, epub, ereader, e-reader, read

readme

react-native-readium

NPM version Commitizen friendly PRs welcome! This project is released under the MIT license


Have A Bug/Feature You Care About?

We :heart: open source. We work on the things that are important to us when we're able to work on them. Have an issue you care about?


Overview

A react-native wrapper for https://readium.org/. At a high level this package allows you to do things like:

  • Render an ebook view.
  • Register for location changes (as the user pages through the book).
  • Register for the Table of Contents (so that you can display things like chapters in your app)
  • Control settings of the Reader. Things like:
    • Dark Mode, Light Mode, Sepia Mode
    • Font Size
    • Page Margins
    • More (see the Settings documentation in the API section)
  • Etc. (read on for more details. :book:)

Table of Contents

Dark Mode Light Mode
Dark Mode Light Mode

Installation

Prerequisites

  1. iOS: Requires an iOS target >= 13.0 (see the iOS section for more details).
  2. Android: Requires compileSdkVersion >= 31 (see the Android section for more details).

:warning: This library does not current support newArch. Please disable newArch if you intend to use it. PR's welcome.

Install Module

NPM

npm install react-native-readium

Yarn

yarn add react-native-readium

iOS

Due to the current state of the Readium swift libraries you need to manually update your Podfile (see more on that here).

# ./ios/Podfile
...
platform :ios, '13.0'

...

target 'ExampleApp' do
  config = use_native_modules!
  ...
  pod 'GCDWebServer', podspec: 'https://raw.githubusercontent.com/readium/GCDWebServer/3.7.5/GCDWebServer.podspec', modular_headers: true
  pod 'R2Navigator', podspec: 'https://raw.githubusercontent.com/readium/swift-toolkit/2.6.0/Support/CocoaPods/ReadiumNavigator.podspec'
  pod 'R2Shared', podspec: 'https://raw.githubusercontent.com/readium/swift-toolkit/2.6.0/Support/CocoaPods/ReadiumShared.podspec'
  pod 'R2Streamer', podspec: 'https://raw.githubusercontent.com/readium/swift-toolkit/2.6.0/Support/CocoaPods/ReadiumStreamer.podspec'
  pod 'ReadiumInternal', podspec: 'https://raw.githubusercontent.com/readium/swift-toolkit/2.6.0/Support/CocoaPods/ReadiumInternal.podspec'
  pod 'Minizip', modular_headers: true
  ...
end

Finally, install the pods:

pod install

Android

If you're not using compileSdkVersion >= 31 you'll need to update that:

// android/build.gradle
...
buildscript {
    ...
    ext {
        ...
        compileSdkVersion = 31
...

Usage

import React, { useState } from 'react';
import { ReadiumView } from 'react-native-readium';
import type { File } from 'react-native-readium';

const MyComponent: React.FC = () => {
  const [file] = useState<File>({
    url: SOME_LOCAL_FILE_URL,
  });

  return (
    <ReadiumView
      file={file}
    />
  );
}

Take a look at the Example App for a more complex usage example.

Supported Formats & DRM

Format Support

Format Support Notes
Epub 2 :white_check_mark:
Epub 3 :white_check_mark:
PDF :x: On the roadmap, feel free to submit a PR or ask for direction.
CBZ :x: On the roadmap, feel free to submit a PR or ask for direction.

Missing a format you need? Reach out and see if it can be added to the roadmap.

DRM Support

DRM is not supported at this time. However, there is a clear path to support it via LCP and the intention is to eventually implement it.

API

View Props

Name Type Optional Description
file File :x: A file object containing the path to the eBook file on disk.
location Locator | Link :white_check_mark: A locator prop that allows you to externally control the location of the reader (e.g. Chapters or Bookmarks).

:warning: If you want to set the location of an ebook on initial load, you should use the File.initialLocation property (look at the file prop). See more here
settings Partial<Settings> :white_check_mark: An object that allows you to control various aspects of the reader's UI (epub only)
style ViewStyle :white_check_mark: A traditional style object.
onLocationChange (locator: Locator) => void :white_check_mark: A callback that fires whenever the location is changed (e.g. the user transitions to a new page)
onTableOfContents (toc: Link[] | null) => void :white_check_mark: A callback that fires once the file is parsed and emits the table of contents embedded in the file. Returns null or an empty [] if no TOC exists. See the Link interface for more info.

:warning: Web vs Native File URLs

Please note that on web the File.url should be a web accessible URL path to the manifest.json of the unpacked epub. In native contexts it needs to be a local filepath to the epub file itself on disk. If you're not sure how to serve epub books take a look at this example which is based on the dita-streamer-js project (which is built on all the readium r2-*-js libraries)

Contributing

See the contributing guide to learn how to contribute to the repository and the development workflow.

Release

The standard release command for this project is:

yarn version

This command will:

  1. Generate/update the Changelog
  2. Bump the package version
  3. Tag & pushing the commit

e.g.

yarn version --new-version 1.2.17
yarn version --patch // 1.2.17 -> 1.2.18

If you'd like to sponsor a specific feature, fix, or the library in general, please reach out on an issue and we'll have a conversation!

License

MIT

changelog

3.0.1 (2025-03-05)

Bug Fixes

  • android: fix android build errors in newer versions of react-native (487febb)

3.0.0 (2025-02-11)

Bug Fixes

  • android: remove tap toggles ui visibility (81ca01a)

BREAKING CHANGES

  • android: Tapping will no longer toggle the system ui visibility.

2.0.2 (2024-10-08)

Bug Fixes

  • web: Handle location not defined in reading order (080b4a9)

2.0.1 (2024-10-03)

Bug Fixes

  • web: estimate the totalProgression if it is not provided (3d849dc)

2.0.0 (2024-09-10)

Bug Fixes

  • web: update reader when file url changes (21eda29)

2.0.0-rc.2 (2024-07-29)

Bug Fixes

  • android: don't set the brightness of the activity. instead rely on device/app settings (8af916b)
  • readiumview: fix an issue when no forwardRef is passed on Android (bbc1967)
  • ReadiumView: fix react warning regarding forwardRefs (45792e6)

2.0.0-rc.0 (2024-07-26)

Features

1.2.1 (2023-05-10)

Bug Fixes

  • web: restructure reader imports in order to fix SSR (37a2e6a)

1.2.0 (2022-12-14)

Features

  • web: remove next and previous buttons in favor of a ref api (0e03366)

1.1.0 (2022-12-10)

Features

  • web: add basic web implementation and example (d55a457)

1.0.4 (2022-12-06)

Bug Fixes

  • android: fix an issue resulting in initial android settings not being applied correctly (9f48874)

1.0.3 (2022-12-05)

Bug Fixes

  • android, ios: allow location and initialLocation to be either Link or Locator objects (ebc1030)

1.0.2 (2022-12-01)

Bug Fixes

  • android: fix android release builds by adding networking security config (f9b0ff8)

1.0.1 (2022-12-01)

Bug Fixes

  • android: update readium dependencies to deal with removed nanohttpd dependency (764f6eb)

1.0.0 (2022-08-22)

1.0.0-alpha.10 (2022-04-05)

Bug Fixes

  • android, ios: fix an issue with background color not staying in sync with appearance setting (fca2f8e)

1.0.0-alpha.9 (2022-04-01)

Bug Fixes

  • locator: update the Locator interface to represent the minimum data required (61c8be1)

Features

  • android, ios, example: add the ability to register to receive the table of contents (94ef6ae)

1.0.0-alpha.8 (2022-03-31)

Bug Fixes

  • android: fix an issue with android crashing due to a "no view found for id" exception (5440662)

1.0.0-alpha.7 (2022-03-31)

Bug Fixes

  • android: fix a race-condition with the settings prop causing crashes (11ebde3)

1.0.0-alpha.6 (2022-03-29)

Features

  • android: strip the 'file://' prefix from the path if it's passed (1171f1e)

1.0.0-alpha.5 (2022-03-28)

Bug Fixes

  • android: remove unused exoplayer deps to prevent conflicts with other projects (96086b4)

1.0.0-alpha.4 (2022-03-24)

Bug Fixes

  • ios: fix an issue causing crash when used in conjunction with react-native-screens (d250bf8)

1.0.0-alpha.3 (2022-03-24)

Bug Fixes

  • ios: add ios.deployment_target of 13.0 (ca1b199)

1.0.0-alpha.2 (2022-03-24)

Bug Fixes

  • podspec: specify swift version in podspec (cc7d7cd)

Features

  • ios, android: remove unused dependencies and code (1d35cdd)

1.0.0-alpha.1 (2022-03-23)

Bug Fixes

  • ios: fix view sizing on iOS (5e6e451)

Features

  • android: implement a basic ebook reader view for android (63e3d70)
  • example: react-native upgrade (74997a2)

1.0.0-alpha.0 (2022-03-11)

Features

  • src, ios: Basic functional implementation of epub reader for iOS (47d18e2)