
ComponentKit by Facebook: A React-Inspired View Framework for iOS - saniul
http://componentkit.org
======
i_s
This technology looks great.

It is too bad Facebook doesn't have their own platform like iOS or Android.
It's becoming pretty clear that they have a much better handle on UI
technology than Apple, Google, Microsoft, or anyone really. Them creating a
logical functional UI API on top of messy imperative APIs is very helpful, but
even better would be if that was not necessary.

~~~
eddieplan9
> _a logical functional UI API on top of messy imperative APIs_

But without the "messy" imperative API, the functional UI cannot be built.
This applies to all functional UI frameworks.

It's funny that one of React's core ideas is to ditch the now old
functional/declarative paradigm that is template languages and allows you to
use imperative JavaScript to directly build up a virtual DOM.

~~~
augustl
I don't think that's true. Under the mutable UI trees, 60 times a second the
entire UI is rendered from scratch in the OpenGL (or similar) layer. It seems
to me it would be possible to completely skip that part by making a new React-
like OpenGL renderer.

~~~
jiyinyiyong
I agree with that idea. In my view I think Skia method calls are like assembly
and virtual DOM is like a high level programming language. So I decided to try
one [https://github.com/Quamolit/](https://github.com/Quamolit/) my original
idea was to write in React way but generates operations that can be finished
with Canvas API.

I found it quite hard to finish such a project though. Browser vendor are more
likely doing the job of abstracting out hardware and OS powers so people can
utilize. There's still much more effect to be done to create an FRP-
like(functional reactive programming) system that everybody is happy with.

------
bsimpson
> (Don't confuse ComponentKit with React Native, a framework for building apps
> in Javascript.)

As long as they can't describe it without citing React, this is going to
confuse people. At the very least, the logline should mention
Obj-C/Swift/Cocoa to differentiate the projects.

~~~
fnordsensei
Indeed! I am for one quite confused. So this is native to Obj-C, right? Unlike
React Native, which is not native, I guess? Can it in any way be made to
interact with React Native or are they two completely different technologies
(i.e., does React Native render to ComponentKit)? Why do Facebook need both?
When do they use the one over the other? Why?

~~~
bsimpson
Ben commented on another thread yesterday. ComponentKit is similar because it
follows Facebook's philosophy for UI, but came about before React Native was
attempted. (Hence, it's written in Apple's native Obj-C as opposed to React's
JS.)

React Native came after some successful experiments later and isn't as mature.

------
natch
This looks really cool.

However, there were a couple odd things about the talk. If you're going to
spend so much time talking about managing mutation of data in a multithreaded
environment, you should at least mention GCD and explain why it doesn't figure
in the list of possible solutions to the problem. But the talk proceeded as if
GCD did not exist, listing a few straw man bad solutions, but not the obvious
go-to solution, GCD. Does the team consist of outsiders to the platform?

Similarly with Auto Layout. Why no mention? Very odd.

It sounds like the back story might be (just smelling this, no proof) that the
developers are really smart, but were making the classic mistake of fighting
the frameworks, and not having a good time, rather than learning the
recommended way (GCD, Auto Layout, etc.) since they came from other
backgrounds. Basically it's NIH syndrome.

Fortunately, what they came up with does look very nice... I can't wait to try
it out. But I wish I knew what they would have to say about working WITH the
frameworks that are provided, with tools like GCD and Auto Layout... how do
those not solve these problems?

~~~
adamjernst
Actually ComponentKit is built on GCD!

[https://github.com/facebook/componentkit/blob/master/Compone...](https://github.com/facebook/componentkit/blob/master/ComponentKit/DataSources/Common/CKComponentPreparationQueue.mm#L141-L142)

GCD is fantastic—one of my absolute favorites. We're trying to solve a problem
one level above that: exposing an API that doesn't require every view
developer to know the details of managing GCD queues and updating a
UICollectionView.

As for Autolayout, it's very powerful but isn't performant enough for layouts
as complex as Facebook's News Feed. We tried it first before developing
ComponentKit.

~~~
natch
Thanks for explaining. Doing everything top to bottom myself, my mind boggles
at an organization where there are multiple "view developers." Nice to have
that kind of resources!

Did you try Auto Layout with a flattened view hierarchy? Deeply nested view
hierarchies are not really the best way to go if there are performance issues.
You can get huge speedups by flattening things. I have a feeling this could
even work within the ComponentKit way of doing things.

------
Osmium
Interesting justification of their choice of Objective-C++ here:

[http://componentkit.org/docs/why-cpp.html](http://componentkit.org/docs/why-
cpp.html)

Anyone else have an opinion on this? Seems unusual for a iOS framework,
especially going forward, but the reasons sound sensible enough.

~~~
tambourine_man
They're changing to Swift in the next version.

(He mentions it at the end of the video)

~~~
MrGando
That makes sense, I don't understand how those two constructors are
equivalent, it seems that he's missing a couple of parameters in the C++
version.

------
aboodman
Man, Facebook is just crushing it with the open source UI libraries recently.

------
giulianoxt
Great initiative by the Facebook team. Anyone knows if there's a similar
framework for Android? (declarative description of the UI, rendering based on
immutable models, single data flow, etc)

~~~
crazychrome
[https://github.com/zserge/android-virtual-
layout](https://github.com/zserge/android-virtual-layout)

------
sam-mueller
I like the steady stream of innovative projects coming out of facebook as of
late, but I can't help but feel like there's quite a bit of overlap in their
initiatives. Just the fact that there's a footnote about how this isn't react-
native illustrates my sentiments exactly.

~~~
spicyj
You're right that there's some overlap:

> It may surprise you to hear that the Components library I’m describing is
> not React Native, but a separate project.

> Why the distinction? It’s simple: React Native hadn’t been invented yet when
> we rebuilt News Feed in Components. Everyone at Facebook is excited about
> the future of React Native, and it’s already been used to power both Mobile
> Ads Manager and Groups.

> (from
> [http://www.objc.io/issue-22/facebook.html](http://www.objc.io/issue-22/facebook.html))

(I work on React.) We're going full steam ahead on React Native, but this is a
slightly more mature project and we figured it made sense to release it for
people who (for whatever reason) can't or aren't ready to adopt React Native
yet. ComponentKit is also more mature and powers the most important part of
the Facebook iOS app so it's virtually guaranteed to be rock-solid, whereas
React Native has only been used in production for a few months.

~~~
prabhasp
Would be great to note this somewhere on the component kit site.

~~~
adamjernst
Will do shortly.

------
RussianCow
This is a great idea, but the fact that it's implemented in Objective-C++ is a
deal-breaker for me since I'm starting to use Swift in my iOS projects. From
the docs:

"ComponentKit is built on Objective-C++. There is no easy way to interoperate
with Swift since Swift cannot bridge to C++."

~~~
Osmium
You can still do it, it just presents an extra hurdle, e.g. see this project
on integrating OpenCV into a Swift project:

[https://github.com/foundry/OpenCVSwiftStitch](https://github.com/foundry/OpenCVSwiftStitch)

So it is possible.

------
ics
For all those focusing on the Objective-C++ aspect, I suggest watching the
talk.

    
    
        - Faster (potentially? actually?)
        - Safer, because Objective-C gives too many chances to crash at runtime
        - They "can't wait" to port to Swift, so don't fret.

------
chuckcode
Not sure if I feel jealous or aghast that they are going to rewrite everything
because apple launched swift... Must be amazing to work someplace with those
kinds of developer resources

------
perishabledave
For those interested, Facebook had a good talk about this at Scale 2014:
[https://www.youtube.com/watch?v=XhXC4SKOGfQ](https://www.youtube.com/watch?v=XhXC4SKOGfQ)

[edit] I just realized the video is linked on the front page of the frameworks
website.

------
EGreg
Is MVC really as bad as all that?

I lost him when he quickly breezed through suddenly adding more arrows in all
directions on the screen. Why would an inner View updating its height trigger
a change to the Model?

------
joshuak
Anyone have a sense of how this compares with QML? QML is declarative
(comparable?), and is cross platform which seems better out of hand.

------
hartator
Is this react native or is it a side project?

~~~
hartator
My bad, was explicit written on the website: "(Don't confuse ComponentKit with
React Native, a framework for building apps in Javascript.)"

