r/reactnative • u/cawfree • May 30 '20
Rough.js bindings are now available for React Native. ✍️(source in comments)
7
3
3
u/richpeopleshit May 31 '20
Dude yes! I was trying to implement this last week in React Native. I got stuck and couldn't get it working properly. I was planning on picking back up at some point but now I'm happy to see you've done this!
1
2
2
u/GreatCosmicMoustache May 31 '20
Great job! Random question, what is the pattern that let's you make "namespaced components", for lack of a better word? The <Rough.ComponentName> thing
2
u/cawfree May 31 '20
Thanks very much! I
export defaulta frozen object which contains all of the components. You can see this here!1
u/GreatCosmicMoustache May 31 '20
Great stuff, thanks a lot! I've been wondering about that for a good while now
2
5
May 30 '20
[removed] — view removed comment
6
u/cawfree May 30 '20
I'm really glad you think so! Thanks a lot.
Originally, I was under the impression that the rendering was something proprietary to Excalidraw, until I randomly happened upon this tweet. As soon as I saw that it was open source, I just had to get it into React Native. I remember so many times over the past couple of years where I would have loved to have had some hand-drawn effects, so better late than never!
Honestly, the real magic behind the integration is that Rough.js was designed extremely well.
I thought it would have been much harder, and require a lot more cherry picking, because usually libraries like this are very tightly coupled to the DOM.
But, we were lucky. Rough.js exposes an extremely useful class called
RoughGeneratorwhich is pure business logic, a high level interface, and just returns SVG parameters which are directly compatible react-native-svg. I believe this has come about because the original library offers a way to target either the DOM directly, or ansvgnode. I think this requirement introduced the perfect level of abstraction for us to hook into. :)
9
u/cawfree May 30 '20
source