Feat: NOVEL and CHAPTER reader context

This commit is contained in:
nyagami
2024-06-08 23:01:07 +07:00
parent 574f54a9bc
commit fca37868f1
3 changed files with 44 additions and 4 deletions
-1
View File
@@ -326,7 +326,6 @@ export const ChapterContent = ({
/>
);
}
console.log('re-render');
return (
<>
<WebViewReader
@@ -50,7 +50,7 @@ type WebViewReaderProps = {
const WebViewReader: FC<WebViewReaderProps> = props => {
const {
data,
data: { chapter, novel },
html,
nextChapter,
webViewRef,
@@ -66,7 +66,6 @@ const WebViewReader: FC<WebViewReaderProps> = props => {
const { RNDeviceInfo } = NativeModules;
const deviceInfoEmitter = new NativeEventEmitter(RNDeviceInfo);
const theme = useTheme();
const { novel, chapter } = data;
const readerSettings = useMemo(
() =>
getMMKVObject<ChapterReaderSettings>(CHAPTER_READER_SETTINGS) ||
@@ -133,6 +132,7 @@ const WebViewReader: FC<WebViewReaderProps> = props => {
showsVerticalScrollIndicator={false}
javaScriptEnabled={true}
onLayout={async () => onLayout()}
injectedJavaScriptObject={{ customValue: 'myCustomValue' }}
onMessage={ev => {
const event: WebViewPostEvent = JSON.parse(ev.nativeEvent.data);
switch (event.type) {
@@ -221,7 +221,7 @@ const WebViewReader: FC<WebViewReaderProps> = props => {
</style>
<link rel="stylesheet" href="${assetsUriPrefix}/css/index.css">
<style>${readerSettings.customCSS}</style>
<script async>
<script>
var initSettings = {
showScrollPercentage: ${showScrollPercentage},
swipeGestures: ${swipeGestures},
@@ -231,6 +231,10 @@ const WebViewReader: FC<WebViewReaderProps> = props => {
}
var batteryLevel = ${batteryLevel};
var autoSaveInterval = 2222;
var { NOVEL, CHAPTER } = ${JSON.stringify({
NOVEL: novel,
CHAPTER: chapter,
})}
</script>
</head>
<body>
@@ -45,6 +45,39 @@ const SettingsReaderScreen = () => {
const navigation = useNavigation();
const webViewRef = useRef<WebView>(null);
const { bottom } = useSafeAreaInsets();
const novel = {
'artist': null,
'author': 'Kinugasa Shougo',
'cover':
'file:///storage/emulated/0/Android/data/com.rajarsheechatterjee.LNReader/files/Novels/lightnovelcave/16/cover.png?1717862123181',
'genres': 'Drama,Slice of Life,Psychological,School Life,Shounen',
'id': 16,
'inLibrary': 1,
'isLocal': 0,
'name': 'Classroom of the Elite (LN)',
'path': 'novel/classroom-of-the-elite-16091321',
'pluginId': 'lightnovelcave',
'status': 'Ongoing',
'summary':
'Kōdo Ikusei Senior High School, a leading prestigious school with state-of-the-art facilities where nearly 100% of students go on to university or find employment. The students there have the freedom to wear any hairstyle and bring any personal effects they desire. Kōdo Ikusei is a paradise-like school, but the truth is that only the most superior of students receive favorable treatment.The protagonist Kiyotaka Ayanokōji is a student of D-class, which is where the school dumps its “inferior” students in order to ridicule them. For a certain reason, Kiyotaka was careless on his entrance examination, and was put in D-class. After meeting Suzune Horikita and Kikyō Kushida, two other students in his class, Kiyotaka’s situation begins to change.Show More',
'totalPages': 8,
};
const chapter = {
'bookmark': 0,
'chapterNumber': 2.1,
'id': 3722,
'isDownloaded': 1,
'name': 'Chapter V4C2.1 - A Vast Array of Thoughts Part 1',
'novelId': 16,
'page': '2',
'path': 'novel/classroom-of-the-elite-547/vol-4-chapter-2-1',
'position': 0,
'progress': 3,
'readTime': '2024-06-08 22:56:09',
'releaseTime': '14 tháng 9 năm 2021',
'unread': 1,
'updatedTime': null,
};
const [hidden, setHidden] = useState(true);
const layoutHeight = Dimensions.get('window').height;
const batteryLevel = useBatteryLevel();
@@ -180,6 +213,10 @@ const SettingsReaderScreen = () => {
}
var batteryLevel = ${batteryLevel};
var autoSaveInterval = 2222;
var { NOVEL, CHAPTER } = ${JSON.stringify({
NOVEL: novel,
CHAPTER: chapter,
})}
</script>
</head>
<body>