O'Reilly logo

Learning React Native by Bonnie Eisenman

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 7. Modules

In Chapter 6, we looked at some of the APIs that React Native exposes for interacting with the host platform. Things like the camera roll and geolocation are platform-specific, but React Native exposes interfaces for them for our convenience. Because support for those APIs is built into React Native, they’re quite easy to use.

What happens when we want to use an API that isn’t supported by React Native? In this chapter, we’ll look at how to install modules written by members of the React Native community using npm. We’ll also take a closer look at one such module for iOS, react-native-video, and learn how the RCTBridgeModule can allow you to add JavaScript interfaces to existing Objective-C APIs. We’ll also look at importing pure JavaScript libraries into your project, and how to manage dependencies.

While we’ll be looking at some Objective-C and Java code this chapter, don’t be alarmed! We’ll be taking it slowly. A full introduction to mobile development for iOS and Android is beyond the scope of this book, but we’ll walk through some examples together.

Installing JavaScript Libraries with npm

Before we discuss how native modules work, first we should cover how to install external dependenies in general. React Native uses npm to manage dependencies. npm is the package manager for Node.js, but the npm registry includes packages for all sorts of JavaScript projects, not just Node. npm uses a file called package.json to store metadata about your project, including ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required