Skip to content

Commit

Permalink
Add support for module resolution on metro (#2240)
Browse files Browse the repository at this point in the history
- Resolve a module id from React Native on Web using the React Native Asset Registry.
- Keep the `Platform.web.tsx` in a way that we can still use `react-native-skia` without React Native on Web.
  • Loading branch information
wcandillon authored Feb 20, 2024
1 parent 54c85d9 commit 10204ef
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions package/src/Platform/Platform.web.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,14 @@ export const Platform: IPlatform = {
PixelRatio: typeof window !== "undefined" ? window.devicePixelRatio : 1, // window is not defined on node
resolveAsset: (source: DataModule) => {
if (isRNModule(source)) {
if (typeof source === "number" && typeof require === "function") {
const {
getAssetByID,
} = require("react-native/Libraries/Image/AssetRegistry");
const { httpServerLocation, name, type } = getAssetByID(source);
const uri = `${httpServerLocation}/${name}.${type}`;
return uri;
}
throw new Error(
"Asset source is a number - this is not supported on the web"
);
Expand Down

0 comments on commit 10204ef

Please sign in to comment.