Skip to content

feat: setting fallback fonts#152

Open
mfazekas wants to merge 13 commits intomainfrom
refactor/unified-font-source-api
Open

feat: setting fallback fonts#152
mfazekas wants to merge 13 commits intomainfrom
refactor/unified-font-source-api

Conversation

@mfazekas
Copy link
Collaborator

@mfazekas mfazekas commented Feb 20, 2026

Adds RiveFonts — font fallback API for react-native. Two-phase design: load fonts into opaque handles, then configure a weight-based fallback map. System fonts are always appended as last resort.

// Load fonts (returns opaque handles)
const regular = await RiveFonts.loadFont({ uri: 'https://…/font.ttf' });
const bold = await RiveFonts.loadFont('kanit_regular.ttf');
const cjk = await RiveFonts.loadFont({ name: 'Noto Sans CJK' });

// Configure weight-based fallback map
await RiveFonts.setFallbackFonts({
  default: [regular, cjk],
  700: [bold, cjk],
});

// Reset to system defaults
await RiveFonts.clearFallbackFonts();

How to test

Open the Font Fallback exerciser in the example app (Exercisers > Font Fallback).

1. System defaults only — tap "Mount View" without selecting any fonts, use text presets (Latin / CJK / Thai / Arabic / Mixed) — all should render via system fallback.

iOS Android
image image

2. URL font — unmount & reset, select "Kanit (URL)", wait for download checkmark, mount — Latin/Thai render in Kanit, CJK/Arabic fall back to system.

iOS Android
image image

3. Bundled resource font — unmount & reset, select "Kanit (Bundled)", mount — same result from native bundle.

iOS Android
image image

4. System font by name — select "Thonburi (System)" on iOS or "serif (System)" on Android, mount with Thai text.

5. Multiple fonts — select both Kanit + Noto Serif Thai, mount, test Mixed preset for multi-script rendering.

iOS Android
image image

@mfazekas mfazekas force-pushed the refactor/unified-font-source-api branch from 16688d6 to a53e063 Compare February 24, 2026 06:19
@mfazekas mfazekas changed the title feat: unified async RiveFonts.addFallbackFont(source) API feat: RiveFonts.addFallbackFont(source) API Feb 24, 2026
@edgarrii
Copy link

@mfazekas thank you!

@mfazekas mfazekas force-pushed the refactor/unified-font-source-api branch from a53e063 to 64ab88b Compare February 24, 2026 14:39
@mfazekas mfazekas changed the title feat: RiveFonts.addFallbackFont(source) API feat: RiveFonts.addFallbackFonts(sources) API Feb 24, 2026
@mfazekas mfazekas force-pushed the refactor/unified-font-source-api branch from 64ab88b to cfe8e4e Compare February 24, 2026 14:42
@mfazekas mfazekas marked this pull request as ready for review February 24, 2026 14:56
@@ -1,6 +0,0 @@
import type { HybridObject } from 'react-native-nitro-modules';

export interface Rive
Copy link
Contributor

Choose a reason for hiding this comment

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

Ah this lasted long :)

I figured eventually this would get extended in some way

@mfazekas mfazekas force-pushed the refactor/unified-font-source-api branch from 88a361d to ca4786f Compare February 27, 2026 06:47
@mfazekas mfazekas changed the title feat: RiveFonts.addFallbackFonts(sources) API refactor: two-phase font loading with weight-based fallback map Feb 27, 2026
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.
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.
…s API

Adds `{ name: string }` to FontSource for system fonts (e.g. `{ name: 'Thonburi' }` on iOS,
`{ name: 'serif' }` on Android). Renames `addFallbackFont` to `addFallbackFonts` accepting
an array to make font ordering explicit and avoid sequential awaits.
Separate font loading from configuration — loadFont() returns opaque
FallbackFont handles, setFallbackFonts() accepts a weight-keyed map.
System fonts always appended as last resort.
@mfazekas mfazekas force-pushed the refactor/unified-font-source-api branch from 42eb65e to 7ac409b Compare February 27, 2026 09:32
@mfazekas mfazekas changed the title refactor: two-phase font loading with weight-based fallback map feat: setting fallback fonts Feb 27, 2026
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.

4 participants