Skip to content

Comments

feat: unified async RiveFonts.addFallbackFont(source) API#152

Draft
mfazekas wants to merge 3 commits intomainfrom
refactor/unified-font-source-api
Draft

feat: unified async RiveFonts.addFallbackFont(source) API#152
mfazekas wants to merge 3 commits intomainfrom
refactor/unified-font-source-api

Conversation

@mfazekas
Copy link
Collaborator

@mfazekas mfazekas commented Feb 20, 2026

Summary

Replaces separate addFallbackFont/addFallbackFontFromResource/addFallbackFontFromURL with a single addFallbackFont(source: FontSource) that accepts require() IDs, URI objects, resource names, URLs, or raw ArrayBuffer bytes. All methods are now async. Renamed native HybridObject from Rive to RiveFontConfig.

await RiveFonts.addFallbackFont(require('./Kanit.ttf'))
await RiveFonts.addFallbackFont({ uri: 'https://…/font.ttf' })
await RiveFonts.addFallbackFont('kanit_regular.ttf')
await RiveFonts.addFallbackFont(arrayBuffer)

Test plan

Use the Font Fallback exerciser in the example app (exercisers/FontFallbackExample.tsx).

System font fallback (no custom fonts)

  1. Open Font Fallback exerciser
  2. Tap "Mount View (System Defaults Only)" without selecting any fonts
  3. Use text presets (Latin / CJK / Thai / Arabic / Mixed) — all should render via system fallback

URL-loaded font

  1. Unmount & Reset
  2. Select "Kanit (URL)" — should show checkmark after download
  3. Mount the view
  4. Test all text presets — Latin/Thai use Kanit, CJK/Arabic fall back to system

Bundled resource font

  1. Unmount & Reset
  2. Select "Kanit (Bundled)" — should load from native bundle resources
  3. Mount and test text presets

Multiple fonts

  1. Select both Kanit (URL) and Noto Serif Thai
  2. Mount and test Thai text — should pick the first matching fallback
  3. Test Mixed preset to verify multi-script rendering

Reset flow

  1. Tap "Unmount & Reset Fonts"
  2. Verify view unmounts, all selections clear
  3. Re-mount with different font configuration

Replace separate addFallbackFont/addFallbackFontFromResource/addFallbackFontFromURL
with a single addFallbackFont(source: FontSource) that accepts require() IDs,
URI objects, resource names, URLs, or raw ArrayBuffer bytes.

All methods are now async. Renamed native HybridObject from Rive to
RiveFontConfig to better reflect its purpose.
customFonts.add(fontBytes)
resetFontCache()
return@async
} catch (_: Exception) {}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [ktlint] standard:try-catch-finally-spacing reported by reviewdog 🐶
Expected a newline after '{'

customFonts.add(fontBytes)
resetFontCache()
return@async
} catch (_: Exception) {}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [ktlint] standard:try-catch-finally-spacing reported by reviewdog 🐶
Expected a newline before '}'

The font file existed in example/ios/ but wasn't referenced in the Xcode
project, so addFallbackFontFromResource couldn't find it at runtime.
Prevents "Cannot set value for property" error on initial render
when the riv file hasn't loaded yet.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant