Flipboard releases React Canvas
github.com
github.com
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" which is built into OSX and iOS (others?) letting the user select a word and look up its definition in the dictionary. Finally I'm sure there are accessibility issues. And don't forget right to left like Arabic. (https://www.flickr.com/photos/u-e/2680759761/)
UI in a game (the most common place to render a UI yourself) usually doesn't care about these things. I'd hazard a guess though that most apps do. I know I get really annoyed when I can't copy small pieces of text from a native app. For example copying a link to a browser, copying a phone number to my phone, copying an address to maps, etc.
In general DOM makes all of these just work.
edit: they actually have their own layout implementation(s). I wonder how those compare to the built in browser versions (performance, correctness, ...)?
https://github.com/Flipboard/react-canvas/blob/master/lib/La...
Imho, making custom "DOM" via canvas just to make UI look fancy is not a solution. Web was always about delivering accessible content for everyone.
Though, library might be good for web apps or games that are not content oriented.
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!
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.
Worth some extra html and style code for those benefits.
I think this is a really cool project and a technical achievement, but I disagree with this one statement. We don't actually need to "achieve the kinds of experiences". This is my biggest problem with designers I've encountered, they do not see the benefits of the platform and try to design everything the same way. The web has distinct advantages that makes it special and I think way too much effort is put into making it behave like native applications (trying to catch up to its benefits rather than leaning on the web's).
Thats bad for the web ecosystem in general. We want the web to be the place people go for content instead of native walled gardens.
Great user experiences make that happen.
Rubbish user experiences that look and feel like a lame 2nd cousin to native apps actively harm the web ecosystem (look at mobile facebook; lots of people just use the app and dont even use the browser on their phone)
The web's benefits are that powerful.
The difference was that then there was a meaningful functional difference between a cloud app and a local desktop app. Cloud apps were better, and people appreciated that.
I'm not convinced that web apps, which have worse UI, not access to native apis (camera, notifications, contacts, etc) offer a meaningful benefit over native apps.
You use mail.google.com on your phone? I don't.
How about Twitter? Facebook? Instagram? App or website?
It's because the native app is better.
The web is not special, it just happens to exist. If you keep building experiences for it that are meaningfully less functional than native apps, people will continue to flock to native apps.
sure... it's not all about hitting 60fps animations on a web app; but web apps that are closer to the look and feel of native apps is the way forward if you're building for the web.
trying to emulate native apps in the browser is the same losing battle, but the inverse. good luck with canvas
I know I usually prefer apps to the web not because of lack of fancy graphical effects at 60 FPS, but because web pages are so larded up w/ ads and other crap, it's hard to actually read the content. Or they try to do tricky things which somehow break on an iPhone's screen. Etc.
Also, hey everyone, before you downvote the parent, please recall this article that you voted so highly just a few weeks ago, and consider its implications on building a web ui on top of canvas: https://news.ycombinator.com/item?id=8965048
> 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.
I agree, and I think you are actually doing this in a way that can work (unlike some other attempts in this space).
For example copy/paste and "define" require you to support selecting text on your canvas and then telling the OS about it when the user picks "copy" or "define". Otherwise you get the bad behavior that 99.99% of all native apps have which is that they don't support selecting anything except in editable textareas so if they display an address I can't copy it into maps.
You could argue the browser should add APIs so you can provide what the user has selected to the OS but, it means every developer has to be perfect. Developers who get it wrong end up making apps that don't follow any OS conventions, don't handle the edge cases, don't handle things when running in other languages, etc etc etc.
To take it to an extreme, maybe the browser should just be a rectangle of pixels and JavaScript. No DOM whatsoever. Imagine we had that world. There'd be no search engines and every page would have a totally unique UI. Some pages you'd use the keyboard to move a cursor to select something. Others would use the mouse. Still others might use a joystick. Some would require IJKL instead of the cursor keys. None of them would have native OS widgets. They'd all use a different font system. Most would probably only support ASCII and maybe ANSI at best.
Instead we have HTML and a DOM and most of these issues are solved and that uniformity has some arguable benefits.
I'm not saying stop your work. I'm just saying I'm there are trade offs. I think an argument can be made either way. Maybe rather than going back to a rect of pixels we should also be lobbying for ways to make the DOM better so we can keep the good parts (universality?) and still do better?
With that said you could easily build a component library on top of this that renders to DOM or react-native or canvas or HTML (server-side) depending on what your use case is (just use dependency injection to get a reference to your underlying components). This way you can more easily manage these tradeoffs.
I think this project is so, so exciting and awesome.
Unfortunately, that affects most games, which would otherwise be an obvious niche for something like this.
More recently I found and fell in love with React for other frontend work, and use it exclusively now for any view-related work. I might have to go back and rewrite the ugliest parts of my code with this, it looks awesome. Kudos to Flipboard for open-sourcing it.
1) Your site looks very similar to bitcoinwisdom ( which i love). Did that come about by coincidence or design? Are there any open source tools that you were able to build off of that bitcoinwisdom also uses?
2) Could you build out support for visualizing financial markets like stocks and the price of oil? The bitcoin ecosystem has a bunch of great UI, but it's difficult to find good web products for actual securities
I'm not sure what they use to build their app. No part of mine is open source except tiny bits of d3, and jQuery.
Wrt supporting other types of markets, I'd love to. The reason Bitcoin has had a wave of nice web-based interfaces is because the exchanges all offer free-to-use HTTP APIs. The "old-world" financial markets all charge money for data access, and it's generally not as easy to consume either. Bitcoin markets were born into the web era.
Sorry to hijack this thread, but I have a question: you seem to have been successful in stopping left/right swipe from navigating back and forward. The app I'm working on supports horizontal scrolling, but it can be a bit confusing if you mean to scroll and accidentally navigate.
I've tried a few things and looked around for answers, but so far the solutions I've found haven't worked out. Can I ask what your secret is? :)
document.querySelector('canvas').addEventListener('mousewheel', function (e) {
e.preventDefault();
});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.
Seeing as one of the benefits of React is in server-side rendering, and now with the new OSS nature of .NET, it's worth considering standard Rx as well ( https://msdn.microsoft.com/en-gb/data/gg577609.aspx ).
Rx is very new to me, so I may have this description wrong, but it essentially seems to be well-supported event-driven programming library. Worth a look if you're interested in FRP.
Is React a good introduction to the land of frontend programming? Or do I first need to familiarize myself with vanilla JS and go bottom up to React?
This is a pretty great book
Alternate your time spent learning.
Sometimes study high-level, sometimes low-level. (Low-level, tongue-in-cheek, as in "JS is the bytecode of web applications.")
I think you can build a lot on top of React with minimal knowledge of js (so, yes, start), but you definitely want to go deep and understand how it works inside (so, yes, also study js).
As you're using a high level framework, you're interacting with that more than the details of JavaScript. So in essence you're learning 'React' not 'JavaScript'.
So just start building in React and the JS will come along naturally.
[1] http://bonsaiden.github.com/JavaScript-Garden/
With the JS quirks out of the way, I would recommend building something in React and muddle through things with SO/google.
The hardest part of frontend dev for an experienced backend dev is the CSS. CSS is conceptually simple but there's a LOT of random domain knowledge you need to get layouts you want. You can bypass a lot of it by using a sass framework (e.g. foundation or bourbon) at the cost of adding a build step and another abstraction layer on top of CSS.
This is the same technique used by Netflix for their React-based television UI.
It looks like amazing work, but it's quite depressing that it's necessary.
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...
If the joke is lost please go read about the similarities between react and immediate mode rendering systems.
I don't have a list of resources.
There is also a lengthy and insightful blog-post about the subject where I found the video: http://jlongster.com/Removing-User-Interface-Complexity,-or-...
There's also a relatively recent library (C++)
- 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
It was behind its times with mxmlc. mxmlc made it painfully clear, even with incremental compile, that you were building a client-server application in a web age.
Once you wanted to build custom UIs, you lost the "WYSIWYG" GUI rapid development environment that was the whole selling point that Adobe came in with.
The data synchronization system worked but it was opaque and how (at the time) they made their money.
Flex lost to the open web.
The fun part is tweaking text layout algorithm and letting Hot Loader pick up changes when replacing components. Without browser refreshing, of course.
> Custom fonts are not currently supported but will be added in a future version.
Ok, that is a pity. I wonder if it has something to do with the complexity of implementing measureText fully in javascript.
React is taking over the web, and I'm excited for it - coming from a person who is incredibly cynical about frameworks. React is proving itself as a powerful library, not an assumption driven framework.
In other words, why is HTML like this:
<Group style={styles.group}>
<Image style={styles.image} src='http://...' />
<Text style={styles.text}>
Lorem ipsum...
</Text>
</Group>
Preferable to something like this (which can easily be done with some helper methods wrapping the verbose React DOM methods): $group({styles: style.group},
$image({styles: image, src: 'http://...'}),
$text({styles: style.text},
'Lorem ipsum...'));
No pre processing step required, and of course it's natural to imbed js in, er..., js.What am I missing? Why keep the HTML part in all this?
The second approach is what I was doing in various flavours for years prior to JSX. I ended up having to adopt comma-first to stay sane in larger/deeper templates, ( e.g. https://gist.github.com/insin/8e72bed793772d82ca8d ). The first thing I did when I saw JSX was start to write a React.DOM emitting version of my then-usual JSON-ML type stuff, but then I tried it and... never going back.
I'm not convinced that HTML is preferable to other representations of the DOM, particularly for representing UI's and applications (rather than documents). The clojure script wrappers for React I've seen seem to believe, for example, that lisp is better at representing the DOM than HTML and I tend to agree. Especially since any configured IDE should be pointing out missed commas and have rainbow parens.
One thing that is different between your examples and the DOM I've been creating with React is that I tend to make custom tags, and I don't end up with tons of repetitive looking stuff. Your last example is quite readable to my eyes, and would be even more so if perhaps decomposed into some helper functions and, of course, if loops were used and the DOM was populated from some data structure.
* Copy/paste (holding on an article gives the options to email or report)
* Pinch to zoom
* Double tap to zoom (opens links instead)
* iOS swipe forwards and backwards (renders the page swipe animation twice, at 60fps I guess)
* iOS Reader View (go on, try it, I laughed)
And most importantly
* Any sort of accessibility
60fps doesn't matter to someone who can't see the screen.
60fps doesn't matter to someone who relies on assistive technologies to surf the web.
60fps doesn't really matter.
Disillusioned web zealot here.
Which reminds me of flash. Most flash controls had similar drawbacks. I think web development shouldn't repeat that mistake (again).
It also reminds me that Google Docs took similar approach. As far as I remember they use a lot of canvas with a bit of DOM intertwined where necessary.
Also, it would be really cool to run everything except rendering in a worker thread and send rendering commands to the UI thread, like react-native does.
Posting b/c someone from Flipboard is probably monitoring this thread ;-)
Tested with Chrome/FF/IE (all latest) with the same result. Hope it helps.
As the components are rendered to canvas, would the metadata that usually feeds SEO be harder to generate? Is that something you could fix through use of the parallel DOM (it's mentioned briefly on the page)?
Just an experiment, but that could be very powerful. A lot of canvas-eligible projects are done in the dom because CSS makes it easier that messing with hardcoding all the style in js functions.
On https://flipboard.com/explore I get some exciting but very distracting rendering artefacts (blocks on the images changing intensity at a high speed until I start scrolling fast - if I scroll through slowly, the flickering continues)..
If I click through on one of the example pages, scrolling seemingly randomly stops working smetimes (after a few tries, it started snapping back to where it was, even when there clearly is more content below).
This is with the Android browser on 4.2.2, admittedly on a rather obscure phone (a Kingzone K1 Turbo) .
If you're interested in more details, my e-mail is on my profile.
I was rather impressed with flipboard.com on my mobile. Although it seemed to hit a jank on a few scrolls and I wonder if there are UX implications for not being able to highlight and copy some of the text.
Regardless very cool!
[1]http://engineering.flipboard.com/2015/02/mobile-web/ [2]https://flipboard.com/@flipboard/flipboard-picks-8a1uu7ngz [3]https://flipboard.com/@flipboard/ten-for-today-k6ln1khuz