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
15 changes: 6 additions & 9 deletions packages/core/src/highlights/highlight-queue-drain-host.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,12 @@ export default function HighlightQueueDrainHost() {
// scope from this same context afterwards. The forced retry uses the same
// accessor with `{ force: true }` so a silent mint failure cannot look like
// a freshly minted token.
const ensureFreshToken = useMemo(
() =>
getAccessToken === null
? null
: async () => {
await getAccessToken()
},
[getAccessToken],
)
const ensureFreshToken =
getAccessToken === null
? null
: async () => {
await getAccessToken()
}

const authRef = useRef<DrainAuth>({ userId, accessToken, ensureFreshToken, getAccessToken })
// Declared before the effects that read it: effects run in order, so the drain
Expand Down
22 changes: 9 additions & 13 deletions packages/ui/src/dom/bible-reader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import type {
} from '@youversion/platform-react-ui'
import { BibleReader } from '@youversion/platform-react-ui'
import type { ComponentType, ReactNode } from 'react'
import { useEffect, useMemo } from 'react'
import { useEffect } from 'react'
import type { StyleProp, ViewStyle } from 'react-native'
import { applySDKConfig, clearAuthResidue } from '../lib/dom-apply'

Expand Down Expand Up @@ -158,18 +158,14 @@ export default function BibleReaderDOM(props: BibleReaderDOMProps) {
// native action can only be async — so fire and forget. Catch rather than
// `void`: expo's `marshal` rejects when the consumer's handler throws, and an
// unattached rejection surfaces as an unhandled rejection in the DOM.
const handleVerseSelect = useMemo(
() =>
onVerseSelect
? (selection: BibleReaderVerseSelection) => {
// `Promise.resolve` so a sync handler (no bridge) can't throw on `.catch`.
Promise.resolve(onVerseSelect(selection)).catch((error: unknown) => {
console.error('[YouVersion SDK] onVerseSelect handler rejected:', error)
})
}
: undefined,
[onVerseSelect],
)
const handleVerseSelect = onVerseSelect
Comment thread
Dustin-Kelley marked this conversation as resolved.
? (selection: BibleReaderVerseSelection) => {
// `Promise.resolve` so a sync handler (no bridge) can't throw on `.catch`.
Promise.resolve(onVerseSelect(selection)).catch((error: unknown) => {
console.error('[YouVersion SDK] onVerseSelect handler rejected:', error)
})
}
: undefined

// fontFamily crosses the bridge as a quote-free token; resolve it back to the
// canonical CSS stack the Web SDK expects. See lib/reader-fonts.ts.
Expand Down
41 changes: 16 additions & 25 deletions packages/ui/src/native/bible-card.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useControllableState } from '@radix-ui/react-use-controllable-state'
import { useYouVersion, type Highlight } from '@youversion/platform-react-native-expo-core'
import type { BibleVersionPickerPressData, FootnoteData } from '@youversion/platform-react-ui'
import { useCallback, useState } from 'react'
import { useState } from 'react'
import { Platform } from 'react-native'
import { useShallow } from 'zustand/react/shallow'
import type { BibleCardProps as BibleCardDOMProps } from '../dom/bible-card'
Expand Down Expand Up @@ -188,32 +188,23 @@ export function BibleCard({
const [footnoteData, setFootnoteData] = useState<FootnoteData | null>(null)
const [isVersionPickerOpen, setIsVersionPickerOpen] = useState(false)

const handleVersionChange = useCallback(
async (newVersionId: number) => {
setVersionId(newVersionId)
},
[setVersionId],
)
const handleVersionChange = async (newVersionId: number) => {
setVersionId(newVersionId)
}

const handleVersionPickerPress = useCallback(
async (_data: BibleVersionPickerPressData) => {
if (Platform.OS === 'web') return
if (!showVersionPicker) return
if (consumerOnVersionPickerPress) {
await consumerOnVersionPickerPress(_data)
} else {
setIsVersionPickerOpen(true)
}
},
[consumerOnVersionPickerPress, setIsVersionPickerOpen, showVersionPicker],
)
const handleVersionPickerPress = async (_data: BibleVersionPickerPressData) => {
if (Platform.OS === 'web') return
if (!showVersionPicker) return
if (consumerOnVersionPickerPress) {
await consumerOnVersionPickerPress(_data)
} else {
setIsVersionPickerOpen(true)
}
}

const handleFootnotePress = useCallback(
async (data: FootnoteData) => {
setFootnoteData(data)
},
[setFootnoteData],
)
const handleFootnotePress = async (data: FootnoteData) => {
setFootnoteData(data)
}

const onFootnotePress =
Platform.OS !== 'web' ? (consumerOnFootnotePress ?? handleFootnotePress) : undefined
Expand Down
6 changes: 3 additions & 3 deletions packages/ui/src/native/bible-chapter-picker-sheet.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useYouVersion } from '@youversion/platform-react-native-expo-core'
import type { BibleChapterPickerSelectData } from '@youversion/platform-react-ui'
import { useCallback, useState } from 'react'
import { useState } from 'react'
import { useSdkTranslation } from '../i18n/use-sdk-translation'
import { Platform, StyleSheet, View, useWindowDimensions } from 'react-native'
import ChapterPickerContentDOM from '../dom/chapter-picker-content'
Expand Down Expand Up @@ -46,9 +46,9 @@ export function BibleChapterPickerSheet({
// rather than an effect — see https://react.dev/learn/you-might-not-need-an-effect.
const [resetKey, setResetKey] = useState(0)
const [dismissKeyboardNonce, setDismissKeyboardNonce] = useState(0)
const handleDismissKeyboardStart = useCallback(() => {
const handleDismissKeyboardStart = () => {
Comment thread
Dustin-Kelley marked this conversation as resolved.
setDismissKeyboardNonce((n) => n + 1)
}, [])
}

const handleClose = () => {
setResetKey((k) => k + 1)
Expand Down
22 changes: 9 additions & 13 deletions packages/ui/src/native/bible-reader-settings-sheet.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { useYouVersion } from '@youversion/platform-react-native-expo-core'
import { createBibleThemeSettingsContentHandlers } from '@youversion/platform-react-ui'
import { useMemo } from 'react'
import BibleReaderSettingsDOM from '../dom/bible-reader-settings'
import { withSheetDomDefaults } from '../lib/embed-dom-props'
import { encodeFontFamilyForDom } from '../lib/reader-fonts'
Expand All @@ -22,18 +21,15 @@ export function BibleReaderSettingsSheet({
const { setFontFamily, setFontSize, setLineSpacing, fontSize, fontFamily, lineSpacing } =
useReaderSettingsStore()

const { onFontIncreased, onFontDecreased, onFontSelected, onChangeLineSpacing } = useMemo(
() =>
createBibleThemeSettingsContentHandlers({
getFontSize: () => useReaderSettingsStore.getState().fontSize,
getFontFamily: () => useReaderSettingsStore.getState().fontFamily,
getLineSpacing: () => useReaderSettingsStore.getState().lineSpacing,
setFontSize,
setFontFamily,
setLineSpacing,
}),
[setFontSize, setFontFamily, setLineSpacing],
)
const { onFontIncreased, onFontDecreased, onFontSelected, onChangeLineSpacing } =
createBibleThemeSettingsContentHandlers({
getFontSize: () => useReaderSettingsStore.getState().fontSize,
getFontFamily: () => useReaderSettingsStore.getState().fontFamily,
getLineSpacing: () => useReaderSettingsStore.getState().lineSpacing,
setFontSize,
setFontFamily,
setLineSpacing,
})

return (
<NativeSheet isOpen={isSettingsSheetOpen} onClose={onClose} showAndroidLoader theme={theme}>
Expand Down
Loading