refactor: improve file:// URL loading in Android (PR #329 improvements)#388
Closed
mfazekas wants to merge 2 commits intorive-app:mainfrom
Closed
refactor: improve file:// URL loading in Android (PR #329 improvements)#388mfazekas wants to merge 2 commits intorive-app:mainfrom
mfazekas wants to merge 2 commits intorive-app:mainfrom
Conversation
This updates the definition of `RiveReactNativeView.downloadUrlAsset` to load `file://` URLs via `java.io.File` Formerly, if a `file://` URL was loaded, that would lead to `com.android.volley.VolleyError: java.lang.ClassCastException: sun.net.www.protocol.file.FileURLConnection cannot be cast to java.net.HttpURLConnection` This only affects Android apps built in release mode, as debug mode is unaffected.
Critical fixes: - Add background threading to FileSystemLoader using coroutines with Dispatchers.IO - Ensure callbacks on main thread with withContext(Dispatchers.Main) - Reuse Volley RequestQueue singleton instead of creating new instance per request High-priority improvements: - Replace naive substring parsing with proper java.net.URI - Handle URL encoding and edge cases (file:/// vs file://) - Add specific error handling for FileNotFoundException with 404 status - Check file existence and permissions before reading - Provide clear error messages for permission denied This aligns the Android implementation with iOS patterns: - Explicit background threading (matching iOS DispatchQueue.global) - Main thread callbacks (matching iOS DispatchQueue.main.async) - Proper URL parsing (matching iOS URL.isFileURL) Addresses concerns from code review: - Thread safety: File I/O now happens on background thread - Resource management: Single RequestQueue shared across requests - Error handling: Granular exceptions with appropriate status codes - URL parsing: Robust handling of special characters and edge cases 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Simplifies PR #329 by removing the unnecessary factory pattern and using a straightforward iOS-style approach with proper
URI.schemechecking.Changes
Removed:
ResourceLoaderinterfaceVolleyHttpLoaderclassFileSystemLoaderclassResourceLoaderFactoryobjectAdded:
if/elseusingURI.schemeindownloadUrlAsset()loadFileUrlAsset()- Handles file:// URLs with background threadingloadRemoteUrlAsset()- Wraps existing Volley HTTP logicKey Improvements
java.net.URIand.schemeproperty instead ofstring.startsWith("file://")Dispatchers.IOwith callbacks on main threadCode Comparison
Before (factory pattern):
After (simple dispatch):
Result: 16 fewer lines, more maintainable, platform consistency with iOS.
Related
🤖 Generated with Claude Code
Co-Authored-By: Claude noreply@anthropic.com