two.js
two.js copied to clipboard
React-native render
Do you think about making react-native renders (for ios & android)?
Not yet..! Does React Native support canvas drawing or expose a GL context? I haven't looked into it much.
I'm interested in this as well. The fact that two.js is renderer-agnostic and already has WebGL support is compelling: I imagine it would be fairly straightforward to port it to OpenGL.
Is that what React Native uses as the underlying drawing for iOS / Android?
Not exactly. React native is a weird word since it's got several of parts:
- Native rendering code written in Objective C, Swift, or Java
- Binding helpers to make native code callable from JS
- React components that call the native rendering code
- React, so you can assemble your app in JS using react components, which are written in JS but call native code, which does the rendering
In the case of two.js, it is probably possible to write a renderer with a combination of native code and JS (using parts 1 and 2 above). Since both iOS and Android support OpenGL ES, the logic from the WebGL render could be re-used, even though the code itself would have to be ported to the native language. The key here is that developers using two.js could share all their code between iOS, Android, and web apps, and it would be rendered natively on each platform.
Note that you wouldn't actually define a react component.
Ah hah, interesting interesting. I've spent some time exploring a Swift renderer... I agree that it's not out of the question to bring a Two.js style API to mobile app development. I'll continue to simmer on this and welcome any ideas you have!
@jonobr1 Maybe using something like this as backend? https://github.com/alibaba/GCanvas
Thanks @anion155. That looks like a very promising API and avenue for realisation!
Just giving this a bump... would be a fantastic addition
Thanks. The more datapoints the better I can prioritize features. This is a good point of reference and repository to see how to develop the native hooks: https://www.npmjs.com/package/create-react-native-plugin
Actually, this looks better: https://github.com/callstack/react-native-builder-bob And this SVG renderer react native library is a good reference: https://github.com/software-mansion/react-native-svg
And as far as iOS development, the process looks straightforward: https://reactnative.dev/docs/native-modules-ios
FYI, if and when released this would be a separate repository and npm package.
Inspecting React Three Fiber's implementation, there should be a way to import Two.js and iterate through each of its exported modules to create React components at runtime. This can be handled through a root bound to the React.createContext
method: https://react.dev/reference/react/createContext#usage
For bitmap rendering, React Three Fiber uses Expo.
Any updates on this? Would love two.js react native support :))
Thanks for the bump. Getting these messages helps me prioritize features. Unfortunately at the moment I'm pretty steeped in client work, so I don't have a lot of free time to undertake this. But, I am tracking it! And will post updates here when I make progress