-
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
base: main
Are you sure you want to change the base?
Conversation
Note, I added a guard for zero height or width on the underlying canvas since it causes obscure crashes on iOS. One thing I've thought about adding is "hiding" the web only changes a bit better that were added to |
is this "all" it takes to get the Web version working? :) it looks small enough :) |
I did go through and compartmentalize the web specific changes! This should make it a bit easier to grok the metro config updates that are required for web compatibility - it's surprisingly little, I thought it would be far more involved. I think this way should be best since the native and web example apps will be able to share example functionality. I also added an augementation of types to the global namespace so that consuming libraries shouldn't have to import Also, I did bump React Three Fiber and add a tweak to I feel bad about breaking MNIST Inference though. My implementation looks like it should be correct to me. Can you eyeball what is maybe going wrong? |
Thank you for doing this. The update on the MNIST example, I wouldn't worry too much about it. It makes sense that because of CanvasKit something weird might be going on here and I can look into it. When reviewing this PR some of the changes are very sensible but some changes feel unrelated, could that be? |
useLayoutEffect, | ||
useCallback, | ||
} from "react"; | ||
import type { RefObject } from "react"; |
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.
shouldn't this PR only add src/Canvas.web.tsx
, and src/main.web.ts
and that's it sorry if I am missing something.
@@ -0,0 +1,3 @@ | |||
{ |
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?
@@ -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 comment
The reason will be displayed to describe this comment to others. Learn more.
this import is not used here right?
Finally got around to adding vanilla web support without a companion Expo project. Just need some tweaks to the metro.config.js to make it support web as well.
To test, go to the example app and do
yarn web
, then open http://localhost:8081I was UNABLE to get MNISTInference example working fully - Nothing gets drawn to the Skia canvas, and the number 2 is always predicted. I'm honestly quite baffled on the lack of visual feedback, since
global.CanvasKit
is present and no errors are generated. And having 2 always be predicted maybe is an artifact of changing how the font is loaded? Sounds like something maybe the creator of react-native-skia should have a look at...Let me know if there's any changes you'd like me to make!