two.js icon indicating copy to clipboard operation
two.js copied to clipboard

React-native render

Open gut4 opened this issue 9 years ago • 14 comments

Do you think about making react-native renders (for ios & android)?

gut4 avatar Oct 27 '15 15:10 gut4

Not yet..! Does React Native support canvas drawing or expose a GL context? I haven't looked into it much.

jonobr1 avatar Oct 28 '15 16:10 jonobr1

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.

mike-marcacci avatar Dec 02 '17 19:12 mike-marcacci

Is that what React Native uses as the underlying drawing for iOS / Android?

jonobr1 avatar Dec 02 '17 20:12 jonobr1

Not exactly. React native is a weird word since it's got several of parts:

  1. Native rendering code written in Objective C, Swift, or Java
  2. Binding helpers to make native code callable from JS
  3. React components that call the native rendering code
  4. 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.

mike-marcacci avatar Dec 02 '17 20:12 mike-marcacci

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 avatar Dec 03 '17 00:12 jonobr1

@jonobr1 Maybe using something like this as backend? https://github.com/alibaba/GCanvas

anion155 avatar Aug 07 '19 20:08 anion155

Thanks @anion155. That looks like a very promising API and avenue for realisation!

jonobr1 avatar Aug 08 '19 07:08 jonobr1

Just giving this a bump... would be a fantastic addition

logan-markewich avatar Nov 13 '22 22:11 logan-markewich

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

jonobr1 avatar Nov 14 '22 22:11 jonobr1

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

jonobr1 avatar Feb 09 '23 18:02 jonobr1

FYI, if and when released this would be a separate repository and npm package.

jonobr1 avatar Feb 09 '23 18:02 jonobr1

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.

jonobr1 avatar Apr 14 '23 06:04 jonobr1

Any updates on this? Would love two.js react native support :))

HeroOfOdyssey avatar Sep 22 '23 16:09 HeroOfOdyssey

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

jonobr1 avatar Sep 23 '23 00:09 jonobr1