-
-
Notifications
You must be signed in to change notification settings - Fork 51
/
App.tsx
219 lines (213 loc) · 5.91 KB
/
App.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
import * as React from 'react';
import { NavigationContainer, useNavigation } from '@react-navigation/native';
import { createNativeStackNavigator } from '@react-navigation/native-stack';
import {
ScrollView,
StyleSheet,
Text,
TouchableOpacity,
useColorScheme,
} from 'react-native';
import { MD3DarkTheme, MD3LightTheme, PaperProvider } from 'react-native-paper';
import {
SafeAreaProvider,
useSafeAreaInsets,
} from 'react-native-safe-area-context';
import {
Basic,
Formats,
CustomThemes,
InitialLocation,
Search,
OpenExternalLink,
Annotations,
Bookmarks,
FullExample,
TableOfContents,
JavascriptInjection,
Spreads,
ScrolledDoc,
ContinuousSpreads,
ContinuousScrolled,
WithSlider,
} from './examples';
const { Navigator, Screen } = createNativeStackNavigator();
const styles = StyleSheet.create({
container: {
justifyContent: 'flex-start',
alignItems: 'center',
},
button: {
padding: 8,
width: '90%',
borderBottomColor: '#c0c0c0',
borderBottomWidth: 2,
},
});
export const examples = [
{
title: 'Basic',
description: 'The minimum to work.',
route: 'Basic',
component: Basic,
},
{
title: 'Formats',
description:
'Loading a book of different formats. (opf, epub, base64 and internal)',
route: 'Formats',
component: Formats,
},
{
title: 'Custom Themes',
description: 'Loading a book with custom themes.',
route: 'CustomThemes',
component: CustomThemes,
},
{
title: 'Initial Location',
description: 'Open book in specific location.',
route: 'InitialLocation',
component: InitialLocation,
},
{
title: 'Search',
description: 'Search terms in the book.',
route: 'Search',
component: Search,
},
{
title: 'Open External Link',
description: 'Handle opening external links in epub',
route: 'OpenExternalLink',
component: OpenExternalLink,
},
{
title: 'Annotations',
description: 'Some use cases for text markup',
route: 'Annotations',
component: Annotations,
},
{
title: 'Bookmarks',
description: 'Using bookmarks in the book',
route: 'Bookmarks',
component: Bookmarks,
},
{
title: 'Table of Contents',
description: 'Ordered list of links into the content',
route: 'TableOfContents',
component: TableOfContents,
},
{
title: 'Javascript Injection',
description: 'Inject a script into the open ebook instance',
route: 'JavascriptInjection',
component: JavascriptInjection,
},
{
title: 'Spreads',
description:
'Display an ebook two pages at a time. Sections of the ebook are displayed separately so if a section has a single page or an odd number of pages it will display with a blank page on the right. Use Tablet to see this works.',
route: 'Spreads',
component: Spreads,
},
{
title: 'Scrolled Doc',
description:
'Displays each "section" or "chapter" of the ebook in its entirety as a single page of variable height that you can scroll up and down.',
route: 'ScrolledDoc',
component: ScrolledDoc,
},
{
title: 'Continuous Spreads',
description:
'The example is the same as Spreads above except that the entire document is rendered at once without breaks so if a section has one page, the next section is shown beginning on the right-hand-page rather than a blank page.',
route: 'ContinuousSpreads',
component: ContinuousSpreads,
},
{
title: 'Continuous Scrolled',
description:
'The example is the same as Scrolled Doc except the entire ebook is rendered in the browser at once so there are no navigation links above and below each chapter. This version may take longer to render and uses more memory since the whole ebook is loaded into memory. This version has no links to navigate or jump between chapters.',
route: 'ContinuousScrolled',
component: ContinuousScrolled,
},
{
title: 'With Slider',
description: 'Navigate between locations with slider',
route: 'WithSlider',
component: WithSlider,
},
{
title: 'Full Example',
description: 'A complete reader using library resources',
route: 'FullExample',
component: FullExample,
},
];
function Examples() {
const { navigate } = useNavigation();
const insets = useSafeAreaInsets();
return (
<ScrollView
contentContainerStyle={{
...styles.container,
paddingBottom: insets.bottom,
paddingLeft: insets.left,
paddingRight: insets.right,
}}
showsVerticalScrollIndicator={false}
>
{examples.map(({ title, description, route }) => (
<TouchableOpacity
style={styles.button}
key={route}
onPress={() => navigate(route as never)}
>
<Text>{title}</Text>
<Text>{description}</Text>
</TouchableOpacity>
))}
</ScrollView>
);
}
export default function App() {
const colorScheme = useColorScheme();
return (
<PaperProvider
theme={colorScheme === 'dark' ? MD3DarkTheme : MD3LightTheme}
>
<SafeAreaProvider>
<NavigationContainer>
<Navigator initialRouteName="Examples">
<Screen
name="Examples"
options={{ title: 'Examples' }}
component={Examples}
/>
{examples.map(({ title, route, component: Example }) => (
<Screen
key={route}
name={route}
options={{
title,
headerShown: ![
'Bookmarks',
'TableOfContents',
'JavascriptInjection',
'Search',
'CustomThemes',
'FullExample',
].includes(route),
}}
component={Example}
/>
))}
</Navigator>
</NavigationContainer>
</SafeAreaProvider>
</PaperProvider>
);
}