Skip to Content
Learning React Native
book

Learning React Native

by Bonnie Eisenman
December 2015
Beginner
200 pages
5h 48m
English
O'Reilly Media, Inc.
Content preview from Learning React Native

Chapter 6. Platform APIs

When building mobile applications, you will naturally want to take advantage of the host platform’s specific APIs. React Native makes it easy to access things like the phone’s camera roll, location, and persistent storage. These platform APIs are made available to React Native through included modules, which provide us with easy-to-use asynchronous JavaScript interfaces to these functions.

React Native does not wrap all of its host platform’s functionality by default; some platform APIs will require you to either write your own modules, or use modules written by others in the React Native community. We will cover that process in Chapter 7. The docs are the best place to check if an API is supported.

This chapter covers some of the available platform APIs. For our example, we’ll make some modifications to the Weather application from earlier. We’ll add geolocation to the app, so that it detects the user’s location automatically. We will also add “memory” to the app, so it will remember your previously searched locations. Finally, we’ll use the camera roll to change the background image to one of the user’s photos.

While relevant code snippets will be presented in each section, the full code for the application is included in “The SmarterWeather Application”.

iOS and Android Compatibility

Cross-platform support for these APIs is a work in progress, so while AsyncStorage is supported on both iOS and Android, geolocation and the camera roll are currently iOS-only. ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Learning React Native, 2nd Edition

Learning React Native, 2nd Edition

Bonnie Eisenman
React and React Native - Fourth Edition

React and React Native - Fourth Edition

Adam Boduch, Roy Derks, Mikhail Sakhniuk
Learning React

Learning React

Kirupa Chinnathambi

Publisher Resources

ISBN: 9781491929049Errata PageSupplemental Content