Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/ype-6539-dimmed-chapter-highlights.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@youversion/platform-react-native-expo-ui': patch
---

Keep highlight fills on the dimmed outgoing passage while the next chapter or reference loads (YPE-6539).
90 changes: 90 additions & 0 deletions packages/ui/src/native/__tests__/bible-reader-native.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -858,6 +858,96 @@ describe('BibleReaderNative', () => {
})
})

describe('dimmed chapter highlights', () => {
function layoutParagraph(sentence: string): void {
const paragraph = screen.UNSAFE_getAllByType(Text).find((node) => node.props.onTextLayout)
if (paragraph === undefined) {
throw new Error('missing paragraph layout')
}
fireEvent(paragraph, 'textLayout', {
nativeEvent: {
lines: [
{
text: sentence,
x: 0,
y: 0,
width: 240,
height: 32,
ascender: 24,
descender: -6,
capHeight: 18,
xHeight: 12,
},
],
},
})
}

function hasHighlightFill(color: string): boolean {
return screen.UNSAFE_getAllByType(Text).some((node) => {
return StyleSheet.flatten(node.props.style)?.backgroundColor === color
})
}

it('keeps highlight fills on the dimmed outgoing chapter while the next chapter loads', async () => {
const chapter1 = fetchChapters({ '1': { status: 200, sentence: 'In the beginning' } })
let resolveChapter2!: (response: {
status: number
body: string
contentType: string
}) => void
const chapter2Pending = new Promise<{ status: number; body: string; contentType: string }>(
(resolve) => {
resolveChapter2 = resolve
},
)

const reader = mount({
fetchBibleContent: (request) =>
request.path.includes('/passages/JHN.2') ? chapter2Pending : chapter1(request),
highlights: [{ version_id: VERSION_ID, passage_id: 'JHN.1.1', color: 'fffe00' }],
})

await screen.findByText('In the beginning')
layoutParagraph('In the beginning')
await waitFor(() => expect(hasHighlightFill('#fffe00')).toBe(true))

reader.update({
chapter: '2',
highlights: [{ version_id: VERSION_ID, passage_id: 'JHN.2.1', color: '5dff79' }],
})

expect(screen.getByText('In the beginning')).toBeTruthy()
expect(hasHighlightFill('#fffe00')).toBe(true)
expect(hasHighlightFill('#5dff79')).toBe(false)

resolveChapter2({
status: 200,
body: chapterBody('The earth was'),
contentType: 'application/json',
})

await screen.findByText('The earth was')
layoutParagraph('The earth was')
await waitFor(() => expect(hasHighlightFill('#5dff79')).toBe(true))
expect(hasHighlightFill('#fffe00')).toBe(false)
})

it('clears highlight fills when highlights are removed on the current chapter', async () => {
const reader = mount({
highlights: [{ version_id: VERSION_ID, passage_id: 'JHN.1.1', color: 'fffe00' }],
})

await screen.findByText('In the beginning')
layoutParagraph('In the beginning')
await waitFor(() => expect(hasHighlightFill('#fffe00')).toBe(true))

reader.update({ highlights: [] })

await waitFor(() => expect(hasHighlightFill('#fffe00')).toBe(false))
})
})

