From 0e033667eef2abf06dfb949ef831b68f9dc51d2c Mon Sep 17 00:00:00 2001 From: Jacob Spizziri Date: Wed, 14 Dec 2022 15:10:09 -0500 Subject: [PATCH] feat(web): remove next and previous buttons in favor of a ref api --- example-web/src/App.tsx | 11 ++++-- example-web/src/components/ReaderButton.tsx | 29 ++++++++++++++++ example-web/src/components/index.ts | 1 + src/web/ReadiumView.tsx | 38 ++++++++++++++++----- src/web/hooks/useReaderRef.ts | 1 + 5 files changed, 70 insertions(+), 10 deletions(-) create mode 100644 example-web/src/components/ReaderButton.tsx diff --git a/example-web/src/App.tsx b/example-web/src/App.tsx index 1306930..865a043 100644 --- a/example-web/src/App.tsx +++ b/example-web/src/App.tsx @@ -1,4 +1,4 @@ -import React, { useState } from 'react'; +import React, { useRef, useState } from 'react'; import { View } from 'react-native'; import './App.css'; // @ts-ignore - FIXME: webpack not resolving types @@ -9,12 +9,14 @@ import type { Locator, Link } from 'react-native-readium'; import { Settings as ReaderSettings, TableOfContents, + ReaderButton, } from './components'; const DEFAULT_SETTINGS = new Settings(); DEFAULT_SETTINGS.appearance = Appearance.NIGHT; function App() { + const ref = useRef(); const [toc, setToc] = useState([]); const [location, setLocation] = useState(); const [settings, setSettings] = useState>(DEFAULT_SETTINGS); @@ -34,8 +36,11 @@ function App() { onSettingsChanged={(s) => setSettings(s)} /> - + + ref.current?.nextPage() } /> + + ref.current?.prevPage() } /> + ); } diff --git a/example-web/src/components/ReaderButton.tsx b/example-web/src/components/ReaderButton.tsx new file mode 100644 index 0000000..7ba95ed --- /dev/null +++ b/example-web/src/components/ReaderButton.tsx @@ -0,0 +1,29 @@ +import React from 'react'; +import { StyleSheet } from 'react-native'; +import { Button, Icon } from '@rneui/themed'; + +export interface ReaderButtonProps { + name: string; + onPress: () => void; +} + +export const ReaderButton: React.FC = ({ + name, + onPress, +}) => { + return ( + }
- {reader && }
); -}; +}); const styles = StyleSheet.create({ container: { @@ -55,7 +77,7 @@ const styles = StyleSheet.create({ display: 'flex', }, maximize: { - width: 'calc(100% - 100px)', + width: '100%', height: '100%', display: 'flex', }, diff --git a/src/web/hooks/useReaderRef.ts b/src/web/hooks/useReaderRef.ts index a72e873..293ab88 100644 --- a/src/web/hooks/useReaderRef.ts +++ b/src/web/hooks/useReaderRef.ts @@ -15,6 +15,7 @@ export const useReaderRef = ({ D2Reader.load({ url: new URL(file.url), lastReadingPosition: file.initialLocation, + userSettings: { verticalScroll: false }, api: { updateCurrentLocation: async (location: Locator) => { if (onLocationChange) onLocationChange(location);