diff --git a/blog/2015-03-26-react-native-bringing-modern-web-techniques-to-mobile.md b/blog/2015-03-26-react-native-bringing-modern-web-techniques-to-mobile.md deleted file mode 100644 index 7fb0e11469960c..00000000000000 --- a/blog/2015-03-26-react-native-bringing-modern-web-techniques-to-mobile.md +++ /dev/null @@ -1,22 +0,0 @@ ---- -title: React Native: Bringing modern web techniques to mobile -author: Tom Occhino -authorTitle: Engineering Manager at Facebook -authorURL: https://github.com/tomocchino -authorImage: https://avatars0.githubusercontent.com/u/13947?v=3&s=460 -authorTwitter: tomocchino -hero: /react-native/blog/img/dark-hero.png -category: announcements ---- - -We introduced [React](https://code.facebook.com/projects/176988925806765/react/) to the world two years ago, and since then it's seen impressive growth, both inside and outside of Facebook. Today, even though no one is forced to use it, new web projects at Facebook are commonly built using React in one form or another, and it's being broadly adopted across the industry. Engineers are choosing to use React every day because it enables them to spend more time focusing on their products and less time fighting with their framework. It wasn't until we'd been building with React for a while, though, that we started to understand what makes it so powerful. - -React forces us to break our applications down into discrete components, each representing a single view. These components make it easier to iterate on our products, since we don't need to keep the entire system in our head in order to make changes to one part of it. More important, though, React wraps the DOM's mutative, imperative API with a declarative one, which raises the level of abstraction and simplifies the programming model. What we've found is that when we build with React, our code is a lot more predictable. This predictability makes it so we can iterate more quickly with confidence, and our applications are a lot more reliable as a result. Additionally, it's not only easier to scale our applications when they're built with React, but we've found it's also easier to scale the size of our teams themselves. - -Together with the rapid iteration cycle of the web, we've been able to build some awesome products with React, including many components of Facebook.com. Additionally, we've built amazing frameworks in JavaScript on top of React, like [Relay](https://facebook.github.io/react/blog/2015/02/20/introducing-relay-and-graphql.html), which allows us to greatly simplify our data fetching at scale. Of course, web is only part of the story. Facebook also has widely used Android and iOS apps, which are built on top of disjointed, proprietary technology stacks. Having to build our apps on top of multiple platforms has bifurcated our engineering organization, but that's only one of the things that makes native mobile application development hard. - - - -> This is an excerpt. Read the rest of the post on [Facebook Code](https://code.facebook.com/posts/1014532261909640/react-native-bringing-modern-web-techniques-to-mobile/). diff --git a/blog/2015-09-14-react-native-for-android.md b/blog/2015-09-14-react-native-for-android.md deleted file mode 100644 index e5b0c3d95f4f68..00000000000000 --- a/blog/2015-09-14-react-native-for-android.md +++ /dev/null @@ -1,19 +0,0 @@ ---- -title: React Native for Android: How we built the first cross-platform React Native app -author: Daniel Witte -authorTitle: Software Engineer at Facebook -authorURL: https://www.facebook.com/drwitte -authorImage: https://scontent-sea1-1.xx.fbcdn.net/v/t1.0-1/c54.54.681.681/s160x160/20622_10100459314481893_1435252658_n.jpg?_nc_log=1&oh=7afdb6aaa02f320c4dd4749733140133&oe=59D77C28 -hero: /react-native/blog/img/blue-hero.jpg -category: announcements ---- - -Earlier this year, we introduced [React Native for iOS](https://code.facebook.com/posts/1014532261909640/react-native-bringing-modern-web-techniques-to-mobile/). React Native brings what developers are used to from React on the web — declarative self-contained UI components and fast development cycles — to the mobile platform, while retaining the speed, fidelity, and feel of native applications. Today, we're happy to release React Native for Android. - -At Facebook we've been using React Native in production for over a year now. Almost exactly a year ago, our team set out to develop the [Ads Manager app](https://www.facebook.com/business/news/ads-manager-app). Our goal was to create a new app to let the millions of people who advertise on Facebook manage their accounts and create new ads on the go. It ended up being not only Facebook's first fully React Native app but also the first cross-platform one. In this post, we'd like to share with you how we built this app, how React Native enabled us to move faster, and the lessons we learned. - - - -> This is an excerpt. Read the rest of the post on [Facebook Code](https://code.facebook.com/posts/1189117404435352/react-native-for-android-how-we-built-the-first-cross-platform-react-native-app/). diff --git a/blog/2015-11-23-making-react-native-apps-accessible.md b/blog/2015-11-23-making-react-native-apps-accessible.md deleted file mode 100644 index 37630c437e86ee..00000000000000 --- a/blog/2015-11-23-making-react-native-apps-accessible.md +++ /dev/null @@ -1,25 +0,0 @@ ---- -title: Making React Native apps accessible -author: Georgiy Kassabli -authorTitle: Software Engineer at Facebook -authorURL: https://www.facebook.com/georgiy.kassabli -authorImage: https://scontent-sea1-1.xx.fbcdn.net/v/t1.0-1/c0.0.160.160/p160x160/1978838_795592927136196_1205041943_n.jpg?_nc_log=1&oh=d7a500fdece1250955a4d27b0a80fee2&oe=59E8165A -hero: /react-native/blog/img/blue-hero.jpg -category: engineering ---- - -With the recent launch of React on web and React Native on mobile, we've provided a new front-end framework for developers to build products. One key aspect of building a robust product is ensuring that anyone can use it, including people who have vision loss or other disabilities. The Accessibility API for React and React Native enables you to make any React-powered experience usable by someone who may use assistive technology, like a screen reader for the blind and visually impaired. - -For this post, we're going to focus on React Native apps. We've designed the React Accessibility API to look and feel similar to the iOS and Android APIs. If you've developed accessible applications for the web, iOS, or Android before, you should feel comfortable with the framework and nomenclature of the React AX API. For instance, you can make a UI element _accessible_ (therefore exposed to assistive technology) and use _accessibilityLabel_ to provide a string description for the element: - -``` - -``` - -Let's walk through a slightly more involved application of the React AX API by looking at one of Facebook's own React-powered products: the **Ads Manager app**. - - - -> This is an excerpt. Read the rest of the post on [Facebook Code](https://code.facebook.com/posts/435862739941212/making-react-native-apps-accessible/). diff --git a/blog/2016-03-24-introducing-hot-reloading.md b/blog/2016-03-24-introducing-hot-reloading.md deleted file mode 100644 index d85ee82a03d751..00000000000000 --- a/blog/2016-03-24-introducing-hot-reloading.md +++ /dev/null @@ -1,214 +0,0 @@ ---- -title: Introducing Hot Reloading -author: Martín Bigio -authorTitle: Software Engineer at Instagram -authorURL: https://twitter.com/martinbigio -authorImage: https://avatars3.githubusercontent.com/u/535661?v=3&s=128 -authorTwitter: martinbigio -category: engineering ---- - -React Native's goal is to give you the best possible developer experience. A big part of it is the time it takes between you save a file and be able to see the changes. Our goal is to get this feedback loop to be under 1 second, even as your app grows. - -We got close to this ideal via three main features: - -* Use JavaScript as the language doesn't have a long compilation cycle time. -* Implement a tool called Packager that transforms es6/flow/jsx files into normal JavaScript that the VM can understand. It was designed as a server that keeps intermediate state in memory to enable fast incremental changes and uses multiple cores. -* Build a feature called Live Reload that reloads the app on save. - -At this point, the bottleneck for developers is no longer the time it takes to reload the app but losing the state of your app. A common scenario is to work on a feature that is multiple screens away from the launch screen. Every time you reload, you've got to click on the same path again and again to get back to your feature, making the cycle multiple-seconds long. - - -## Hot Reloading - -The idea behind hot reloading is to keep the app running and to inject new versions of the files that you edited at runtime. This way, you don't lose any of your state which is especially useful if you are tweaking the UI. - -A video is worth a thousand words. Check out the difference between Live Reload (current) and Hot Reload (new). - - - -If you look closely, you can notice that it is possible to recover from a red box and you can also start importing modules that were not previously there without having to do a full reload. - -**Word of warning:** because JavaScript is a very stateful language, hot reloading cannot be perfectly implemented. In practice, we found out that the current setup is working well for a large amount of usual use cases and a full reload is always available in case something gets messed up. - -Hot reloading is available as of 0.22, you can enable it: - -* Open the developer menu -* Tap on "Enable Hot Reloading" - - -## Implementation in a nutshell - -Now that we've seen why we want it and how to use it, the fun part begins: how it actually works. - -Hot Reloading is built on top of a feature [Hot Module Replacement](https://webpack.github.io/docs/hot-module-replacement-with-webpack.html), or HMR. It was first introduced by Webpack and we implemented it inside of React Native Packager. HMR makes the Packager watch for file changes and send HMR updates to a thin HMR runtime included on the app. - -In a nutshell, the HMR update contains the new code of the JS modules that changed. When the runtime receives them, it replaces the old modules' code with the new one: - -![](/react-native/blog/img/hmr-architecture.png) - - -The HMR update contains a bit more than just the module's code we want to change because replacing it, it's not enough for the runtime to pick up the changes. The problem is that the module system may have already cached the *exports* of the module we want to update. For instance, say you have an app composed of these two modules: - -``` -// log.js -function log(message) { - const time = require('./time'); - console.log(`[${time()}] ${message}`); -} - -module.exports = log; -``` - -``` -// time.js -function time() { - return new Date().getTime(); -} - -module.exports = time; -``` - -The module `log`, prints out the provided message including the current date provided by the module `time`. - -When the app is bundled, React Native registers each module on the module system using the `__d` function. For this app, among many `__d` definitions, there will one for `log`: - -``` -__d('log', function() { - ... // module's code -}); -``` - -This invocation wraps each module's code into an anonymous function which we generally refer to as the factory function. The module system runtime keeps track of each module's factory function, whether it has already been executed, and the result of such execution (exports). When a module is required, the module system either provides the already cached exports or executes the module's factory function for the first time and saves the result. - -So say you start your app and require `log`. At this point, neither `log` nor `time`'s factory functions have been executed so no exports have been cached. Then, the user modifies `time` to return the date in `MM/DD`: - -``` -// time.js -function bar() { - var date = new Date(); - return `${date.getMonth() + 1}/${date.getDate()}`; -} - -module.exports = bar; -``` - -The Packager will send time's new code to the runtime (step 1), and when `log` gets eventually required the exported function gets executed it will do so with `time`'s changes (step 2): - -![](/react-native/blog/img/hmr-step.png) - - -Now say the code of `log` requires `time` as a top level require: - -``` -const time = require('./time'); // top level require - -// log.js -function log(message) { - console.log(`[${time()}] ${message}`); -} - -module.exports = log; -``` - -When `log` is required, the runtime will cache its exports and `time`'s one. (step 1). Then, when `time` is modified, the HMR process cannot simply finish after replacing `time`'s code. If it did, when `log` gets executed, it would do so with a cached copy of `time` (old code). - -For `log` to pick up `time` changes, we'll need to clear its cached exports because one of the modules it depends on was hot swapped (step 3). Finally, when `log` gets required again, its factory function will get executed requiring `time` and getting its new code. - -![](/react-native/blog/img/hmr-log.png) - - -## HMR API - -HMR in React Native extends the module system by introducing the `hot` object. This API is based on [Webpack](https://webpack.github.io/docs/hot-module-replacement.html)'s one. The `hot` object exposes a function called `accept` which allows you to define a callback that will be executed when the module needs to be hot swapped. For instance, if we would change `time`'s code as follows, every time we save time, we'll see “time changed” in the console: - -``` -// time.js -function time() { - ... // new code -} - -module.hot.accept(() => { - console.log('time changed'); -}); - -module.exports = time; -``` - -Note that only in rare cases you would need to use this API manually. Hot Reloading should work out of the box for the most common use cases. - -## HMR Runtime - -As we've seen before, sometimes it's not enough only accepting the HMR update because a module that uses the one being hot swapped may have been already executed and its imports cached. For instance, suppose the dependency tree for the movies app example had a top-level `MovieRouter` that depended on the `MovieSearch` and `MovieScreen` views, which depended on the `log` and `time` modules from the previous examples: - - -![](/react-native/blog/img/hmr-diamond.png) - - -If the user accesses the movies' search view but not the other one, all the modules except for `MovieScreen` would have cached exports. If a change is made to module `time`, the runtime will have to clear the exports of `log` for it to pick up `time`'s changes. The process wouldn't finish there: the runtime will repeat this process recursively up until all the parents have been accepted. So, it'll grab the modules that depend on `log` and try to accept them. For `MovieScreen` it can bail, as it hasn't been required yet. For `MovieSearch`, it will have to clear its exports and process its parents recursively. Finally, it will do the same thing for `MovieRouter` and finish there as no modules depends on it. - -In order to walk the dependency tree, the runtime receives the inverse dependency tree from the Packager on the HMR update. For this example the runtime will receive a JSON object like this one: - -``` -{ - modules: [ - { - name: 'time', - code: /* time's new code */ - } - ], - inverseDependencies: { - MovieRouter: [], - MovieScreen: ['MovieRouter'], - MovieSearch: ['MovieRouter'], - log: ['MovieScreen', 'MovieSearch'], - time: ['log'], - } -} -``` - -## React Components - -React components are a bit harder to get to work with Hot Reloading. The problem is that we can't simply replace the old code with the new one as we'd loose the component's state. For React web applications, [Dan Abramov](https://twitter.com/dan_abramov) implemented a babel [transform](https://gaearon.github.io/react-hot-loader/) that uses Webpack's HMR API to solve this issue. In a nutshell, his solution works by creating a proxy for every single React component on *transform time*. The proxies hold the component's state and delegate the lifecycle methods to the actual components, which are the ones we hot reload: - -![](/react-native/blog/img/hmr-proxy.png) - -Besides creating the proxy component, the transform also defines the `accept` function with a piece of code to force React to re-render the component. This way, we can hot reload rendering code without losing any of the app's state. - -The default [transformer](https://github.com/facebook/react-native/blob/master/packager/transformer.js#L92-L95) that comes with React Native uses the `babel-preset-react-native`, which is [configured](https://github.com/facebook/react-native/blob/master/babel-preset/configs/hmr.js#L24-L31) to use `react-transform` the same way you'd use it on a React web project that uses Webpack. - -## Redux Stores - -To enable Hot Reloading on [Redux](https://redux.js.org/) stores you will just need to use the HMR API similarly to what you'd do on a web project that uses Webpack: - -``` -// configureStore.js -import { createStore, applyMiddleware, compose } from 'redux'; -import thunk from 'redux-thunk'; -import reducer from '../reducers'; - -export default function configureStore(initialState) { - const store = createStore( - reducer, - initialState, - applyMiddleware(thunk), - ); - - if (module.hot) { - module.hot.accept(() => { - const nextRootReducer = require('../reducers/index').default; - store.replaceReducer(nextRootReducer); - }); - } - - return store; -}; -``` - -When you change a reducer, the code to accept that reducer will be sent to the client. Then the client will realize that the reducer doesn't know how to accept itself, so it will look for all the modules that refer it and try to accept them. Eventually, the flow will get to the single store, the `configureStore` module, which will accept the HMR update. - -## Conclusion - -If you are interested in helping making hot reloading better, I encourage you to read [Dan Abramov's post around the future of hot reloading](https://medium.com/@dan_abramov/hot-reloading-in-react-1140438583bf#.jmivpvmz4) and to contribute. For example, Johny Days is going to [make it work with multiple connected clients](https://github.com/facebook/react-native/pull/6179). We're relying on you all to maintain and improve this feature. - -With React Native, we have the opportunity to rethink the way we build apps in order to make it a great developer experience. Hot reloading is only one piece of the puzzle, what other crazy hacks can we do to make it better? diff --git a/blog/2016-03-28-dive-into-react-native-performance.md b/blog/2016-03-28-dive-into-react-native-performance.md deleted file mode 100644 index 629b83ea121ff4..00000000000000 --- a/blog/2016-03-28-dive-into-react-native-performance.md +++ /dev/null @@ -1,23 +0,0 @@ ---- -title: Dive into React Native Performance -author: Pieter De Baets -authorTitle: Software Engineer at Facebook -authorURL: https://github.com/javache -authorImage: https://avatars1.githubusercontent.com/u/5676?v=3&s=460 -authorTwitter: javache -category: engineering ---- - -React Native allows you to build iOS and Android apps in JavaScript using React and Relay's declarative programming model. This leads to more concise, easier-to-understand code; fast iteration without a compile cycle; and easy sharing of code across multiple platforms. You can ship faster and focus on details that really matter, making your app look and feel fantastic. Optimizing performance is a big part of this. Here is the story of how we made React Native app startup twice as fast. - -## Why the hurry? - -With an app that runs faster, content loads quickly, which means people get more time to interact with it, and smooth animations make the app enjoyable to use. In emerging markets, where [2011 class phones](https://code.facebook.com/posts/952628711437136/classes-performance-and-network-segmentation-on-android/) on [2G networks](https://newsroom.fb.com/news/2015/10/news-feed-fyi-building-for-all-connectivity/) are the majority, a focus on performance can make the difference between an app that is usable and one that isn't. - -Since releasing React Native on [iOS](https://facebook.github.io/react/blog/2015/03/26/introducing-react-native.html) and on [Android](https://code.facebook.com/posts/1189117404435352/react-native-for-android-how-we-built-the-first-cross-platform-react-native-app/), we have been improving list view scrolling performance, memory efficiency, UI responsiveness, and app startup time. Startup sets the first impression of an app and stresses all parts of the framework, so it is the most rewarding and challenging problem to tackle. - - - -> This is an excerpt. Read the rest of the post on [Facebook Code](https://code.facebook.com/posts/895897210527114/dive-into-react-native-performance/). diff --git a/blog/2016-04-13-react-native-a-year-in-review.md b/blog/2016-04-13-react-native-a-year-in-review.md deleted file mode 100644 index afa84f28c84b60..00000000000000 --- a/blog/2016-04-13-react-native-a-year-in-review.md +++ /dev/null @@ -1,20 +0,0 @@ ---- -title: React Native: A year in review -author: Martin Konicek -authorTitle: Software Engineer at Facebook -authorURL: https://github.com/mkonicek -authorImage: https://avatars1.githubusercontent.com/u/346214?v=3&s=460 -authorTwitter: martinkonicek -hero: /react-native/blog/img/big-hero.jpg -category: announcements ---- - -It's been one year since we open-sourced React Native. What started as an idea with a handful of engineers is now a framework being used by product teams across Facebook and beyond. Today at F8 we announced that Microsoft is bringing [React Native to the Windows ecosystem](https://microsoft.github.io/code-push/articles/ReactNativeWindows.html), giving developers the potential to build React Native on Windows PC, Phone, and Xbox. It will also provide open source tools and services such as a React Native extension for Visual Studio Code and CodePush to help developers create React Native apps on the Windows platform. In addition, [Samsung](https://www.tizen.org/blogs) is building React Native for its hybrid platform, which will empower developers to build apps for millions of SmartTVs and mobile and wearable devices. We also released the [Facebook SDK for React Native](https://github.com/facebook/react-native-fbsdk), which makes it easier for developers to incorporate Facebook social features like Login, Sharing, App Analytics, and Graph APIs into their apps. In one year, React Native has changed the way developers build on every major platform. - -It's been an epic ride — but we are only getting started. Here is a look back at how React Native has grown and evolved since we open-sourced it a year ago, some challenges we faced along the way, and what we expect as we look ahead to the future. - - - -> This is an excerpt. Read the rest of the post on [Facebook Code](https://code.facebook.com/posts/597378980427792/react-native-a-year-in-review/). diff --git a/blog/2016-07-06-toward-better-documentation.md b/blog/2016-07-06-toward-better-documentation.md deleted file mode 100644 index 0f3c0f704ff4f4..00000000000000 --- a/blog/2016-07-06-toward-better-documentation.md +++ /dev/null @@ -1,69 +0,0 @@ ---- -title: Toward Better Documentation -author: Kevin Lacker -authorTitle: Engineering Manager at Facebook -authorURL: https://twitter.com/lacker -authorImage: http://www.gravatar.com/avatar/9b790592be15d4f55a5ed7abb5103304?s=128 -authorTwitter: lacker -category: announcements ---- - -Part of having a great developer experience is having great documentation. A lot goes into creating good docs - the ideal documentation is concise, helpful, accurate, complete, and delightful. Recently we've been working hard to make the docs better based on your feedback, and we wanted to share some of the improvements we've made. - -## Inline Examples - -When you learn a new library, a new programming language, or a new framework, there's a beautiful moment when you first write a bit of code, try it out, see if it works... and it *does* work. You created something real. We wanted to put that visceral experience right into our docs. Like this: - -```ReactNativeWebPlayer -import React, { Component } from 'react'; -import { AppRegistry, Text, View } from 'react-native'; - -class ScratchPad extends Component { - render() { - return ( - - - Isn't this cool? - - - 👍 - - - ); - } -} - -AppRegistry.registerComponent('ScratchPad', () => ScratchPad); -``` - -We think these inline examples, using the [`react-native-web-player`](https://github.com/dabbott/react-native-web-player) module with help from [Devin Abbott](https://twitter.com/devinaabbott), are a great way to learn the basics of React Native, and we have updated our [tutorial for new React Native developers](/react-native/docs/tutorial.html) to use these wherever possible. Check it out - if you have ever been curious to see what would happen if you modified just one little bit of sample code, this is a really nice way to poke around. Also, if you're building developer tools and you want to show a live React Native sample on your own site, [`react-native-web-player`](https://github.com/dabbott/react-native-web-player) can make that straightforward. - -The core simulation engine is provided by [Nicolas Gallagher](https://twitter.com/necolas)'s [`react-native-web`](https://github.com/necolas/react-native-web) project, which provides a way to display React Native components like `Text` and `View` on the web. Check out [`react-native-web`](https://github.com/necolas/react-native-web) if you're interested in building mobile and web experiences that share a large chunk of the codebase. - -## Better Guides - -In some parts of React Native, there are multiple ways to do things, and we've heard feedback that we could provide better guidance. - -We have a new [guide to Navigation](/react-native/docs/navigator-comparison.html) that compares the different approaches and advises on what you should use - `Navigator`, `NavigatorIOS`, `NavigationExperimental`. In the medium term, we're working towards improving and consolidating those interfaces. In the short term, we hope that a better guide will make your life easier. - -We also have a new [guide to handling touches](/react-native/docs/handling-touches.html) that explains some of the basics of making button-like interfaces, and a brief summary of the different ways to handle touch events. - -Another area we worked on is Flexbox. This includes tutorials on how to [handle layout with Flexbox](/react-native/docs/flexbox.html) and how to control [the size of components](/react-native/docs/height-and-width.html). It also includes an unsexy but hopefully-useful [list of all the props that control layout in React Native](/react-native/docs/layout-props.html). - -## Getting Started - -When you start getting a React Native development environment set up on your machine, you do have to do a bunch of installing and configuring things. It's hard to make installation a really fun and exciting experience, but we can at least make it as quick and painless as possible. - -We built a [new Getting Started workflow](/react-native/releases/next/docs/getting-started.html) that lets you select your development operating system and your mobile operating system up front, to provide one concise place with all the setup instructions. We also went through the installation process to make sure everything worked and to make sure that every decision point had a clear recommendation. After testing it out on our innocent coworkers, we're pretty sure this is an improvement. - -We also worked on the [guide to integrating React Native into an existing app](/react-native/docs/integration-with-existing-apps.html). Many of the largest apps that use React Native, like the Facebook app itself, actually build part of the app in React Native, and part of it using regular development tools. We hope this guide makes it easier for more people to build apps this way. - -## We Need Your Help - -Your feedback lets us know what we should prioritize. I know some people will read this blog post and think "Better docs? Pffft. The documentation for X is still garbage!". That's great - we need that energy. The best way to give us feedback depends on the sort of feedback. - -If you find a mistake in the documentation, like inaccurate descriptions or code that doesn't actually work, [file an issue](https://github.com/facebook/react-native/issues). Tag it with "Documentation", so that it's easier to route it to the right people. - -If there isn't a specific mistake, but something in the documentation is fundamentally confusing, it's not a great fit for a GitHub issue. Instead, post on [Canny](https://react-native.canny.io/feature-requests) about the area of the docs that could use help. This helps us prioritize when we are doing more general work like guide-writing. - -Thanks for reading this far, and thanks for using React Native! diff --git a/blog/2016-08-12-react-native-meetup-san-francisco.md b/blog/2016-08-12-react-native-meetup-san-francisco.md deleted file mode 100644 index 0c36af6c47beda..00000000000000 --- a/blog/2016-08-12-react-native-meetup-san-francisco.md +++ /dev/null @@ -1,110 +0,0 @@ ---- -title: San Francisco Meetup Recap -author: Héctor Ramos -authorTitle: Developer Advocate at Facebook -authorURL: https://twitter.com/hectorramos -authorImage: https://s.gravatar.com/avatar/f2223874e66e884c99087e452501f2da?s=128 -authorTwitter: hectorramos -hero: /react-native/blog/img/rnmsf-august-2016-hero.jpg -category: events ---- - -Last week I had the opportunity to attend the [React Native Meetup](https://www.meetup.com/React-Native-San-Francisco/photos/27168649/#452793854) at Zynga’s San Francisco office. With around 200 people in attendance, it served as a great place to meet other developers near me that are also interested in React Native. - -I was particularly interested in learning more about how React and React Native are used at companies like Zynga, Netflix, and Airbnb. The agenda for the night would be as follows: - -* Rapid Prototyping in React -* Designing APIs for React Native -* Bridging the Gap: Using React Native in Existing Codebases - -But first, the event started off with a quick introduction and a brief recap of recent news: - -* Did you know that React Native is now the [top Java repository on GitHub](https://twitter.com/jamespearce/status/759637111880359937)? -* [rnpm](https://github.com/rnpm/rnpm) is now part of React Native core! You can now use `react-native link` in place of `rnpm link` to [install libraries with native dependencies](https://facebook.github.io/react-native/docs/linking-libraries-ios.html). -* The React Native Meetup community is growing fast! There are now over 4,800 developers across a variety of React Native meetup groups all over the globe. - -If [one of these meetups](https://www.meetup.com/find/?allMeetups=false&keywords=react+native&radius=Infinity&userFreeform=San+Francisco%2C+CA&mcId=z94105&mcName=San+Francisco%2C+CA&sort=recommended&eventFilter=mysugg) is held near you, I highly recommend attending! - -## Rapid Prototyping in React at Zynga - -The first round of news was followed by a quick introduction by Zynga, our hosts for the evening. Abhishek Chadha talked about how they use React to quickly prototype new experiences on mobile, demoing a quick prototype of a Draw Something-like app. They use a similar approach as React Native, providing access to native APIs via a bridge. This was demonstrated when Abhishek used the device's camera to snap a photo of the audience and then drew a hat on someone's head. - -## Designing APIs for React Native at Netflix - -Up next, the first featured talk of the evening. [Clarence Leung](https://twitter.com/clarler), Senior Software Engineer at Netflix, presented his talk on Designing APIs for React Native. First he noted the two main types of libraries one may work on: components such as tab bars and date pickers, and libraries that provide access to native services such as the camera roll or in-app payments. There are two ways one may approach when building a library for use in React Native: - -* Provide platform-specific components -* A cross-platform library with a similar API for both iOS and Android - -Each approach has its own considerations, and it’s up to you to determine what works best for your needs. - -**Approach #1** - -As an example of platform-specific components, Clarence talked about the DatePickerIOS and DatePickerAndroid from core React Native. On iOS, date pickers are rendered as part of the UI and can be easily embedded in an existing view, while date pickers on Android are presented modally. It makes sense to provide separate components in this case. - -**Approach #2** - -Photo pickers, on the other hand, are treated similarly on iOS and Android. There are some slight differences — Android does not group photos into folders like iOS does with Selfies, for example — but those are easily handled using `if` statements and the `Platform` component. - -Regardless of which approach you settle on, it’s a good idea to minimize the API surface and build app-specific libraries. For example, iOS’s In-App Purchase framework supports one-time, consumable purchases, as well as renewable subscriptions. If your app will only need to support consumable purchases, you may get away with dropping support for subscriptions in your cross-platform library. - -![](/react-native/blog/img/rnmsf-august-2016-netflix.jpg) - -There was a brief Q&A session at the end of Clarence’s talk. One of the interesting tid bits that came out of it was that around 80% of the React Native code written for these libraries at Netflix is shared across both iOS and Android. - -## Bridging the Gap, Using React Native in Existing Codebases - -The final talk of the night was by [Leland Richardson](https://twitter.com/intelligibabble) from Airbnb. The talk was focused on the use of React Native in existing codebases. I already know how easy it is to write a new app from scratch using React Native, so I was very interested to hear about Airbnb’s experience adopting React Native in their existing native apps. - -Leland started off by talking about greenfield apps versus brownfield apps. Greenfield means to start a project without the need to consider any prior work. This is in contrast to brownfield projects where you need to take into account the existing project’s requirements, development processes, and all of the teams various needs. - -When you’re working on a greenfield app, the React Native CLI sets up a single repository for both iOS and Android and everything just works. The first challenge against using React Native at Airbnb was the fact that the iOS and Android app each had their own repository. Multi-repo companies have some hurdles to get past before they can adopt React Native. - -To get around this, Airbnb first set up a new repo for the React Native codebase. They used their continuous integration servers to mirror the iOS and Android repos into this new repo. After tests are run and the bundle is built, the build artifacts are synced back to the iOS and Android repos. This allows the mobile engineers to work on native code without altering their development enviroment. Mobile engineers don't need to install npm, run the packager, or remember to build the JavaScript bundle. The engineers writing actual React Native code do not have to worry about syncing their code across iOS and Android, as they work on the React Native repository directly. - -This does come with some drawbacks, mainly they could not ship atomic updates. Changes that require a combination of native and JavaScript code would require three separate pull requests, all of which had to be carefully landed. In order to avoid conflicts, CI will fail to land changes back to the iOS and Android repos if master has changed since the build started. This would cause long delays during high commit frequency days (such as when new releases are cut). - -Airbnb has since moved to a mono repo approach. Fortunately this was already under consideration, and once the iOS and Android teams became comfortable with using React Native they were happy to accelerate the move towards the mono repo. - -This has solved most of the issues they had with the split repo approach. Leland did note that this does cause a higher strain on the version control servers, which may be an issue for smaller companies. - -![](/react-native/blog/img/rnmsf-august-2016-airbnb.jpg) - -### The Navigation Problem - -The second half of Leland's talk focused on a topic that is dear to me: the Navigation problem in React Native. He talked about the abundance of navigation libraries in React Native, both first party and third party. NavigationExperimental was mentioned as something that seemed promising, but ended up not being well suited for their use case. - -In fact, none of the existing navigation libraries seem to work well for brownfield apps. A brownfield app requires that the navigation state be fully owned by the native app. For example, if a user’s session expires while a React Native view is being presented, the native app should be able to take over and present a login screen as needed. - -Airbnb also wanted to avoid replacing native navigation bars with JavaScript versions as part of a transition, as the effect could be jarring. Initially they limited themselves to modally presented views, but this obviously presented a problem when it came to adopting React Native more widely within their apps. - -They decided that they needed their own library. The library is called `airbnb-navigation`. The library has not yet being open sourced as it is strongly tied to Airbnb’s codebase, but it is something they’d like to release by the end of the year. - -I won’t go into much detail into the library’s API, but here are some of the key takeaways: - -* One must preregister scenes ahead of time -* Each scene is displayed within its own `RCTRootView`. They are presented natively on each platform (e.g. `UINavigationController`s are used on iOS). -* The main `ScrollView` in a scene should be wrapped in a `ScrollScene` component. Doing so allows you to take advantage of native behaviors such as tapping on the status bar to scroll to the top on iOS. -* Transitions between scenes are handled natively, no need to worry about performance. -* The Android back button is automatically supported. -* They can take advantage of View Controller based navigation bar styling via a Navigator.Config UI-less component. - -There’s also some considerations to keep in mind: - -* The navigation bar is not easily customized in JavaScript, as it is a native component. This is intentional, as using native navigation bars is a hard requirement for this type of library. -* ScreenProps must be serialized/de-serialized whenever they're sent through the bridge, so care must be taken if sending too much data here. -* Navigation state is owned by the native app (also a hard requirement for the library), so things like Redux cannot manipulate navigation state. - -Leland's talk was also followed by a Q&A session. Overall, Airbnb is satisfied with React Native. They’re interested in using Code Push to fix any issues without going through the App Store, and their engineers love Live Reload, as they don't have to wait for the native app to be rebuilt after every minor change. - -## Closing Remarks - -The event ended with some additional React Native news: - -* Deco announced their [React Native Showcase](https://www.decosoftware.com/showcase), and invited everyone to add their app to the list. -* The recent [documentation overhaul](https://facebook.github.io/react-native/blog/2016/07/06/toward-better-documentation.html) got a shoutout! -* Devin Abbott, one of the creators of Deco IDE, will be teaching an introductory [React Native course](https://www.decosoftware.com/course). - -![](/react-native/blog/img/rnmsf-august-2016-docs.jpg) - -Meetups provide a good opportunity to meet and learn from other developers in the community. I'm looking forward to attending more React Native meetups in the future. If you make it up to one of these, please look out for me and let me know how we can make React Native work better for you! diff --git a/blog/2016-08-19-right-to-left-support-for-react-native-apps.md b/blog/2016-08-19-right-to-left-support-for-react-native-apps.md deleted file mode 100644 index a59970d54c016a..00000000000000 --- a/blog/2016-08-19-right-to-left-support-for-react-native-apps.md +++ /dev/null @@ -1,220 +0,0 @@ ---- -title: Right-to-Left Layout Support For React Native Apps -author: Mengjue (Mandy) Wang -authorTitle: Software Engineer Intern at Facebook -authorURL: https://github.com/MengjueW -authorImage: https://avatars0.githubusercontent.com/u/13987140?v=3&s=128 -category: engineering ---- -After launching an app to the app stores, internationalization is the next step to further your audience reach. Over 20 countries and numerous people around the world use Right-to-Left (RTL) languages. Thus, making your app support RTL for them is necessary. - -We're glad to announce that React Native has been improved to support RTL layouts. This is now available in the [react-native](https://github.com/facebook/react-native) master branch today, and will be available in the next RC: [`v0.33.0-rc`](https://github.com/facebook/react-native/releases). - -This involved changing [css-layout](https://github.com/facebook/css-layout), the core layout engine used by RN, and RN core implementation, as well as specific OSS JS components to support RTL. - -To battle test the RTL support in production, the latest version of the **Facebook Ads Manager** app (the first cross-platform 100% RN app) is now available in Arabic and Hebrew with RTL layouts for both [iOS](https://itunes.apple.com/app/id964397083) and [Android](https://play.google.com/store/apps/details?id=com.facebook.adsmanager). Here is how it looks like in those RTL languages: - -

