Live data from Hacker News

Flipboard releases React Canvas

github.com

71–80 of 136 posts

Re: Flipboard releases React Canvas

#71

Here's an interesting take on the "hybrid" app idea: - React Canvas is your application layer - HTML canvas is your common rendering layer - Browsers are your web runtime - Ejecta[0] is your iOS runtime - (I don't know a native android canvas runtime) [0] http://impactjs.com/ejecta --> renders with WebGL

React Native can be the core of your iOS/Androis runtime.

Re: Flipboard releases React Canvas

#72

If rendering UI to a canvas fits your needs then by all means do it. Just be aware that when it comes time to localize to other languages it starts getting hard to support things like CJK where in order to properly work there's an Input Method Editor ( http://i.imgur.com/JmmYwyi.gif ) that needs to be able to read the text. There's also cut/copy/paste which users can't do from text on a canvas. There's also "define"…

Well said. We also experimented with non-DOM rendering, in particular with WebGL-sprites. We achieved very nice result running constantly at 60fps even on low-end mobiles but it's nothing worth if one doesn't have all the DOM amenities you mentioned or a full integration with the browser environment.

Re: Flipboard releases React Canvas

#73

Earlier quoted context omitted.

It's css-layout: https://github.com/facebook/css-layout . The same engine used in React Native. It turns out that you only need a portion of CSS for apps. It's very performant.

Huh. Using a reimplemented, minimal CSS engine would mean more or less baked-in cross-browser compatibility, right?

Yes, but it's hard to do your own layout on the web because in times that want to width of an element that has text with `flex: 0`, you can't do that. It's mainly useful for things like this where you control everything.

Re: Flipboard releases React Canvas

#74
post #31

This looks really neat. How does this compare to Famo.us, which also claims at have smooth animations at 60 fps?

Famo uses the DOM, by encoding matrix transforms to strings and sticking them into the attributes of DOM nodes.

Technically, Famous can render to anything. I believe DOM was just their first render target. See their work on "mixed mode" WebGL rendering.

Re: Flipboard releases React Canvas

#75
post #17

Oh my, it is beautiful on the inside. Check out the source. They're totally showing off the power of React component model even when it doesn't render directly to DOM tree: https://github.com/Flipboard/react-canvas/blob/master/lib/Su... It's about describing nested side effects in time, really.

I actually wonder if it can be done even more elegant with RxJS?

Rx programming is so great. It's one of those things that you seldom find a use case for but when you do it leads to 50x easier and more readable code. It truly is for events what Linq was for collections Mostly only useful with more advanced ui and network programming though

Re: Flipboard releases React Canvas

#76

If rendering UI to a canvas fits your needs then by all means do it. Just be aware that when it comes time to localize to other languages it starts getting hard to support things like CJK where in order to properly work there's an Input Method Editor ( http://i.imgur.com/JmmYwyi.gif ) that needs to be able to read the text. There's also cut/copy/paste which users can't do from text on a canvas. There's also "define"…

Each of these features can be implemented on top of a canvas renderer. Not saying it's easy, but can be done. The browser itself does it, everything is 2D textures in the end.

Re: Flipboard releases React Canvas

#77
LOL, didn't expect it to work with React Hot Loader practically out of the box (except for for some reason): https://github.com/Flipboard/react-canvas/pull/3/files

The fun part is tweaking text layout algorithm and letting Hot Loader pick up changes when replacing components. Without browser refreshing, of course.

Re: Flipboard releases React Canvas

#78

If rendering UI to a canvas fits your needs then by all means do it. Just be aware that when it comes time to localize to other languages it starts getting hard to support things like CJK where in order to properly work there's an Input Method Editor ( http://i.imgur.com/JmmYwyi.gif ) that needs to be able to read the text. There's also cut/copy/paste which users can't do from text on a canvas. There's also "define"…

I'm glad someone else said this, you've echoed a lot of my thoughts. I'm a huge react fan, and I think this is super neat - once again showing the flexibility and power of React's component and render model. It'll probably have a big impact on game UI for the web.

That said, doing this on a content-driven site is absolute madness. It breaks so many things, and throws away so many fundamental tenets of the web. by the time they've reimplemented everything they'll have probably lost all performance wins. The fancy animations are a miniscule gain for such a great loss of functionality

Excited to play with this though, since I'm learning canvas and graphics!

Re: Flipboard releases React Canvas

#79

If rendering UI to a canvas fits your needs then by all means do it. Just be aware that when it comes time to localize to other languages it starts getting hard to support things like CJK where in order to properly work there's an Input Method Editor ( http://i.imgur.com/JmmYwyi.gif ) that needs to be able to read the text. There's also cut/copy/paste which users can't do from text on a canvas. There's also "define"…

React Canvas author here. I outlined some of the reasons why it is not always the right answer: http://engineering.flipboard.com/2015/02/mobile-web/#Practic... On Flipboard we use DOM where appropriate for text input and areas of the application where performance is less critical.

And to your point about accessibility: https://github.com/flipboard/react-canvas#accessibility

You are correct that the DOM just works. But we need a better option on the web in order to achieve the kinds of experiences that people have come to expect from native applications. The hope is that by pushing the browser beyond its limits that we can make progress in this area.

Re: Flipboard releases React Canvas

#80
post #15

A stronger indictment of the DOM than finding it necessary to combine a CSS parser written in Javascript, a virtual DOM and a canvas based renderer because it is faster than updating the DOM would be difficult to come up with... It looks like amazing work, but it's quite depressing that it's necessary.

Does mobile browser DOM rendering use GPU hardware acceleration?

Yes they can. If you are interested here is how the rendering works.

The rendering happens in batches, the first render is always an expensive operation and includes both "paint" & "layout".

- The "layout"-operation recalculates the tree of visible elements.

- The "paint"-operation paints the element and is commonly done using a software rasterizer.

Every subsequent render happens if an DOM-element triggers a layout or a paint (or both). A re-paint occurs when changes are made to an elements skin that changes visibility, but do not affect its layout. Examples of this include outline, visibility, or background color.

When you use GPU-accelerated CSS properties such as opacity, translate, rotate & scale, both layout- and paint-operations are not executed. The GPU handles the changes for those properties. This is how famo.us wants to achieve its "60fps".

React by itself can cause expensive operations too if you trigger a CSS property that is not GPU-accelerated. In the process of rendering, a DOM-element can be destroyed and recreated when your state or model changes. So be vary of third-party React-components that promise "fluid" or "fast" speeds. IMO animation is still a research-topic for React. Their manual currently lists a method for basic CSS animations and transitions, but it's projects like React Canvas that make React a worthwhile contender for performant animations.

http://facebook.github.io/react/docs/animation.html

Mobile browsers are no different to Desktop browsers, almost every smartphone has a GPU of some sort. So you have 2 main-bottlenecks with every device. The first is the CPU (& RAM), the next one is the GPU (& the GPU-RAM).

What is GPU-accelerated and why:

http://www.html5rocks.com/en/tutorials/speed/high-performanc...

How Reflows and Repaints cause slow javascript:

http://www.stubbornella.org/content/2009/03/27/reflows-repai...

Post reply on HN