Merged
Conversation
Two web capture bugs:
1. JPG captures were silently producing PNG because toDataURL("image/jpg")
is not a valid MIME type — browsers require "image/jpeg". Now maps
"jpg" to "jpeg" before calling toDataURL.
2. Base64 result was blank in the example because raw base64 was used
directly as an Image source. Prepend the data URI prefix when
result is "base64" so it displays correctly.
Ref #586
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
This PR fixes two web-specific capture/preview issues in react-native-view-shot and its web example: ensuring JPG captures are encoded as real JPEGs (not silently PNG) and ensuring base64 capture results display correctly in the example app.
Changes:
- Map
format: "jpg"to the correct canvas MIME type (image/jpeg) before callingtoDataURLon web. - Prefix raw base64 capture output with a proper
data:image/...;base64,header inexample-webso<Image source={{uri}}>renders it. - Minor refactor to compute MIME type once before building the data URL / data URI.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
src/RNViewShot.web.ts |
Ensures correct MIME type (image/jpeg) is used for JPG on web canvas exports. |
example-web/src/screens/BasicTestScreen.tsx |
Fixes example preview for base64 results by converting raw base64 into a data URI. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
Owner
Author
|
tested manually. |
Closed
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
toDataURL("image/jpg")is not a valid MIME type, browsers require"image/jpeg". Now maps"jpg"→"jpeg"before callingtoDataURL.<Image source={{uri}}>, which doesn't work without thedata:image/...;base64,prefix.Ref #586
Test plan
npm run type-check/npm run lint:cipass🤖 Generated with Claude Code