Skip to content

Commit

Permalink
Fix: Scroll to current Chapter (LNReader#1101)
Browse files Browse the repository at this point in the history
* cleanup + fixed scroll to current Chapter

* removed unused memoization

* removed unused import

* ChapterDrawer.tsx => index.tsx

* added correct types

* applied suggestion

* changed chapter.position to scrollIndex + 2

* refactored index.ts
  • Loading branch information
CD-Z committed Jun 14, 2024
1 parent 58a633e commit ea33690
Show file tree
Hide file tree
Showing 5 changed files with 318 additions and 266 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,5 @@ web-build/

.vscode/
src/sources/en/generators/
*.lockb
*.lockb
.tool-versions
1 change: 1 addition & 0 deletions src/database/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export interface ChapterInfo {
chapterNumber?: number;
page: string;
progress: number | null;
position?: number;
}

export interface DownloadedChapter extends ChapterInfo {
Expand Down
265 changes: 0 additions & 265 deletions src/screens/reader/components/ChapterDrawer.tsx

This file was deleted.

83 changes: 83 additions & 0 deletions src/screens/reader/components/ChapterDrawer/RenderListChapter.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import React from 'react';
import { View, Pressable, TextStyle } from 'react-native';
import { Text } from 'react-native-paper';
import color from 'color';
import { ChapterInfo, NovelInfo } from '@database/types';
import { ThemeColors } from '@theme/types';
import { StackNavigationProp } from '@react-navigation/stack';
import { RootStackParamList } from '@navigators/types';
import { StyleProp } from 'react-native';
import { ViewStyle } from 'react-native';

type Styles = {
chapterCtn: StyleProp<ViewStyle>;
drawerElementContainer: StyleProp<ViewStyle>;
chapterNameCtn: StyleProp<TextStyle>;
releaseDateCtn: StyleProp<TextStyle>;
};
type Navigation = StackNavigationProp<RootStackParamList, 'Chapter', undefined>;

type Props = {
item: ChapterInfo;
novelItem: NovelInfo;
styles: Styles;
theme: ThemeColors;
navigation: Navigation;
chapterId: number;
};
const changeChapter = (
item: ChapterInfo,
navigation: Navigation,
novelItem: NovelInfo,
) => {
navigation.replace('Chapter', {
novel: novelItem,
chapter: item,
});
};
const renderListChapter = ({
item,
novelItem,
styles,
theme,
navigation,
chapterId,
}: Props) => {
return (
<View
style={[
styles.drawerElementContainer,
item.id === chapterId && {
backgroundColor: color(theme.primary).alpha(0.12).string(),
},
]}
>
<Pressable
android_ripple={{ color: theme.rippleColor }}
onPress={() => changeChapter(item, navigation, novelItem)}
style={styles.chapterCtn}
>
<Text
numberOfLines={1}
style={[
styles.chapterNameCtn,
{ color: item.unread ? theme.onSurface : theme.outline },
]}
>
{item.name}
</Text>
{item.releaseTime ? (
<Text
style={[
styles.releaseDateCtn,
{ color: item.unread ? theme.onSurfaceVariant : theme.outline },
]}
>
{item.releaseTime}
</Text>
) : null}
</Pressable>
</View>
);
};
export default renderListChapter;
Loading

0 comments on commit ea33690

Please sign in to comment.