-
Notifications
You must be signed in to change notification settings - Fork 0
feat(mobile): 書櫃加入 epub metadata 擷取、格狀封面版面、排序,修正進度誤判讀畢 #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,102 @@ | ||
| import { Image, Pressable, Text, View } from 'react-native'; | ||
| import type { BookRecord } from '../lib/library'; | ||
| import { coverStyleFor, PROGRESS_FILL_COLOR, PROGRESS_TRACK_COLOR } from '../lib/coverStyles'; | ||
|
|
||
| interface Props { | ||
| record: BookRecord; | ||
| width: number; | ||
| onPress: () => void; | ||
| onDelete: () => void; | ||
| } | ||
|
|
||
| // 封面用固定像素寬高(而非 flex:1 + aspectRatio),因為卡片寬度依賴 FlatList numColumns | ||
| // 產生的欄寬去算,若 numColumns 沒套用成功(例如 Fast Refresh 沒有完整重新掛載), | ||
| // flex:1 會讓卡片撐滿整列寬度變得超大;改成呼叫端算好固定寬度傳進來,就不會受這個影響。 | ||
| const BookCard = ({ record, width, onPress, onDelete }: Props) => { | ||
| const pct = Math.round((record.progress ?? 0) * 100); | ||
| const style = coverStyleFor(record.id); | ||
| const coverHeight = Math.round(width * 1.5); | ||
|
|
||
| return ( | ||
| <View style={{ width }}> | ||
| <Pressable | ||
| onPress={onPress} | ||
| onLongPress={onDelete} | ||
| accessibilityRole="button" | ||
| accessibilityLabel={record.author ? `開啟《${record.title}》,作者 ${record.author}` : `開啟《${record.title}》`} | ||
| > | ||
| <View | ||
| style={{ | ||
| width, | ||
| height: coverHeight, | ||
| borderRadius: 6, | ||
| overflow: 'hidden', | ||
| backgroundColor: style.bg, | ||
| }} | ||
| > | ||
| {record.coverUri ? ( | ||
| <Image source={{ uri: record.coverUri }} style={{ width: '100%', height: '100%' }} resizeMode="cover" /> | ||
| ) : ( | ||
| <View style={{ flex: 1, justifyContent: 'space-between', padding: 14 }}> | ||
| <View> | ||
| <View style={{ width: 20, height: 2, backgroundColor: style.rule, marginBottom: 8 }} /> | ||
| <Text numberOfLines={4} style={{ color: style.ink, fontSize: 13, fontWeight: '600', lineHeight: 17 }}> | ||
| {record.title} | ||
| </Text> | ||
| </View> | ||
| {record.author ? ( | ||
| <Text | ||
| numberOfLines={1} | ||
| style={{ color: style.ink, fontSize: 9, letterSpacing: 1, textTransform: 'uppercase', opacity: 0.75 }} | ||
| > | ||
| {record.author} | ||
| </Text> | ||
| ) : null} | ||
| </View> | ||
| )} | ||
| </View> | ||
| </Pressable> | ||
|
|
||
| {/* 刪除按鈕:比照 renderer/src/components/Library/BookCard.tsx 的右上角圓形 ✕ 按鈕, | ||
| 取代原本只能長按刪除(手機上不夠明顯)的做法;長按仍保留當備援手勢。 */} | ||
| <Pressable | ||
| onPress={onDelete} | ||
| hitSlop={8} | ||
| style={{ | ||
| position: 'absolute', | ||
| top: 6, | ||
| right: 6, | ||
| width: 26, | ||
| height: 26, | ||
| borderRadius: 13, | ||
| backgroundColor: 'rgba(0,0,0,0.55)', | ||
| alignItems: 'center', | ||
| justifyContent: 'center', | ||
| }} | ||
| accessibilityRole="button" | ||
| accessibilityLabel="移除書籍" | ||
| > | ||
| <Text style={{ color: '#fff', fontSize: 12, lineHeight: 14 }}>✕</Text> | ||
| </Pressable> | ||
|
|
||
| <View style={{ marginTop: 8 }}> | ||
| <Text numberOfLines={2} style={{ fontSize: 13, fontWeight: '500', color: '#2a2420', lineHeight: 17 }}> | ||
| {record.title} | ||
| </Text> | ||
| {record.author ? ( | ||
| <Text numberOfLines={1} style={{ fontSize: 11, color: '#9a8f80', marginTop: 3 }}> | ||
| {record.author} | ||
| </Text> | ||
| ) : null} | ||
| <View style={{ flexDirection: 'row', alignItems: 'center', marginTop: 6, gap: 6 }}> | ||
| <View style={{ flex: 1, height: 4, borderRadius: 2, backgroundColor: PROGRESS_TRACK_COLOR, overflow: 'hidden' }}> | ||
| <View style={{ width: `${pct}%`, height: '100%', backgroundColor: PROGRESS_FILL_COLOR }} /> | ||
| </View> | ||
| <Text style={{ fontSize: 10, color: '#9a8f80' }}>{pct === 100 ? '讀畢' : `${pct}%`}</Text> | ||
| </View> | ||
| </View> | ||
| </View> | ||
| ); | ||
| }; | ||
|
|
||
| export default BookCard; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.