-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Discussion Episode 7: React Native with Felipe Lima from Airbnb #55
Comments
cc @felipecsl 📧 |
🎉 |
Thanks guys, it was very interesting! |
Quite interesting episode! |
@hotchemi check out the library https://github.com/airbnb/react-native-maps, it integrates Google Maps with React Native using Google Play Services |
@felipecsl Awesome! I'll check it:D |
Great episode, thanks guys, I learned a lot of stuff about React Native 👍 The part that is still not clicking for me is how threading works. It was briefly mentioned but I can't imagine how you perform in javascript the typical task of triggering a long running method (e.g. sorting or networking) that stays inside your javascript code and then you update the UI to reflect that a long process is happening (like loading). Typically the long process method is launched into another thread and then you immediately update the UI to not block the user and inform her that request was received. How is this handled in single threaded javascript? |
Thank you very much for your feedback. Indeed, Xamarin is not like a webview and yes, xamarin uses native widgets. As far as I know, Xamarin runs in its own Virutal Machine interpreting byte code (generated from C#). For android development that means, you have a "virtual machine" embedded in your apk (which themself runs on a java virtual machine). This is a similar concept to React Native, where you have a JavaScript Engine embedded in your apk. Regarding JavaScript: If you search on Google for "JavaScript language" you will find such definitions:
hold on, it really makes sense as you will see in a minute: A JavaScript engine uses an EventLoop (in the javascript engine in your Browser) to run JavaScript. The equivalent on Android would be Android's main looper. You can post some peace of code (as functions / callback) on the EventLoop with JavaScript's EventLoop and Android's main looper are basically working the same way: The first "peace of code" put on the EventLoop queue is your main java script code included in your website (or ReactiveNative entry point). Each click event results in putting the callback function (which is a "peace of code") onto the queue. Hence non-blocking (you can put as many "peace of code" on the queue as you want, but that will not run immediately but once this "peace of code" is on the first position on the queue). Last but not least asynchronous concurrent: So while its true that only one thread executes the topmost "peace of code" from the EventLoop Queue, many threads can put "peace of code" on the queue of the EventLoop. For example, making an ajax http request: The JavaScript engine uses a browser API ( which then runs in on its own thread owned by the Browser and not by the javascript engine) to start making a http call and the result will be put back on the Queue of the EventLoop and then eventually the ajax http request callback will be executed when it is the first element on the Queue. I hope that clarifies your question. |
@sockeqwe I see what you did here, you're starting longblogposting! 😹 |
One of my co-workers (a web developer) listening about how we're solving different concurrency issues on Android often says: "no concurrency no problems". I should agree with him. We almost always can do things in one thread having less complicated code. |
@sockeqwe Excellent explanation 😍 |
@sebaslogen YAGNI doing development on React Native, or you chose a bad technology to build concurrent programs |
To help complete the picture on multiplatform SDKs, there is also Flutter from Google that compiles Dart to native, it's also inspired by React and produces Android and iOS apps: https://flutter.io/widgets-intro/ @Adambl4 knowing the advantages and limitations of React Native helps me figure out for which kind of apps or features this could be the right tool. |
@artem-zinnatullin I. CANT. STOP. IT. 😄 @sebaslogen As @Adambl4 already said, you only hardly ever will need it. However, with HTML5 https://www.facebook.com/notes/andy-street/react-native-scheduling/10153916310914590/ Just a side note: Workers are not really used widely in web development because as @Adambl4 pointed out correctly, usually you dont need them because the way javascript works is enough and the fact that you have a powerful backend for "computational stuff". Last but not least, you can bridge from React Native to native C or Java or Swift to make this computations outside of javascript. Regarding CPU: This is a "implementation detail" and responsibility of the JavaScript engine. On a PC also the browser tries to make use of the resources like CPU as best as possible. As Felipe explained in the podcast, react native uses at least 3 Threads (UI Thread, Rendering / Layouting Thread and "javascript main thread"). But yes, you as developer have no api for resource management (like CPU etc). That should be done / managed properly by the Browser / JavaScript engine. |
Wow excellent discussion, guys. Just learned a bunch of stuff! 😄 |
I was a bit confused by the part where there is no RecyclerView concept made in ReactNative. |
In other articles about ReactNative I have seen many people mentioning issues like animations stutter and screens opening slow. Also, routing and navigation concept seems to be a bit complex in ReactNative. |
@AAverin on the Airbnb app specifically, we've been avoiding building scrolling-intensive UI with React Native exactly because of that problem (lack of view recycling). AFAIK there is no easy solution for that issue (yet). There is a new implementation for the Android layout engine released recently called "Android nodes" which is supposed to address some of the performance issues, but it's still experimental.
Correct.
This is done in a background thread. I don't know how slow/fast it is, but yeah, you have to pass it through the JNI layer.
Correct. However, there are ways to work around that.
Since all RN bridging is done in the background, it doesn't impact the experience as much as you'd expect, but of course it will "always" be slower than building in pure native because there is an overhead involved. "Error prone" is also relative. If you have good automated test coverage (unit and integration) then you should be fine. |
@felipecsl Thanks for your answers. Also, Airbnb app in Play Store is >40Mb. How much of that is RN extra weight? How much of that is iOS part that is not really needed in Android APK? What are the chances to squeeze RN app into Instant Apps requirements for 3Mb? For comparison, our native app written in full Kotlin now is <10Mb, and we ship a lot of libraries that can be stripped for Instant App support |
You can test your javascript like you would for any web application. Just pick your favorite unit testing lib. I like Jasmine, but any should do.
We have a lot of stuff in the app, tons of dependencies (some which also include native code). RN contributes to ~10mb extra, which could be quite a lot depending on your current app size.
None. All the RN code is shared between both platforms and we have very little platform specific checks in the JS code, so virtually all of it is shared by iOS and Android.
I think getting it under 3Mb including RN is virtually impossible due to the JSC native binary size. If app size is a concern for you, I'd definitely stay away from RN. |
No description provided.
The text was updated successfully, but these errors were encountered: