-
Notifications
You must be signed in to change notification settings - Fork 36
Add Web Support (Take 2) #228
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
scottmas
wants to merge
8
commits into
wcandillon:main
Choose a base branch
from
scottmas:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
04f6e00
Add web support
scottmas 0ee0559
Merge branch 'main' into main
scottmas 05e7ba9
Better zero height/width behavior and warning
scottmas a9fc71d
Merge branch 'main' into main
scottmas 293fd99
Make web example not clutter
scottmas f24e5d7
Merge branch 'main' of github.com:scottmas/react-native-webgpu
scottmas fec88a3
More robust global type augmentation
scottmas 63a2c45
Merge branch 'main' into main
scottmas File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"trailingComma": "all" | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
const path = require("path"); | ||
const root = path.resolve(__dirname, "../.."); | ||
const r3fPath = path.resolve(root, "node_modules/@react-three/fiber"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this import is not used here right? |
||
const rnwPath = path.resolve(root, "node_modules/react-native-web"); | ||
const assetRegistryPath = path.resolve( | ||
root, | ||
"node_modules/react-native-web/dist/modules/AssetRegistry/index", | ||
); | ||
|
||
module.exports = function(metroConfig){ | ||
metroConfig.resolver.platforms = ["ios", "android", "web"]; | ||
const origResolveRequest = metroConfig.resolver.resolveRequest; | ||
metroConfig.resolver.resolveRequest = (contextRaw, moduleName, platform) => { | ||
const context = { | ||
...contextRaw, | ||
preferNativePlatform: false, | ||
}; | ||
|
||
if (moduleName === "react-native") { | ||
return { | ||
filePath: path.resolve(rnwPath, "dist/index.js"), | ||
type: "sourceFile", | ||
}; | ||
} | ||
|
||
// Let default config handle other modules | ||
return origResolveRequest(context, moduleName, platform); | ||
}; | ||
|
||
metroConfig.transformer.assetRegistryPath = assetRegistryPath; | ||
|
||
return metroConfig | ||
} | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8" /> | ||
<meta httpEquiv="X-UA-Compatible" content="IE=edge" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" /> | ||
<link rel="icon" href="/src/assets/react.png" type="image/png"> | ||
<script src="https://unpkg.com/canvaskit-wasm/bin/full/canvaskit.js"></script> | ||
|
||
<title>Example</title> | ||
<!-- The `react-native-web` recommended style reset: https://necolas.github.io/react-native-web/docs/setup/#root-element --> | ||
<style id="react-native-web-reset"> | ||
/* These styles make the body full-height */ | ||
html, | ||
body { | ||
height: 100%; | ||
} | ||
/* These styles disable body scrolling if you are using <ScrollView> */ | ||
body { | ||
overflow: hidden; | ||
} | ||
/* These styles make the root element full-height */ | ||
#root { | ||
display: flex; | ||
height: 100%; | ||
flex: 1; | ||
} | ||
</style> | ||
<body> | ||
<noscript> | ||
You need to enable JavaScript to run this app. | ||
</noscript> | ||
<div id="root"></div> | ||
<script src="index.bundle?platform=web&dev=true&hot=false&lazy=true&transform.engine=hermes&transform.routerRoot=app&unstable_transformProfile=hermes-stable" defer></script> | ||
</body> | ||
</html> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { AppRegistry } from "react-native"; | ||
import App from "./src/App"; | ||
import { name as appName } from "./app.json"; | ||
|
||
AppRegistry.registerComponent(appName, () => App); | ||
|
||
const rootTag = document.getElementById("root"); | ||
if (process.env.NODE_ENV !== "production") { | ||
if (!rootTag) { | ||
throw new Error( | ||
'Required HTML element with id "root" was not found in the document HTML.', | ||
); | ||
} | ||
} | ||
|
||
CanvasKitInit({ | ||
locateFile: (file) => `https://unpkg.com/canvaskit-wasm/bin/full/${file}`, | ||
}).then((CanvasKit) => { | ||
window.CanvasKit = global.CanvasKit = CanvasKit; | ||
AppRegistry.runApplication(appName, { rootTag }); | ||
}); |
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
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
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
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
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
Binary file not shown.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this change is not related right?