- - -

- -## Overview Changes in RN for RTL support -[css-layout](https://github.com/facebook/css-layout) already has a concept of `start` and `end` for the layout. In the Left-to-Right (LTR) layout, `start` means `left`, and `end` means `right`. But in RTL, `start` means `right`, and `end` means `left`. This means we can make RN depend on the `start` and `end` calculation to compute the correct layout, which includes `position`, `padding`, and `margin`. - -In addition, [css-layout](https://github.com/facebook/css-layout) already makes each component's direction inherits from its parent. This means, we simply need to set the direction of the root component to RTL, and the entire app will flip. - -The diagram below describes the changes at high level: - -![](/react-native/blog/img/rtl-rn-core-updates.png) - -These include: - -* [css-layout RTL support for absolute positioning](https://github.com/facebook/css-layout/commit/46c842c71a1232c3c78c4215275d104a389a9a0f) -* mapping `left` and `right` to `start` and `end` in RN core implementation for shadow nodes -* and exposing a [bridged utility module](https://github.com/facebook/react-native/blob/f0fb228ec76ed49e6ed6d786d888e8113b8959a2/Libraries/Utilities/I18nManager.js) to help control the RTL layout - -With this update, when you allow RTL layout for your app: - -* every component layout will flip horizontally -* some gestures and animations will automatically have RTL layout, if you are using RTL-ready OSS components -* minimal additional effort may be needed to make your app fully RTL-ready - -## Making an App RTL-ready - -1. To support RTL, you should first add the RTL language bundles to your app. - * See the general guides from [iOS](https://developer.apple.com/library/ios/documentation/MacOSX/Conceptual/BPInternational/LocalizingYourApp/LocalizingYourApp.html#//apple_ref/doc/uid/10000171i-CH5-SW1) and [Android](https://developer.android.com/training/basics/supporting-devices/languages.html). - -2. Allow RTL layout for your app by calling the `allowRTL()` function at the beginning of native code. We provided this utility to only apply to an RTL layout when your app is ready. Here is an example: - - iOS: - ```objc - // in AppDelegate.m - [[RCTI18nUtil sharedInstance] allowRTL:YES]; - ``` - - Android: - ```java - // in MainActivity.java - I18nUtil sharedI18nUtilInstance = I18nUtil.getInstance(); - sharedI18nUtilInstance.allowRTL(context, true); - ``` - -3. For Android, you need add `android:supportsRtl="true"` to the [``](https://developer.android.com/guide/topics/manifest/application-element.html) element in `AndroidManifest.xml` file. - -Now, when you recompile your app and change the device language to an RTL language (e.g. Arabic or Hebrew), your app layout should change to RTL automatically. - -## Writing RTL-ready Components - -In general, most components are already RTL-ready, for example: - -* Left-to-Right Layout - -

