Commit 09e0fae
fix: iOS production builds fail to load bundled .riv assets (#12)
* fix: iOS production asset loading
Fixes production build issue where iOS bundled assets fail to load.
**Problem:**
On iOS, `resolveAssetSource()` returns file:// URLs for bundled
assets: `file:///path/to/app/assets/rive/rewards_source.riv`
The previous implementation tried to extract the filename and load
it as a bundle resource, which only worked in debug builds. In
production, assets are packaged as actual files in the app bundle,
not as named resources accessible via `Bundle.main.path(forResource:)`.
**Previous approach (broken in production):**
```typescript
// Extract "rewards_source" from file URL
const match = assetURI.match(/file:\/\/(.*\/)+(.*)\.riv/);
return RiveFileFactory.fromResource(match[2], loadCdn);
// ❌ Failed: "Could not find Rive file: rewards_source.riv"
```
**New approach (works in debug and production):**
```typescript
// Load directly from file:// URL
return RiveFileFactory.fromFileURL(assetURI, loadCdn);
// ✅ Reads file directly from disk
```
**Implementation:**
- Added `fromFileURL` to `RiveFile.nitro.ts` spec
- Implemented `fromFileURL` in iOS (`HybridRiveFileFactory.swift`)
- Validates file:// URL scheme
- Loads data directly from file path using `Data(contentsOf:)`
- Runs on background thread
- Implemented `fromFileURL` in Android (`HybridRiveFileFactory.kt`)
- Matches iOS validation behavior
- Converts URI to path using `java.net.URI`
- Loads on `Dispatchers.IO` background thread
- Updated `fromSource()` to use `fromFileURL()` for file:// URLs
- Regenerated Nitrogen boilerplate
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
* Update src/core/RiveFile.ts
Co-authored-by: Gordon <pggordonhayes@gmail.com>
---------
Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: Gordon <pggordonhayes@gmail.com>1 parent 70c06a6 commit 09e0fae
File tree
12 files changed
+135
-5
lines changed- android/src/main/java/com/margelo/nitro/rive
- ios
- nitrogen/generated
- android
- c++
- kotlin/com/margelo/nitro/rive
- ios
- c++
- swift
- src
- core
- specs
12 files changed
+135
-5
lines changedLines changed: 27 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| 12 | + | |
| 13 | + | |
12 | 14 | | |
13 | 15 | | |
14 | 16 | | |
| |||
33 | 35 | | |
34 | 36 | | |
35 | 37 | | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
36 | 63 | | |
37 | 64 | | |
38 | 65 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
38 | 38 | | |
39 | 39 | | |
40 | 40 | | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
41 | 80 | | |
42 | 81 | | |
43 | 82 | | |
| |||
Lines changed: 16 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 22 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
0 commit comments