it('shows scripture when the version language is on the provider list', async () => {
const restore = stubVersionNames({ [VERSION_ID]: 'BSB' }, { [VERSION_ID]: 'en' })
try {
Expand Down
46 changes: 46 additions & 0 deletions packages/ui/src/native/__tests__/bible-text-view.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,52 @@ describe('BibleTextView', () => {
})
})

it('keeps highlight fills on the dimmed outgoing passage while the next reference loads', async () => {
useHighlightsMock.mockImplementation((options: UseHighlightsOptions) => ({
...emptyHighlights(options),
highlights:
options.enabled !== false && options.book === 'JHN' && options.chapter === '3'
? [{ version_id: 3034, passage_id: 'JHN.3.16', color: 'fffe00' }]
: [],
}))
let resolveNext!: (response: Response) => void
const pending = new Promise<Response>((resolve) => {
resolveNext = resolve
})
installFetch((requested) =>
requested === 'JHN.3.16'
? jsonPassage(passageHtml(verseBlock(16, JOHN)), 'John 3:16')
: pending,
)
const view = render(<BibleTextView reference="JHN.3.16" versionId={3034} />, {
wrapper: highlightWrapper(),
})

await screen.findByText(JOHN)
paintHighlight(JOHN)
await waitFor(() => {
const painted = screen.UNSAFE_getAllByType(Text).some((node) => {
return StyleSheet.flatten(node.props.style)?.backgroundColor === '#fffe00'
})
expect(painted).toBe(true)
})

view.rerender(<BibleTextView reference="JHN.4.1" versionId={3034} />)

expect(screen.getByText(JOHN)).toBeTruthy()
const stillPainted = screen.UNSAFE_getAllByType(Text).some((node) => {
return StyleSheet.flatten(node.props.style)?.backgroundColor === '#fffe00'
})
expect(stillPainted).toBe(true)

resolveNext(jsonPassage(passageHtml(verseBlock(1, 'Now when Jesus learned')), 'John 4:1'))
await screen.findByText('Now when Jesus learned')
const oldPaintRemains = screen.UNSAFE_getAllByType(Text).some((node) => {
return StyleSheet.flatten(node.props.style)?.backgroundColor === '#fffe00'
})
expect(oldPaintRemains).toBe(false)
})

it('draws dark ink when theme is dark inside a light provider', async () => {
serveOnly('JHN.3.16', passageHtml(verseBlock(16, JOHN)), 'John 3:16')
render(<BibleTextView reference="JHN.3.16" versionId={3034} theme="dark" />, {
Expand Down
1 change: 1 addition & 0 deletions packages/ui/src/native/bible-reader-native.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ export function BibleReaderNative(props: BibleReaderNativeProps): ReactNode {
direction: versionDirection,
ink,
background,
isCurrent,
})

// ---- Selection ----
Expand Down
13 changes: 7 additions & 6 deletions packages/ui/src/native/bible-text-view-native.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,18 +96,23 @@ export function BibleTextViewNative({
? { content: hostHtml.content, reference: hostHtml.reference }
: null
const load = usePassage(fetchBibleContent, versionId, address, supplied)
// Supplied mode never paints a retained fetch: the host owns passage, loading, and error.
const passage = suppliedMode && (hostHtml === null || address === null) ? null : load.passage
const currentKey = address === null ? null : passageKey(versionId, address)
const isCurrent = passage !== null && currentKey !== null && passage.key === currentKey
// Intros load as passages but have no numeric chapter for paint.
const highlights = useHighlightPaint(highlightScopeFor(reference, versionId))
const multiple = resolvedLineMultiple(lineHeight)
// By the rendered passage's version: dimmed old text keeps its direction while the next loads.
const versionDirection = load.passage ? versionDirections?.get(load.passage.versionId) : undefined
const versionDirection = passage ? versionDirections?.get(passage.versionId) : undefined
const { look, paint } = usePassageStyle({
passage: load.passage,
passage,
highlights,
fontSize,
lineMultiple: multiple,
fontFamily,
direction: scriptureDirection ?? versionDirection,
isCurrent,
})
const selected = useMemo(() => new Set(selectedVerses ?? []), [selectedVerses])
const drawNotes = renderNotes && onFootnotePress !== undefined
Expand Down Expand Up @@ -142,11 +147,7 @@ export function BibleTextViewNative({
Promise.resolve(now.onFootnotePress(footnoteFor(now.passage, verse, html))).catch(console.error)
}, [])

// Supplied mode never paints a retained fetch: the host owns passage, loading, and error.
const passage = suppliedMode && (hostHtml === null || address === null) ? null : load.passage
const hostLoading = suppliedMode && (passageState?.loading ?? false)
const currentKey = address === null ? null : passageKey(versionId, address)
const isCurrent = passage !== null && currentKey !== null && passage.key === currentKey
let message: string | null = null
let onRetry: (() => void) | null = null
if (suppliedMode) {
Expand Down
Loading