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 ...
Get Learning React Native now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.