- -

- -* Right-to-Left Layout - -

- -

- -However, there are several cases to be aware of, for which you will need the [`I18nManager`](https://github.com/facebook/react-native/blob/f0fb228ec76ed49e6ed6d786d888e8113b8959a2/Libraries/Utilities/I18nManager.js). In [`I18nManager`](https://github.com/facebook/react-native/blob/f0fb228ec76ed49e6ed6d786d888e8113b8959a2/Libraries/Utilities/I18nManager.js), there is a constant `isRTL` to tell if layout of app is RTL or not, so that you can make the necessary changes according to the layout. - -#### Icons with Directional Meaning -If your component has icons or images, they will be displayed the same way in LTR and RTL layout, because RN will not flip your source image. Therefore, you should flip them according to the layout style. - -* Left-to-Right Layout - -

- -

- -* Right-to-Left Layout - -

- -

- -Here are two ways to flip the icon according to the direction: - -* Adding a `transform` style to the image component: - ```js - - ``` - -* Or, changing the image source according to the direction: - ```js - let imageSource = require('./back.png'); - if (I18nManager.isRTL) { - imageSource = require('./forward.png'); - } - return ( - - ); - ``` - -#### Gestures and Animations - -In iOS and Android development, when you change to RTL layout, the gestures and animations are the opposite of LTR layout. Currently, in RN, gestures and animations are not supported on RN core code level, but on components level. The good news is, some of these components already support RTL today, such as [`SwipeableRow`](https://github.com/facebook/react-native/blob/38a6eec0db85a5204e85a9a92b4dee2db9641671/Libraries/Experimental/SwipeableRow/SwipeableRow.js) and [`NavigationExperimental`](https://github.com/facebook/react-native/tree/master/Libraries/NavigationExperimental). However, other components with gestures will need to support RTL manually. - -A good example to illustrate gesture RTL support is [`SwipeableRow`](https://github.com/facebook/react-native/blob/38a6eec0db85a5204e85a9a92b4dee2db9641671/Libraries/Experimental/SwipeableRow/SwipeableRow.js). - -

- - -

- - -##### Gestures Example -```js -// SwipeableRow.js -_isSwipingExcessivelyRightFromClosedPosition(gestureState: Object): boolean { - // ... - const gestureStateDx = IS_RTL ? -gestureState.dx : gestureState.dx; - return ( - this._isSwipingRightFromClosed(gestureState) && - gestureStateDx > RIGHT_SWIPE_THRESHOLD - ); -}, -``` - -##### Animation Example -```js -// SwipeableRow.js -_animateBounceBack(duration: number): void { - // ... - const swipeBounceBackDistance = IS_RTL ? - -RIGHT_SWIPE_BOUNCE_BACK_DISTANCE : - RIGHT_SWIPE_BOUNCE_BACK_DISTANCE; - this._animateTo( - -swipeBounceBackDistance, - duration, - this._animateToClosedPositionDuringBounce, - ); -}, -``` - - -## Maintaining Your RTL-ready App - -Even after the initial RTL-compatible app release, you will likely need to iterate on new features. To improve development efficiency, [`I18nManager`](https://github.com/facebook/react-native/blob/f0fb228ec76ed49e6ed6d786d888e8113b8959a2/Libraries/Utilities/I18nManager.js) provides the `forceRTL()` function for faster RTL testing without changing the test device language. You might want to provide a simple switch for this in your app. Here's an example from the RTL example in the RNTester: - -

- -

- -```js - - - - forceRTL - - - - - - - -_onDirectionChange = () => { - I18nManager.forceRTL(!this.state.isRTL); - this.setState({isRTL: !this.state.isRTL}); - Alert.alert('Reload this page', - 'Please reload this page to change the UI direction! ' + - 'All examples in this app will be affected. ' + - 'Check them out to see what they look like in RTL layout.' - ); -}; -``` - -When working on a new feature, you can easily toggle this button and reload the app to see RTL layout. The benefit is you won't need to change the language setting to test, however some text alignment won't change, as explained in the next section. Therefore, it's always a good idea to test your app in the RTL language before launching. - -## Limitations and Future Plan - -The RTL support should cover most of the UX in your app; however, there are some limitations for now: - -* Text alignment behaviors differ in iOS and Android - * In iOS, the default text alignment depends on the active language bundle, they are consistently on one side. In Android, the default text alignment depends on the language of the text content, i.e. English will be left-aligned and Arabic will be right-aligned. - * In theory, this should be made consistent across platform, but some people may prefer one behavior to another when using an app. More user experience research may be needed to find out the best practice for text alignment. - - -* There is no "true" left/right - - As discussed before, we map the `left`/`right` styles from the JS side to `start`/`end`, all `left` in code for RTL layout becomes "right" on screen, and `right` in code becomes "left" on screen. This is convenient because you don't need to change your product code too much, but it means there is no way to specify "true left" or "true right" in the code. In the future, allowing a component to control its direction regardless of the language may be necessary. - -* Make RTL support for gestures and animations more developer friendly - - Currently, there is still some programming effort required to make gestures and animations RTL compatible. - In the future, it would be ideal to find a way to make gestures and animations RTL support more developer friendly. - -## Try it Out! -Check out the [`RTLExample`](https://github.com/facebook/react-native/blob/master/RNTester/js/RTLExample.js) in the `RNTester` to understand more about RTL support, and let us know how it works for you! - -Finally, thank you for reading! We hope that the RTL support for React Native helps you grow your apps for international audience! diff --git a/blog/2016-09-08-exponent-talks-unraveling-navigation.md b/blog/2016-09-08-exponent-talks-unraveling-navigation.md deleted file mode 100644 index 2d66764bd42377..00000000000000 --- a/blog/2016-09-08-exponent-talks-unraveling-navigation.md +++ /dev/null @@ -1,12 +0,0 @@ ---- -title: Expo Talks: Adam on Unraveling Navigation -author: Héctor Ramos -authorTitle: Developer Advocate at Facebook -authorURL: https://twitter.com/hectorramos -authorImage: https://s.gravatar.com/avatar/f2223874e66e884c99087e452501f2da?s=128 -authorTwitter: hectorramos -youtubeVideoId: oeSjTxVkMhc -category: videos ---- - -[Adam Miskiewicz](https://twitter.com/skevy) from [Expo](https://expo.io/) talks about mobile navigation and the [`ex-navigation`](https://github.com/exponent/ex-navigation) React Native library at Expo's office hours last week. diff --git a/blog/2016-10-25-0.36-headless-js-the-keyboard-api-and-more.md b/blog/2016-10-25-0.36-headless-js-the-keyboard-api-and-more.md deleted file mode 100644 index 5f7480ed96015b..00000000000000 --- a/blog/2016-10-25-0.36-headless-js-the-keyboard-api-and-more.md +++ /dev/null @@ -1,86 +0,0 @@ ---- -title: 0.36: Headless JS, the Keyboard API, & more -author: Héctor Ramos -authorTitle: Developer Advocate at Facebook -authorURL: https://twitter.com/hectorramos -authorImage: https://s.gravatar.com/avatar/f2223874e66e884c99087e452501f2da?s=128 -authorTwitter: hectorramos -category: announcements ---- - -Today we are releasing [React Native 0.36](https://github.com/facebook/react-native/releases/tag/v0.36.0). Read on to learn more about what's new. - -## Headless JS - -Headless JS is a way to run tasks in JavaScript while your app is in the background. It can be used, for example, to sync fresh data, handle push notifications, or play music. It is only available on Android, for now. - -To get started, define your async task in a dedicated file (e.g. `SomeTaskName.js`): - -```javascript -module.exports = async (taskData) => { - // Perform your task here. -} -``` - -Next, register your task in on `AppRegistry`: - -```javascript -AppRegistry.registerHeadlessTask('SomeTaskName', () => require('SomeTaskName')); -``` - -Using Headless JS does require some native Java code to be written in order to allow you to start up the service when needed. Take a look at our new [Headless JS docs](/react-native/docs/headless-js-android.html) to learn more! - -## The Keyboard API - -Working with the on-screen keyboard is now easier with [`Keyboard`](/react-native/docs/keyboard.html). You can now listen for native keyboard events and react to them. For example, to dismiss the active keyboard, simply call `Keyboard.dismiss()`: - -```js -import { Keyboard } from 'react-native' - -// Hide that keyboard! -Keyboard.dismiss() -``` - -## Animated Division - -Combining two animated values via addition, multiplication, and modulo are already supported by React Native. With version 0.36, combining two [animated values via division](/react-native/docs/animated.html#divide) is now possible. There are some cases where an animated value needs to invert another animated value for calculation. An example is inverting a scale (2x --> 0.5x): - -``` -const a = Animated.Value(1); -const b = Animated.divide(1, a); - -Animated.spring(a, { - toValue: 2, -}).start(); -``` - -`b` will then follow `a`'s spring animation and produce the value of `1 / a`. - -The basic usage is like this: - -``` - - - -``` - -In this example, the inner image won't get stretched at all because the parent's scaling gets cancelled out. If you'd like to learn more, check out the [Animations guide](/react-native/docs/animations.html). - -## Dark Status Bars - -A new `barStyle` value has been added to `StatusBar`: `dark-content`. With this addition, you can now use [`barStyle`](/react-native/docs/statusbar.html#barstyle) on both iOS and Android. The behavior will now be the following: - -- `default`: Use the platform default (light on iOS, dark on Android). -- `light-content`: Use a light status bar with black text and icons. -- `dark-content`: Use a dark status bar with white text and icons. - -## ...and more - -The above is just a sample of what has changed in 0.36. Check out the [release notes on GitHub](https://github.com/facebook/react-native/releases/tag/v0.36.0) to see the full list of new features, bug fixes, and breaking changes. - -You can upgrade to 0.36 by running the following commands in a terminal: - -```bash -$ npm install --save react-native@0.36 -$ react-native upgrade -``` diff --git a/blog/2016-11-08-introducing-button-yarn-and-a-public-roadmap.md b/blog/2016-11-08-introducing-button-yarn-and-a-public-roadmap.md deleted file mode 100644 index a156e1900e7c75..00000000000000 --- a/blog/2016-11-08-introducing-button-yarn-and-a-public-roadmap.md +++ /dev/null @@ -1,58 +0,0 @@ ---- -title: Introducing Button, Faster Installs with Yarn, and a Public Roadmap -author: Héctor Ramos -authorTitle: Developer Advocate at Facebook -authorURL: https://twitter.com/hectorramos -authorImage: https://s.gravatar.com/avatar/f2223874e66e884c99087e452501f2da?s=128 -authorTwitter: hectorramos -category: announcements ---- - -We have heard from many people that there is so much work happening with React Native, it can be tough to keep track of what's going on. To help communicate what work is in progress, we are now publishing a [roadmap for React Native](https://github.com/facebook/react-native/wiki/Roadmap). At a high level, this work can be broken down into three priorities: - -- **Core Libraries**. Adding more functionality to the most useful components and APIs. -- **Stability**. Improve the underlying infrastructure to reduce bugs and improve code quality. -- **Developer Experience**. Help React Native developers move faster - -If you have suggestions for features that you think would be valuable on the roadmap, check out [Canny](https://react-native.canny.io/feature-requests), where you can suggest new features and discuss existing proposals. - -## What's new in React Native - -[Version 0.37 of React Native](https://github.com/facebook/react-native/releases/tag/v0.37.0), released today, introduces a new core component to make it really easy to add a touchable Button to any app. We're also introducing support for the new [Yarn](https://yarnpkg.com/) package manager, which should speed up the whole process of updating your app's dependencies. - -## Introducing Button - -Today we're introducing a basic `