react-native-simple-epub-reader 0.1.0 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -10,7 +10,7 @@ import type { ReaderContextProps } from './types';
10
10
  import { defaultTheme } from '../constants/theme';
11
11
  import type WebView from 'react-native-webview';
12
12
  import * as webViewInjectFunctions from '../helpers/webViewInjectFunctions';
13
- import type { ePubCfi, Flow, Location, Theme } from '../types';
13
+ import type { ePubCfi, Location, Theme } from '../types';
14
14
  import { useReaderState } from '../hooks/useReaderState';
15
15
  import { Actions } from '../types/state.types';
16
16
 
@@ -123,8 +123,11 @@ function ReaderProvider({ children }: { children: React.ReactNode }) {
123
123
  const getMeta = useCallback(() => state.meta, [state.meta]);
124
124
  const changeFontFamily = useCallback((fontFamily: string) => {
125
125
  book.current?.injectJavaScript(`
126
- rendition.themes.font('${fontFamily}');
127
- rendition.views().forEach(view => view.pane ? view.pane.render() : null); true;
126
+ if (typeof rendition !== 'undefined' && rendition) {
127
+ rendition.themes.font('${fontFamily}');
128
+ rendition.views().forEach(view => view.pane ? view.pane.render() : null);
129
+ }
130
+ true;
128
131
  `);
129
132
  dispatch({ type: Actions.CHANGE_FONT_FAMILY, payload: fontFamily });
130
133
  }, []);
@@ -133,23 +136,14 @@ function ReaderProvider({ children }: { children: React.ReactNode }) {
133
136
  book.current?.injectJavaScript(script);
134
137
  }, []);
135
138
 
136
- const changeFlow = useCallback((flow: Flow) => {
137
- webViewInjectFunctions.injectJavaScript(
138
- book,
139
- `rendition.flow(${JSON.stringify(flow)}); true`
140
- );
141
- dispatch({ type: Actions.SET_FLOW, payload: flow });
142
- }, []);
143
-
144
- const setFlow = useCallback((flow: Flow) => {
145
- dispatch({ type: Actions.SET_FLOW, payload: flow });
146
- }, []);
147
-
148
139
  const changeTheme = useCallback((theme: Theme) => {
149
140
  book.current?.injectJavaScript(`
150
- rendition.themes.register({ theme: ${JSON.stringify(theme)} });
151
- rendition.themes.select('theme');
152
- rendition.views().forEach(view => view.pane ? view.pane.render() : null); true;
141
+ if (typeof rendition !== 'undefined' && rendition) {
142
+ rendition.themes.register({ theme: ${JSON.stringify(theme)} });
143
+ rendition.themes.select('theme');
144
+ rendition.views().forEach(view => view.pane ? view.pane.render() : null);
145
+ }
146
+ true;
153
147
  `);
154
148
  dispatch({ type: Actions.CHANGE_THEME, payload: theme });
155
149
  }, []);
@@ -158,7 +152,9 @@ function ReaderProvider({ children }: { children: React.ReactNode }) {
158
152
  webViewInjectFunctions.injectJavaScript(
159
153
  book,
160
154
  `
161
- rendition.next();
155
+ if (typeof rendition !== 'undefined' && rendition) {
156
+ rendition.next();
157
+ }
162
158
  `
163
159
  );
164
160
  }, []);
@@ -167,19 +163,29 @@ function ReaderProvider({ children }: { children: React.ReactNode }) {
167
163
  webViewInjectFunctions.injectJavaScript(
168
164
  book,
169
165
  `
170
- rendition.prev();
166
+ if (typeof rendition !== 'undefined' && rendition) {
167
+ rendition.prev();
168
+ }
171
169
  `
172
170
  );
173
171
  }, []);
174
172
 
175
173
  const goToLocation = useCallback((targetCfi: ePubCfi) => {
176
- book.current?.injectJavaScript(`rendition.display('${targetCfi}'); true`);
174
+ book.current?.injectJavaScript(`
175
+ if (typeof rendition !== 'undefined' && rendition) {
176
+ rendition.display('${targetCfi}');
177
+ }
178
+ true;
179
+ `);
177
180
  }, []);
178
181
 
179
182
  const changeFontSize = useCallback((size: string) => {
180
183
  book.current?.injectJavaScript(`
181
- rendition.themes.fontSize('${size}');
182
- rendition.views().forEach(view => view.pane ? view.pane.render() : null); true;
184
+ if (typeof rendition !== 'undefined' && rendition) {
185
+ rendition.themes.fontSize('${size}');
186
+ rendition.views().forEach(view => view.pane ? view.pane.render() : null);
187
+ }
188
+ true;
183
189
  `);
184
190
  dispatch({ type: Actions.CHANGE_FONT_SIZE, payload: size });
185
191
  }, []);
@@ -203,8 +209,6 @@ function ReaderProvider({ children }: { children: React.ReactNode }) {
203
209
  setLocations,
204
210
  changeFontFamily,
205
211
  injectJavascript,
206
- changeFlow,
207
- setFlow,
208
212
  changeFontSize,
209
213
  theme: state.theme,
210
214
  flow: state.flow,
@@ -237,8 +241,6 @@ function ReaderProvider({ children }: { children: React.ReactNode }) {
237
241
  setLocations,
238
242
  changeFontFamily,
239
243
  injectJavascript,
240
- changeFlow,
241
- setFlow,
242
244
  changeFontSize,
243
245
  state.theme,
244
246
  state.flow,
@@ -68,6 +68,7 @@ export interface GestureHandlerProps {
68
68
  onSwipeRight?: () => void;
69
69
  onTap?: () => void;
70
70
  onPinch?: (e: GestureUpdateEvent<PinchGestureHandlerEventPayload>) => void;
71
+ onWebViewMessage?: (event: any) => void;
71
72
  }
72
73
 
73
74
  export type ReaderProps = {