https://ridi.github.io/react-viewer/demo/
npm install @ridi/react-viewer
Add @ridi/react-viewer
reducer into your reducers.
import { reducers as reader } from '@ridi/react-viewer';
import { combineReducers } from 'redux';
const appReducer = combineReducers({
...
reader,
...
});
Connect Connector
with redux store.
import { createStore } from 'redux';
import { Connector } from '@ridi/react-viewer';
const store = createStore( ... );
Connector.connect(store);
Reader
component provides all functionality of viewer and renders viewer body.
Put Reader
component into your component.
import React from 'react';
import Reader from '@ridi/react-viewer';
export default ViewerPage extends React.Component {
render() {
return <Reader />;
}
};
Reader
's properties:
onMount
(func): called after reader is mountedonUnmount
(func): called after reader is unmountedonTouched
(func): called when user touches the reader screenfooter
(node): markup for the footer areacontentFooter
(node): markup for the content footer areaignoreScroll
(bool): temporarily disable scrolling (onscroll
viewType)disablePageCalculation
(bool): temporarily disable page calculation (onpage
viewType)onScrolled
(func): called when scrolling event is triggered on screen (onscroll
viewType)
There are 2 ways to set contents in this reader.
First of all, dispatch setContentMetadata
for setting content metadata.
Then each content updated by one at a time.
import {
updateContent,
setContentMetadata,
ContentFormat,
BindingType,
} from '@ridi/react-viewer';
dispatch(setContentMetadata(ContentFormat.HTML, BindingType.LEFT, 50));
dispatch(updateContent(1, '<p>...</p>', false));
//... 1 ~ 50
dispatch(updateContent(50, '<p>...</p>', true));
Using this way, whole contents including metadata are set in a time.
Dispatch setContents(ByValue/byUri)
action with already loaded content or content's URIs.
import {
setContentsByValue,
setContentsByUri,
ContentFormat,
BindingType,
} from '@ridi/react-viewer';
dispatch(setContentsByUri(ContentFormat.HTML, BindingType.LEFT,[
'./uri1.json',
'./uri2.json',
...
]));
dispatch(setContentsByValue(ContentFormat.HTML, BindingType.LEFT,[
'<p>...</p>',
'<p>...</p>',
...
]));
contentFormat
: content format (HTML: 0, IMAGE: 1)bindingType
: binding type (LEFT: 0, RIGHT: 1)
$ npm install
$ npm run install:demo
$ npm run watch
Browse http://localhost:8000.