Learning React Native Building Native Mobile Apps with JavaScript 2nd Edition Bonnie Eisenman download https://textbookfull.com/product/learning-react-native-building- native-mobile-apps-with-javascript-2nd-edition-bonnie-eisenman/ Download more ebook from https://textbookfull.com
We believe these products will be a great fit for you. Click the link to download now, or visit textbookfull.com to discover even more! Fullstack React Native Create beautiful mobile apps with JavaScript and React Native 5th Edition Devin Abbott https://textbookfull.com/product/fullstack-react-native-create- beautiful-mobile-apps-with-javascript-and-react-native-5th- edition-devin-abbott/ React Native in Action Developing iOS and Android apps with JavaScript 1st Edition Nader Dabit https://textbookfull.com/product/react-native-in-action- developing-ios-and-android-apps-with-javascript-1st-edition- nader-dabit/ React Native in Action Developing iOS and Android apps with JavaScript 1st Edition Nader Dabit https://textbookfull.com/product/react-native-in-action- developing-ios-and-android-apps-with-javascript-1st-edition- nader-dabit-2/ Building Hybrid Android Apps with Java and JavaScript Applying Native Device APIs Japplying Native Device Apis 1st Edition Gok Nizamettin Khanna Nitin https://textbookfull.com/product/building-hybrid-android-apps- with-java-and-javascript-applying-native-device-apis-japplying- native-device-apis-1st-edition-gok-nizamettin-khanna-nitin/
Progressive Web Apps with React Create Lightning Fast Web Apps With Native Power Using React and Firebase 1st Edition Scott Domes https://textbookfull.com/product/progressive-web-apps-with-react- create-lightning-fast-web-apps-with-native-power-using-react-and- firebase-1st-edition-scott-domes/ Cross-platform Localization for Native Mobile Apps with Xamarin 1st Edition Christopher Miller https://textbookfull.com/product/cross-platform-localization-for- native-mobile-apps-with-xamarin-1st-edition-christopher-miller/ Practical React Native: Build Two Full Projects and One Full Game using React Native 1st Edition Frank Zammetti https://textbookfull.com/product/practical-react-native-build- two-full-projects-and-one-full-game-using-react-native-1st- edition-frank-zammetti/ Learning React Modern Patterns for Developing React Apps 2nd Edition Alex Banks https://textbookfull.com/product/learning-react-modern-patterns- for-developing-react-apps-2nd-edition-alex-banks/ Building Progressive Web Apps Bringing the Power of Native to the Browser 1st Edition Tal Ater https://textbookfull.com/product/building-progressive-web-apps- bringing-the-power-of-native-to-the-browser-1st-edition-tal-ater/
Bonnie Eisenman Learning React Native BUILDING NATIVE MOBILE APPS WITH JAVASCRIPT Learning React Native 2 n d E d i t i o n
Bonnie Eisenman Learning React Native Building Native Mobile Apps with JavaScript SECOND EDITION Boston Farnham Sebastopol Tokyo Beijing Boston Farnham Sebastopol Tokyo Beijing
978-1-491-98914-2 [LSI] Learning React Native by Bonnie Eisenman Copyright © 2018 Bonnie Eisenman. All rights reserved. Printed in the United States of America. Published by O’Reilly Media, Inc., 1005 Gravenstein Highway North, Sebastopol, CA 95472. O’Reilly books may be purchased for educational, business, or sales promotional use. Online editions are also available for most titles (http://oreilly.com/safari). For more information, contact our corporate/insti‐ tutional sales department: 800-998-9938 or corporate@oreilly.com. Editor: Meg Foley Production Editor: Nicholas Adams Copyeditor: Rachel Monaghan Proofreader: Gillian McGarvey Indexer: Judith McConville Interior Designer: David Futato Cover Designer: Karen Montgomery Illustrator: Rebecca Demarest December 2015: First Edition November 2017: Second Edition Revision History for the Second Edition 2017-10-23: First Release See http://oreilly.com/catalog/errata.csp?isbn=9781491989142 for release details. The O’Reilly logo is a registered trademark of O’Reilly Media, Inc. Learning React Native, the cover image, and related trade dress are trademarks of O’Reilly Media, Inc. While the publisher and the author have used good faith efforts to ensure that the information and instructions contained in this work are accurate, the publisher and the author disclaim all responsibility for errors or omissions, including without limitation responsibility for damages resulting from the use of or reliance on this work. Use of the information and instructions contained in this work is at your own risk. If any code samples or other technology this work contains or describes is subject to open source licenses or the intellectual property rights of others, it is your responsibility to ensure that your use thereof complies with such licenses and/or rights.
Table of Contents Preface. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ix 1. What Is React Native?. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 Advantages of React Native 2 Developer Experience 2 Code Reuse and Knowledge Sharing 3 Risks and Drawbacks 4 Summary 4 2. Working with React Native. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 How Does React Native Work? 5 Rendering Lifecycle 7 Creating Components in React Native 8 Working with Views 8 Using JSX 9 Styling Native Components 10 Host Platform APIs 11 Summary 12 3. Building Your First Application. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 Setting Up Your Environment 13 Developer Setup: Create React Native App 14 Creating Your First Application with create-react-native-app 14 Previewing Your App on iOS or Android 15 Developer Setup: The Traditional Approach 16 Creating Your First Application with react-native 16 Running Your App on iOS 17 Running Your App on Android 18 iii
Exploring the Sample Code 19 Building a Weather App 22 Handling User Input 24 Displaying Data 26 Fetching Data from the Web 29 Adding a Background Image 32 Putting It All Together 34 Summary 36 4. Components for Mobile. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39 Analogies Between HTML Elements and Native Components 39 The <Text> Component 40 The <Image> Component 42 Working with Touch and Gestures 44 Creating Basic Interactions with <Button> 44 Using the <TouchableHighlight> Component 45 Using the PanResponder Class 48 Working with Lists 54 Using the Basic <FlatList> Component 56 Updating the <FlatList> Contents 59 Integrating Real Data 63 Working with <SectionList> 65 Navigation 69 Other Organizational Components 70 Summary 71 5. Styles. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73 Declaring and Manipulating Styles 73 Using Inline Styles 74 Styling with Objects 75 Using StyleSheet.create 75 Concatenating Styles 76 Organization and Inheritance 77 Exporting Style Objects 77 Passing Styles as Props 78 Reusing and Sharing Styles 79 Positioning and Designing Layouts 80 Using Layouts with Flexbox 80 Using Absolute Positioning 84 Putting It Together 85 Summary 88 iv | Table of Contents
6. Platform APIs. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91 Using Geolocation 91 Reading the User’s Location 92 Handling Permissions 93 Testing Geolocation in Emulated Devices 94 Watching the User’s Location 95 Working Around Limitations 95 Updating the Weather Application 96 Accessing the User’s Images and Camera 98 Interacting with the CameraRoll Module 99 Requesting Images with GetPhotoParams 100 Rendering an Image from the Camera Roll 101 Uploading an Image to a Server 102 Storing Persistent Data with AsyncStorage 103 The SmarterWeather Application 104 The <WeatherProject> Component 104 The <Forecast> Component 107 The <Button> Component 108 The <LocationButton> Component 109 The <PhotoBackdrop> Component 110 Summary 112 7. Modules and Native Code. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113 Installing JavaScript Libraries with npm 113 Installing Third-Party Components with Native Code 115 Using the Video Component 116 Objective-C Native Modules 116 Writing an Objective-C Native Module for iOS 116 Exploring react-native-video for iOS 121 Java Native Modules 124 Writing a Java Native Module for Android 124 Exploring react-native-video for Java 127 Cross-Platform Native Modules 130 Summary 130 8. Platform-Specific Code. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133 iOS- or Android-Only Components 133 Components with Platform-Specific Implementations 134 Using Platform-Specific File Extensions 134 Using the Platform Module 137 When to Use Platform-Specific Components 137 Table of Contents | v
9. Debugging and Developer Tools. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139 JavaScript Debugging Practices, Translated 139 Activating the Developer Options 139 Debugging with console.log 141 Using the JavaScript Debugger 143 Working with the React Developer Tools 144 React Native Debugging Tools 145 Using Inspect Element 145 Interpreting the Red Screen of Death 146 Debugging Beyond JavaScript 150 Common Development Environment Issues 151 Common Xcode Problems 151 Common Android Problems 152 The React Native Packager 153 Issues Deploying to an iOS Device 153 Simulator Behavior 155 Testing Your Code 155 Type Checking with Flow 156 Unit Testing with Jest 156 Snapshot Testing with Jest 157 When You’re Stuck 160 Summary 161 10. Navigation and Structure in Larger Applications. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 163 The Flashcard Application 163 Project Structure 166 Application Screens 167 Reusable Components 173 Styles 177 Data Models 178 Using React-Navigation 181 Creating a StackNavigator 182 Using navigation.navigate to Transition Between Screens 182 Configuring the Header with navigationOptions 185 Implementing the Rest 186 Summary 187 11. State Management in Larger Applications. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 189 Using Redux to Manage State 189 Actions 190 Reducers 192 Connecting Redux 195 vi | Table of Contents
Persisting Data with AsyncStorage 203 Summary and Homework 206 Conclusion. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 207 A. Modern JavaScript Syntax. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 209 B. Deploying Your Application. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 215 C. Working with Expo Applications. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 219 Index. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 221 Table of Contents | vii
Preface This book is an introduction to React Native, Facebook’s JavaScript framework for building mobile applications. Using your existing knowledge of JavaScript and React, you’ll be able to build and deploy fully featured mobile applications for both iOS and Android that truly render natively. There are plenty of advantages to working with React Native over traditional means of mobile development without needing to sacri‐ fice the native look and feel. We’ll start with the basics and work our way up to creating a full-fledged application with 100% code reuse between iOS and Android. In addition to the essentials of the framework, we’ll discuss how to work beyond it, including how to make use of third- party libraries and even how to write your own Java or Objective-C libraries to extend React Native. If you’re coming to mobile development from the perspective of a frontend software engineer or web developer, this is the book for you. React Native is a pretty amazing thing, and I hope you’re as excited to explore it as I am! Prerequisites This book is not an introduction to React, in general. We’ll assume that you have some working knowledge of React. If you’re brand new to React, I suggest reading through a tutorial or two before coming back to take the plunge into mobile develop‐ ment. Specifically, you should be familiar with the role of props and state, the com‐ ponent lifecycle, and how to create React components. We’ll also be using some modern JavaScript syntax, as well as JSX. If you aren’t famil‐ iar with these, don’t worry; we’ll cover JSX in Chapter 2, and modern JavaScript syn‐ tax in Appendix A. These features are essentially 1:1 translations of the JavaScript code you’re already accustomed to writing. This book focuses on using React Native to write iOS and Android applications, though React Native can also be used to write applications targeting Ubuntu, ix
Windows, and macOS. Linux and Windows users can use React Native to develop Android applications, but in order to write iOS applications, you will need to develop on macOS. Conventions Used in This Book The following typographical conventions are used in this book: Italic Indicates new terms, URLs, email addresses, filenames, and file extensions. Constant width Used for program listings, as well as within paragraphs to refer to program ele‐ ments such as variable or function names, databases, data types, environment variables, statements, and keywords. Constant width bold Shows commands or other text that should be typed literally by the user. Constant width italic Shows text that should be replaced with user-supplied values or by values deter‐ mined by context. This element signifies a tip or suggestion. This element signifies a general note. This element indicates a warning or caution. x | Preface
Using Code Examples Supplemental material (code examples, exercises, etc.) is available for download at https://github.com/bonniee/learning-react-native. This book is here to help you get your job done. In general, if example code is offered with this book, you may use it in your programs and documentation. You do not need to contact us for permission unless you’re reproducing a significant portion of the code. For example, writing a program that uses several chunks of code from this book does not require permission. Selling or distributing a CD-ROM of examples from O’Reilly books does require permission. Answering a question by citing this book and quoting example code does not require permission. Incorporating a signifi‐ cant amount of example code from this book into your product’s documentation does require permission. We appreciate, but do not require, attribution. An attribution usually includes the title, author, publisher, and ISBN. For example: “Learning React Native, Second Edi‐ tion, by Bonnie Eisenman (O’Reilly). Copyright 2018 Bonnie Eisenman, 978-1-491-98914-2.” If you feel your use of code examples falls outside fair use or the permission given above, feel free to contact us at permissions@oreilly.com. O’Reilly Safari Safari (formerly Safari Books Online) is a membership-based training and reference platform for enterprise, government, educators, and individuals. Members have access to thousands of books, training videos, Learning Paths, interac‐ tive tutorials, and curated playlists from over 250 publishers, including O’Reilly Media, Harvard Business Review, Prentice Hall Professional, Addison-Wesley Profes‐ sional, Microsoft Press, Sams, Que, Peachpit Press, Adobe, Focal Press, Cisco Press, John Wiley & Sons, Syngress, Morgan Kaufmann, IBM Redbooks, Packt, Adobe Press, FT Press, Apress, Manning, New Riders, McGraw-Hill, Jones & Bartlett, and Course Technology, among others. For more information, please visit http://oreilly.com/safari. Preface | xi
How to Contact Us Please address comments and questions concerning this book to the publisher: O’Reilly Media, Inc. 1005 Gravenstein Highway North Sebastopol, CA 95472 800-998-9938 (in the United States or Canada) 707-829-0515 (international or local) 707-829-0104 (fax) We have a web page for this book, where we list errata, examples, and any additional information. You can access this page at http://bit.ly/learning-react-native-2e. To comment or ask technical questions about this book, send email to bookques‐ tions@oreilly.com. For more information about our books, courses, conferences, and news, see our web‐ site at http://www.oreilly.com. Find us on Facebook: http://facebook.com/oreilly Follow us on Twitter: http://twitter.com/oreillymedia Watch us on YouTube: http://www.youtube.com/oreillymedia Resources It’s dangerous to go alone! Well, not really, but that doesn’t mean you have to. Here are some resources you may find useful as you work through the book: • The GitHub repository for this book contains all of the code samples we’ll be dis‐ cussing. If you get stumped or want more context, try looking here first. • Join the mailing list at LearningReactNative.com for follow-up articles, sugges‐ tions, and helpful resources. • The official documentation has a lot of good reference material. Additionally, the React Native community is a useful resource: • The react-native tag on Stack Overflow • The Reactiflux chat group includes many core contributors and other helpful folks • #reactnative (irc.lc/freenode/reactnative) on Freenode xii | Preface
Acknowledgments As is traditional: this book would not have been possible without the help and sup‐ port of many others. Thank you to my editor, Meg Foley, and the rest of the O’Reilly team for bringing this project into the world. Thank you also to my technical review‐ ers for your time and insightful feedback: Ryan Hurley, Dave Benjamin, David Bieber, Jason Brown, Erica Portnoy, and Jonathan Stark. I would also like to thank the React Native team, without whose stellar work this book would naturally be impossible. Thanks also to Zachary Elliott for his help with the Flashcard application, Android testing, and support throughout. Mi estas dankplena pro via subteno. And many thanks are owed to my dear friends and family, who put up with me throughout this process and provided moral support, guidance, and distraction as the situation required. Thank you. Preface | xiii
CHAPTER 1 What Is React Native? React Native is a JavaScript framework for writing real, natively rendering mobile applications for iOS and Android. It’s based on React, Facebook’s JavaScript library for building user interfaces, but instead of targeting the browser, it targets mobile platforms. In other words, it enables web developers to write mobile applications that look and feel truly “native,” all from the comfort of a familiar JavaScript library. Plus, because most of the code you write can be shared between platforms, React Native makes it easy to simultaneously develop for both Android and iOS. Similar to React for the web, React Native applications are written with a mixture of JavaScript and XML-esque markup, known as JSX. Then, under the hood, the React Native “bridge” invokes the native rendering APIs in Objective-C (for iOS) or Java (for Android). Thus, your application will render using real mobile UI components, not webviews, and will look and feel like any other mobile application. React Native also exposes JavaScript interfaces for platform APIs, so your React Native apps can access platform features like the phone camera or the user’s location. The core React Native project supports writing mobile applications for both iOS and Android. Community implementations also provide support for Windows, Ubuntu, the web, and more. In this book, we’ll build both Android and iOS apps with React Native. The vast majority of the code we write will be cross-platform. And, yes, you can really use React Native to build production-ready mobile applica‐ tions. Some anecdata: Facebook, Airbnb, Walmart, and Baidu are already using it in production for user-facing applications. 1
Advantages of React Native The fact that React Native renders using its host platform’s standard rendering APIs distinguishes it from most existing methods of cross-platform application develop‐ ment, like Cordova or Ionic. Existing methods of writing mobile applications use combinations of JavaScript, HTML, and CSS and typically render using webviews. While this approach can work, it also comes with drawbacks, especially around per‐ formance. Additionally, these methods do not usually have access to the host plat‐ form’s set of native UI elements. When these frameworks do try to mimic native UI elements, the results usually feel just a little off. In addition, reverse-engineering all the fine details of things like animations takes an enormous amount of effort, and they can quickly become outdated. In contrast, React Native actually translates your markup to real, native UI elements, leveraging existing means of rendering views on whatever platform you are working with. Additionally, React works separately from the main UI thread, so your applica‐ tion can maintain high performance without sacrificing capability. The update cycle in React Native is the same as in React: when props or state change, React Native re- renders the views. The major difference between React Native and React in the browser is that React Native does this by leveraging the UI libraries of its host plat‐ form, rather than using HTML and CSS markup. For developers accustomed to working on the web with React, this means you can write mobile apps with the performance and look and feel of a native application, while using familiar tools. React Native also represents an improvement over normal mobile development in two other areas: developer experience and cross-platform development potential. Developer Experience If you’ve developed for mobile before, you might be surprised by how easy React Native is to work with. The React Native team has baked strong developer tools and meaningful error messages into the framework so that working with robust tools is a natural part of your development experience. For instance, because React Native is “just” JavaScript, you don’t need to rebuild your application in order to see your changes reflected; instead, you can refresh your appli‐ cation just as you would any other web page. All of those minutes spent waiting for your application to build can really add up, and in contrast React Native’s quick itera‐ tion cycle feels like a godsend. Additionally, React Native lets you take advantage of intelligent debugging tools and error reporting. If you are comfortable with Chrome or Safari’s developer tools (Figure 1-1), you will be happy to know that you can use them for mobile develop‐ ment as well. Likewise, you can use whatever text editor you prefer for JavaScript 2 | Chapter 1: What Is React Native?
editing. React Native does not force you to work in Xcode to develop for iOS or in Android Studio for Android development. Figure 1-1. Using the Chrome Debugger with React Native Besides the day-to-day improvements to your development experience, React Native also has the potential to positively impact your product release cycle. For instance, Apple and Google both permit you to load JavaScript-only changes to an app’s behav‐ ior without going through the standard review process. This is particularly nice on iOS, where application updates typically require several days or weeks of review. All of these small perks add up to saving you and your fellow developers time and energy, allowing you to focus on the more interesting parts of your work and be more productive overall. Code Reuse and Knowledge Sharing Working with React Native can dramatically shrink the resources required to build mobile applications. Any developer who knows how to write React code can target the web, iOS, and Android, all with the same skill set. By removing the need to “silo” developers based on their target platform, React Native lets your team iterate more quickly and share knowledge and resources more effectively. Not only can you share knowledge, but much of your code can be shared, too. Not all the code you write will be cross-platform, and depending on the functionality you Advantages of React Native | 3
need on a specific platform, you may occasionally need to dip into Objective-C or Java (we’ll cover how so-called native modules work in Chapter 7). But reusing code across platforms is surprisingly easy with React Native. For example, the Facebook Ads Manager application for Android shares 87% of its codebase with the iOS ver‐ sion. The final application we’ll look at in this book, a flashcard app, has total code reuse between Android and iOS. It’s hard to beat that! Risks and Drawbacks As with anything, using React Native is not without its downsides, and whether or not it is a good fit for your team really depends on your individual situation. Because React Native introduces another layer to your project, it can make debugging hairier, especially at the intersection of React and the host platform. We’ll cover debugging for React Native in more depth in Chapter 9 and try to address some of the most common issues. Along the same lines, when updates are released for the host platform—say, a new suite of APIs in a new version of Android—there will be a lag before they are fully supported in React Native. The good news is that in the vast majority of cases, you can implement support for missing APIs yourself, which we’ll cover in Chapter 7. Also, if you do hit a roadblock, you won’t be locked in to using React Native—many companies have successfully implemented hybrid approaches to app development. Changing the platform you use to write your applications is a big choice. Still, I think you’ll see that the benefits of React Native outweigh the risks. Summary React Native is an exciting framework that enables web developers to create robust mobile applications using their existing JavaScript knowledge. It offers faster mobile development and more efficient code sharing across iOS, Android, and the web without sacrificing the end user’s experience or application quality. The tradeoff is that it adds some complexity to your application setup. If your team can handle that and wants to develop mobile applications for more than just one platform, you should be looking at React Native. In the next chapter, we go over some of the main ways in which React Native differs from React for the web, and cover some key concepts. If you’d like to skip straight to developing, feel free to jump to Chapter 3, in which we set up our development envi‐ ronment and write our very first React Native application. 4 | Chapter 1: What Is React Native?
CHAPTER 2 Working with React Native In this chapter, we’ll cover the bridge, and review how React Native works under the hood. Then, we’ll look at how React Native components differ from their web coun‐ terparts, and cover what you’ll need to know in order to create and style components for mobile. If you’d prefer to dig into the development process and see React Native in action, feel free to jump ahead to Chapter 3. How Does React Native Work? The idea of writing mobile applications in JavaScript feels a little odd. How is it possi‐ ble to use React in a mobile environment? In order to understand the technical underpinnings of React Native, we first need to recall one of React’s concepts: the Vir‐ tual DOM. In React, the Virtual DOM acts as a layer between the developer’s description of how things ought to look and the work done to actually render your application onto the page. To render interactive user interfaces in a browser, developers must edit the browser’s DOM, or Document Object Model. This is an expensive step, and excessive writes to the DOM have a significant impact on performance. Rather than directly render changes on the page, React computes the necessary changes in-memory and rerenders the minimal amount necessary. Figure 2-1 shows how this works. 5
Figure 2-1. Performing calculations in the Virtual DOM limits rerendering in the brows‐ er’s DOM In the context of React on the web, most developers think of the Virtual DOM as a performance optimization. The Virtual DOM certainly has performance benefits, but its real potential lies in the power of its abstraction. Placing a clean abstraction layer between the developer’s code and the actual rendering opens up a lot of interesting possibilities. What if React could render to a target other than the browser’s DOM? After all, React already “understands” what your application is supposed to look like. Indeed, this is how React Native works, as shown in Figure 2-2. Instead of rendering to the browser’s DOM, React Native invokes Objective-C APIs to render to iOS com‐ ponents, or Java APIs to render to Android components. This sets React Native apart from other cross-platform app development options, which often end up rendering web-based views. Figure 2-2. React can render to different targets 6 | Chapter 2: Working with React Native
This is all possible because of the bridge, which provides React with an interface into the host platform’s native UI elements. React components return markup from their render function, which describes how they should look. With React for the web, this translates directly to the browser’s DOM. For React Native, this markup is translated to suit the host platform, so a <View> might become an iOS-specific UIView. The core React Native project supports iOS and Android. Because of the abstraction layer provided by the Virtual DOM, React Native can target other platforms, too— someone just needs to write the bridge. For example, there are community imple‐ mentations of React Native for Windows and Ubuntu, so you can also use React Native to create desktop applications. Rendering Lifecycle If you are accustomed to working in React, the React lifecycle should be familiar to you. When React runs in the browser, the render lifecycle begins by mounting your React components (Figure 2-3). Figure 2-3. Mounting components in React After that, React handles the rendering and rerendering of your component as neces‐ sary (Figure 2-4). Figure 2-4. Rerendering components in React For the render stage, the developer returns HTML markup from a React component’s render method, which React then renders directly into the page as necessary. For React Native, the lifecycle is the same, but the rendering process is slightly differ‐ ent because React Native depends on the bridge. We looked at the bridge briefly in Figure 2-2. The bridge translates JavaScript calls and invokes the host platform’s underlying APIs and UI elements (i.e., in Objective-C or Java, as appropriate). Because React Native doesn’t run on the main UI thread, it can perform these asyn‐ chronous calls without impacting the user’s experience. Rendering Lifecycle | 7
Creating Components in React Native All React code lives in React components. React Native components are largely the same as ordinary React components, with some important differences around ren‐ dering and styling. Working with Views When writing in React for the web, you render normal HTML elements (<div>, <p>, <span>, <a>, etc.). With React Native, all of these elements are replaced by platform- specific React components (see Table 2-1). The most basic is the cross-platform <View>, a simple and flexible UI element that can be thought of as analogous to the <div>. On iOS, for instance, the <View> component renders to a UIView, whereas on Android it renders to a View. Table 2-1. Basic React elements for the web compared with React Native React React Native <div> <View> <span> <Text> <li>, <ul> <FlastList>, child items <img> <Image> Other components are platform-specific. For instance, the <DatePickerIOS> compo‐ nent (predictably) renders the iOS standard date picker (Figure 2-5). Here is an excerpt from the RNTester sample app, demonstrating an iOS date picker. The usage is straightforward, as you would expect: <DatePickerIOS date={this.state.date} mode="time" /> Figure 2-5. The <DatePickerIOS> component is, as the name suggests, iOS-specific 8 | Chapter 2: Working with React Native
Because all of our UI elements are now React components rather than basic HTML elements like the <div>, you will need to explicitly import each component you want to use. For instance, we need to import the <DatePickerIOS> component like so: import { DatePickerIOS } from "react-native"; The RNTester application, which is bundled into the React Native GitHub project, allows you to view all of the supported UI elements. I encourage you to examine the various elements included in the RNTester app. It also demonstrates many styling options and interactions. Platform-specific components and APIs have special tags in the documentation, and typically use the platform name as a suffix —for example, <TabBarIOS> and <ToolbarAndroid>. Because these components vary from platform to platform, how you structure your React components becomes even more important when you’re working in React Native. In React for the web, we often have a mix of React components: some manage logic and their child components, while others render raw markup. If you want to reuse code when working in React Native, maintaining separation between these types of components becomes critical. A React <DatePickerIOS> component obvi‐ ously cannot be reused for Android. However, a component that encapsulates the associated logic can be reused. Then the visual component can be swapped out based on your platform. You can also designate platform-specific versions of components if you want, so you could have a picker.ios.js and a picker.android.js file, each with a sep‐ arate implementation of the same component. We’ll cover this in “Components with Platform-Specific Implementations” on page 134. Using JSX In React Native, just as in React, we write our views using JSX, combining markup and the JavaScript that controls it into a single file. JSX met with strong reactions when React first debuted. For many web developers, the separation of files based on technologies is a given: you keep your CSS, HTML, and JavaScript files separate. The idea of combining markup, control logic, and even styling into one language can be confusing. JSX prioritizes the separation of concerns over the separation of technologies. In React Native, this is even more strictly enforced. In a world without the browser, it makes even more sense to unify our styles, markup, and behavior in a single file for each component. Accordingly, your .js files in React Native are in fact JSX files. If you’ve been using vanilla JavaScript when working with React for the web, you will want to transition to JSX syntax for your work in React Native. Creating Components in React Native | 9
If you’ve never seen JSX before, don’t worry: it’s pretty simple. As an example, a pure- JavaScript React component for the web might look something like this: class HelloMessage extends React.Component { render() { return React.createElement( "div", null, "Hello ", this.props.name ); } } ReactDOM.render( React.createElement(HelloMessage, { name: "Bonnie" }), mountNode); We can render this more succinctly by using JSX. Instead of calling React.createElement and passing in a list of HTML attributes, we use XML-like markup: class HelloMessage extends Component { render() { // Instead of calling createElement, we return markup return <div>Hello {this.props.name}</div>; } } // We no longer need a createElement call here ReactDOM.render(<HelloMessage name="Bonnie" />, mountNode); Both of these will render the following HTML onto the page: <div>Hello Bonnie</div> Styling Native Components On the web, we style React components using CSS, just as we would any other HTML element. Whether you love it or hate it, CSS is a necessary part of the web. React usu‐ ally does not affect the way we write CSS. It does make it easier to dynamically build class names based on props and state, but otherwise React is mostly agnostic about how we handle styles on the web. Non-web platforms have a wide array of approaches to layout and styling. When we work with React Native, thankfully, we utilize one standardized approach to styling. Part of the bridge between React and the host platform includes the implementation of a heavily pruned subset of CSS. This narrow implementation of CSS relies primar‐ ily on flexbox for layout, and focuses on simplicity rather than implementing the full range of CSS rules. Unlike the web, where CSS support varies across browsers, React Native is able to enforce consistent support of style rules. As with the various UI 10 | Chapter 2: Working with React Native
elements, you can see many examples of supported styles in the RNTester application, which is one of the examples that ships with React Native. React Native also insists on the use of inline styles, which exist as JavaScript objects. The React team has advocated for this approach before in React for web applications. If you have previously experimented with inline styles in React, the syntax will look familiar to you: // Define a style... const style = { backgroundColor: 'white', fontSize: '16px' }; // ...and then apply it. const txt = ( <Text style={style}> A styled Text </Text>); React Native also provides some utilities for creating and extending style objects that make dealing with inline styles a more manageable process. We will explore those later in Chapter 5. Does looking at inline styles make you twitch? If you’re coming from a web-based background, this is a break from standard practices. Working with style objects, as opposed to stylesheets, takes some mental adjustments and changes the way you need to approach writing styles. However, in the context of React Native, it is a useful shift. We will be discussing styling best practices and workflow in Chapter 5. Just try not to be surprised when you see them in use! Host Platform APIs Perhaps the biggest difference between React for the web and React Native is the way we think about host platform APIs. On the web, we often deal with fragmentation and inconsistent adoption of standards; still, most browsers support a common core of shared features. With React Native, however, platform-specific APIs play a much larger role in creating an excellent, natural-feeling user experience. There are also many more options to consider. Mobile APIs include everything from data storage to location services to accessing hardware such as the camera. Unconventional plat‐ forms lead to even more interesting APIs—what should the interface look like between React Native and a virtual reality headset, for instance? By default, React Native for iOS and Android includes support for many commonly used features, and React Native can support any asynchronous native API. We will take a look at many of them throughout this book. React Native makes it straightfor‐ ward and simple to use host platform APIs, so you can experiment freely. Be sure to Host Platform APIs | 11
think about what feels right for your target platform, and design with natural interac‐ tions in mind. Inevitably, the React Native bridge will not expose all host platform functionality. If you find yourself in need of an unsupported feature, you have the option of adding it to React Native yourself. Alternatively, chances are good that someone else has done so already, so be sure to check for community implementations. We’ll cover this in Chapter 7. It is also worth noting that utilizing host platform APIs has implications for code reuse. React components that need platform-specific functionality will be platform- specific as well. Isolating and encapsulating those components will bring added flexi‐ bility to your application. Of course, this applies for the web, too: if you plan on sharing code between React Native and React, keep in mind that things like the DOM do not actually exist in React Native. Summary Writing components for mobile is a bit different in React Native when compared with React for the web. JSX is mandatory, and our basic building blocks are now compo‐ nents such as <View> in lieu of HTML elements such as <div>. Styling is also quite different, based on a subset of CSS, and we assign styles with inline syntax. Still, these adjustments are quite manageable. In the next chapter, we’ll put this into practice as we build our first application! 12 | Chapter 2: Working with React Native
CHAPTER 3 Building Your First Application In this chapter, we will cover how to set up your local development environment for working with React Native. Then we will go through the basics of creating a simple application that you can deploy to your own iOS or Android device. Setting Up Your Environment Setting up your development environment will enable you to follow along with the examples in the book and write your own applications. There are two general approaches to setting up a development environment for React Native. The first, a tool called Create React Native App, gives you a quicker, easier installation but supports only pure-JavaScript applications. The second, more tradi‐ tional approach involves fully installing React Native and all of its dependencies. Think of Create React Native App as a shortcut for easier testing and prototyping. Information on migrating from Create React Native App to a full React Native project can be found in Appendix C. Which approach should you take? I recommend that beginners use Create React Native App for educational purposes and quick proto‐ typing. Eventually, if you’re working on a React Native app professionally or writing a hybrid app that uses both JavaScript and native Java, Objective-C, or Swift code, you’ll want to install the full React Native developer setup. 13
Both approaches are described next. The example code in subsequent chapters will typically work with either approach; when something is incompatible with Create React Native App and requires a full React Native project, it will be noted. Developer Setup: Create React Native App Create React Native App is a command-line tool that allows you to quickly create and run React Native applications without needing to install Xcode or Android Studio. If you want to get up and running quickly, then Create React Native App is the right choice. Create React Native App is a great tool, but as mentioned earlier it supports only pure-JavaScript applications. Later in this book, we’ll discuss ways of integrating React Native applications with native code written in Java or Objective-C. Don’t worry: if you begin with Create React Native App, you can still “eject” into a full React Native project. Let’s start by installing the create-react-native-app package from npm. React Native uses npm, the Node.js package manager, to manage dependencies. The npm registry includes packages for all sorts of JavaScript projects, not just Node. npm install -g create-react-native-app Creating Your First Application with create-react-native-app To create a new project with Create React Native App, run the following command: create-react-native-app first-project This will install some JavaScript dependencies, as well as create the boilerplate for your application. Your project directory will look something like this: . ├── App.js ├── App.test.js ├── README.md ├── app.json ├── node_modules ├── package.json └── yarn.lock This structure looks like what you might expect from a simple JavaScript project. There is a package.json file, which contains metadata about the project and its depen‐ dencies. The README.md file includes information for running the project. App.test.js includes a simple test file. The code for your application is located in 14 | Chapter 3: Building Your First Application
Exploring the Variety of Random Documents with Different Content
“Well—” she responded at last, “yes, Claude—I do! But,” she added, “the whole affair is too mystifying—too utterly amazing. When, one day, I can tell you what happened to me you will, I know, stand aghast. Ah! when I think of it all,” she cried hoarsely, “I often regard it as a miracle that I am alive and at your side again—at the side of the man I love!” More than this she refused to tell me. I had, at last, established that the hand of Lionel Eastwell, the popular pilot at Hendon, was the hand of the enemy. I had suspected it, but here was proof! His association with the mysterious woman was, of course, still an enigma, but I saw that Roseye herself held the key to it, and now that we had agreed that Eastwell was playing us both false, I hoped that this, in itself, would induce her to tell me the frank and open truth. When Teddy returned he heard from my lips what had happened during our absence, and he stood speechless. “Let’s run the dynamo, light up, and examine the machine,” he suggested, and though it was already midnight we readily adopted his suggestion. That it had again been tampered with I felt no doubt. That statement of old Theed’s that he had heard “sawing” made it plain that some devil’s work had been done—and by Eastwell no doubt, because he was an expert in aviation. The expert knows exactly the point at which he can weaken the strongest aeroplane. Well, we soon ran the dynamo, and had a good light going, one that was almost too glaring in that confined space. All
of us were present, including the maid Mulliner, as slowly we examined and tested, piece by piece, every bolt, nut, strainer, and indeed every part of the machine. It was past three o’clock in the morning ere we finished, yet we could find absolutely nothing wrong. The engines worked well: the dynamo was in order, the intensified current for the working of the invisible wave was up to the high voltage as before, and as far as we could discover the machine had not been tampered with in any way. “They intended to investigate the secrets of the box,” Teddy remarked. “No doubt that’s what they were after.” “Well—they didn’t see very much!” I laughed, for already I had been up to the locked attic to which we had carried it on the previous night, and found it there with the door still secure. Then, having satisfied ourselves that no damage had been done, we all retired to rest. But sleep did not come to my eyes. Hour after hour I lay awake until the grey dawn, pondering over the events of that night. That a desperate plot of the enemy was afoot against us could not be doubted, and I realised that it would take all our ingenuity and foresight to combat the plans of an unscrupulous enemy well provided with money, and desperate upon a resolve. To go boldly to the authorities and denounce Lionel Eastwell as a spy would avail me nothing. Indeed, there was no actual evidence of it. No more popular man at Hendon, at Brooklands, or at the Royal Automobile Club was there than Eastwell. Yet, was not that popularity, purchased by the ample means at his disposal, and the constant dinners and
luncheons which he gave regardless of their cost, proof in itself that he was acting secretly against the interests of Great Britain? Long ago I had suspected that his was the Invisible Hand that sent every secret of our progress in aviation to Germany by way of the United States. He had several American friends to whom I had been introduced, apparently business men who had come over for various reasons, and it was, no doubt, those men who conveyed back to New York secret information which, later on, returned across the Atlantic and was duly docketed in the Intelligence Bureau of the German General Staff at Berlin. Truly the wily Teuton leaves nothing to chance, and has his secret agents in the most unsuspected places. Yet, reflecting as I did in those long wakeful hours, I saw that it was not surprising, and that the enemy would, naturally, have kept a very watchful eye upon anyone who had devised a means of fighting Zeppelins, and, if possible, defeat him in his attempt. This thought decided me. I meant, at all hazards, to try my device against an enemy airship, even though I might fail. I had foreseen all the risks of machine-guns mounted upon the top of the latest airship, of the dangers of night-flying, of landing difficulties even if successful, and the hundred and one mishaps which might occur in the excitement and darkness. Indeed, in following a Zeppelin at a high altitude and in clouds, I might very easily be mistaken for an enemy attendant aeroplane, and thus draw the fire of our own anti- aircraft guns. In addition, I held no official position in the anti-aircraft service. As far as the newly-formed Joint Naval and Military Air Committee were concerned, I might be a mere man-in-the-street. Therefore I should be compelled to act upon my own initiative. Indeed, I had already offered
my invention to the proper official quarter, but had only received a type-written acknowledgment. I, however, was not surprised, because that Department had, I knew, been flooded by the devices of hot-air cranks. Still, as I lay reflecting, I remembered that we could build 1,700 aeroplanes for the cost of one Dreadnought, and a Zeppelin would cost a good deal less than a destroyer. I did not approve of that shrieking section of the Press which was loudly declaring that we had lost the supremacy in aeroplanes which we possessed at the beginning of the war. That was not a fact. We, of course, had no dirigibles worth the name and, perhaps, we were asking pilots to fly machines inferior to the Fokker. Yet we had brought Fokkers down at the front, and with good experimental work and a speedy policy of construction we should, I believed, soon be far ahead of the Central Powers as far as aircraft was concerned. Those days were dark and perilous days for Britain. That something must be done, every one was agreed. Yet, as I tossed upon my bed in that narrow little room in the obscure farm-house, I knew that within my hand I possessed a great, and yet mysterious power—and that power I intended to use and prove at the earliest opportunity. Still I had to reckon with enemies; cool, clever, cunning persons who would hesitate at nothing in order to nullify my efforts, and wreck my machine and all my hopes. Ah! If only Roseye, my well-beloved, would reveal to me the truth. Why did she so persistently refuse?
Why? I wondered why?
Chapter Twenty Two. More Devil’s Work. Next day I decided that, in view of the fact that our enemies had traced us, it would be best to at once remove our headquarters. Further, in order to attack a Zeppelin, as I intended, we ought to station ourselves upon the line of their advance from the East Coast towards London, and somewhere in proximity to an anti-aircraft listening-post. All three of us held council and decided that, as I knew of a listening-post in East Anglia, I should fly the machine to that neighbourhood, rather than dismantle it and take it by road. It was arranged that Teddy should accompany me, and that Theed should drive Roseye, Mulliner and his father in the car. By this rapid and unexpected flight we hoped to at least evade the unwelcome attentions of that mysterious woman whom Roseye described as having leopard’s eyes. Experience had taught us that in the Zeppelin raids upon England the airships generally approached by crossing the coast-line between Lowestoft and Margate, therefore I decided upon a district that would be the centre of a danger-zone. Having studied my map I saw that my most direct route would be over Tonbridge, thence by the railway line to Sevenoaks, and then north-east till I could pick up Gravesend—which would be easy on account of the river Thames—and afterwards due north would bring me to G—, which would be easily distinguishable by certain landmarks. We had wheeled out the machine, and I was tuning her up before starting, both Teddy and I ready in our air-clothes,
when Theed, who was giving the machine a final look round, suddenly gave vent to an ejaculation of dismay. “Why look, sir!” he cried. “What’s this?” I hopped quickly out of the pilot’s seat and, joining him, saw to my surprise that, beneath the wooden petrol-tank a fine insulated twin-wire had been, placed, and upon it, tacked lightly to the wood, was a small disc of some black- looking material through which the fine wire ran. In breathless eagerness I traced the wire and, to my horror, saw what a devilish contrivance it was. The twin-wire had been connected up to the battery that ran the lamp over my map and instruments, therefore had I switched on the light at night, it would have failed, for it was intended that the current should ignite that little disc of inflammable material and explode my petrol-tank behind me! Truly, the device of those crafty and subtle enemies was a devilish one. That wire had been connected up by an Invisible Hand—by the hand of one who certainly knew the most vulnerable point of the machine. Teddy and Roseye both stood aghast at this latest revelation. Then, when I had disconnected the wire, I placed it with the little black incendiary disc upon the ground and connected up the wires to an accumulator from the car. In a moment the black substance shot into a fierce red flame which burned and spluttered with intense heat for fully five minutes. From the barn, a few minutes later, Theed emerged carrying a piece of the wire, evidently discarded by the intruder who
had so swiftly and so cunningly prepared another death- trap for me. A further hour we spent in making a second examination of the machine, and then having appointed to meet that evening at the old King’s Head, in G—, at seven o’clock, I climbed into the pilot’s seat and, with Teddy at my side, we shot forward and soon left the ground heading for the railway line which I knew would run from right to left across our track at Tonbridge. I was really glad to place Holly Farm behind me. It certainly was not a “healthy” spot, as far as we were concerned. The low-down cunning of our enemies had once more been revealed. Yet how I longed for Roseye to tell me the actual truth! Why did she so persistently refuse? What could she have to hide from me—the man who loved her so very dearly. We trusted each other. She had trusted her life to me in the air on many occasions—even on the previous night. Yet she remained silent. The day was bright and crisp, with a slight north-westerly wind and a few scudding clouds. Very soon, when we had risen to about four thousand feet—for I had determined to fly high again—I saw a big seaplane coming up from the coast. It passed us about four miles distant and then I gave over the dual controls to Teddy, so that he might get used to them ready for the crucial test when it must mean either destruction to a Zeppelin, or to ourselves. Teddy was a first-rate patriot. There was nothing of the milk-and-water type about him, and yet, at the same time, he was nothing of a lady’s man. He was always courteous, humorous, and charming with the fair sex, but he preferred
to read and smoke his rather foul briar pipe, than to go out of an evening into the glitter and clatter of London life. But we were friends—firm friends, and he was just as prepared and keen to take the risk as I was. We found Tonbridge quite easily. Below us what looked like a toy-train was puffing along towards Dover, leaving a white streak of steam behind. For a few minutes I made a short circuit over the town in order to find the line that ran across to Sevenoaks, and at last, distinguishing it, I made my way over that rather scattered place and then struck another railway line at a place marked upon the map as Fawkham, after which I soon picked out the shining river with Gravesend on one bank and Tilbury on the other. I glanced at the altimeter. We were 10,500 feet up. Below us all was misty in the valley of the river. Then over the brown land of Essex I sped forward until I again found another railway line at Brentwood and, following it, soon saw my landmark—one which I need not refer to here, for I have no desire to instruct enemy airmen. Nothing extraordinary had met my eye. I was used to the patchwork landscape. Then began a search for a convenient field in which to land. I came down from ten thousand to a thousand feet in long sweeping circles, examining each grass meadow as I went. The lower I came, the more easily could I distinguish the pastures and ploughed land and woods. A train was passing and I noted the direction of the smoke —most important in making a landing. Teddy at my side, as practised as I was myself in flying, had never moved. Through his big goggles he was gazing down, trying to decide upon a landing-place, just as I was.
I banked for a moment. Then put her nose down and then, finding no spot attractive, climbed again. I did not want to land too near the town, for I had no desire to attract undue attention. I was trying to find a certain main road, for, truth to tell, I had been up very early that morning consulting my maps. On that main road were two or three farms in which I hoped I could shelter my machine, just as I had done at Holly Farm. I suppose we spent perhaps nearly half an hour in the air before, after critical examination, I decided to descend into a large park before a good-sized old Georgian house belonging, no doubt, to some county family. Parks, provided they have few trees, are always desired by the aviator as landing-places. Indeed, as I circled round I could plainly see that several figures, attracted by the heavy, roar of my engine, were standing outside watching us. Two minutes later I brought the machine round to the wind. Down went her nose—down, down. The air screamed about our ears. The earth rushed up to meet us, as it always seems to do. Truth to tell, by my own fault, I had had a nasty nose-dive, but I righted her and, touching the grass, managed to pull up dead. Teddy, who had been watching it all, never turned a hair. Only when I shut off the roar of the engine, he remarked:
“By Jove! Devilish good landing! That nose-dive was rather a nasty one, Claude—wasn’t it?” And, unstrapping himself, he hopped out and sought his cigarette-case from his hip-pocket, as was his habit. We were close against the big, rather ugly country house, therefore, leaving the machine, we went up and soon found its owner—a retired colonel of the usual JP type—hard on poachers when on the County Bench, I expect. Still, he welcomed us warmly and was, we found, quite a good sort. I asked him to take us aside, and he conducted us to the library, a fine old-fashioned room lined with brown-backed books. There I told him the truth—of what we were after. “Well,” said the white-haired old man, looking me up and down, “you seem a pretty keen young fellow, and your friend also. If you are over here on such a mission then I hope you will, both of you, consider yourselves my guests. I’ve a big barn beyond the stables where I can garage your machine quite well.” Then I told him of the trio who were on their way to the King’s Head, in G—. “I shall only be too delighted to be their host,” he replied at once. “I know Sir Herbert and Lady Lethmere well, but I don’t believe I’ve ever met their daughter.” Then he introduced his wife, a rather youngly-dressed woman, whose eyes were “made-up” and the artificiality of
whose cheeks were just a trifle too transparent. But artificiality seems fashionable to-day. We duly put the machine away into the barn and later, when we sat at tea in the drawing-room, the conversation naturally turned upon Zeppelins. Colonel Cator, for such we had found our host’s name to be, held rather sceptical views regarding the power of aeroplanes to combat airships, and he waxed distinctly humorous as we sat together. “There have been so many fables told us about aircraft,” declared the erect old man, “that one does not really know what to believe.” “There have been a good many improvements recently in aircraft of all sorts, so that most of the pre-war types have been already scrapped,” I said. “Yes, yes, I know,” exclaimed our host. “But what I object is to the fairy-tales that we’ve been told in the past—how we’ve been reassured.” “But does the past really affect the present very much?” I queried. “I contend that it does. We should have been told the truth,” he declared emphatically and, rising, he took from beneath a table a large scrap-book. Then, returning to his chair, he said: “I have here a cutting from The Times of March 20, 1913. I came across it only the other day. Listen—and I’ll read it to you, because it is most illuminating to you airmen.” And then he read to us as follows:—
“Colonel Seeley, Secretary of State for War, said yesterday: We have decided that the Army should have small dirigibles which could be packed up in boxes, put in motor-lorries or in ships, and sent wherever they are required. These we have got. These dirigibles, I say without hesitation—and all who understand the matter will agree—are superior to any other kind of portable airship. They have various mechanical advantages, which I do not wish to dwell upon, because those concerned believe the secret is our own, enabling them to rise more rapidly in the air, and enabling them, above all, to avoid having to part with hydrogen when they rise, and therefore there is no need for reinforcing the hydrogen when they fall. They have these advantages, which we believe are superior to those of any other nation.” Then, pausing, the colonel raised his eyes to mine, and, with a merry laugh, asked: “Now. What do you think of that for a Ministerial statement eh?” “Perhaps, instead of putting them in boxes, we might have had them put into paper bags, and distributed with pounds of tea?” suggested Teddy. “Why not?” “But I don’t see how it affects the present situation at all,” I argued. “We are surely much wiser now than we were three years ago.” “Well—let’s hope so,” laughed the colonel. “But that speech is full of grim humour—is it not?” And with that we were compelled to agree.
Chapter Twenty Three. The “L39.” Having taken Colonel and Mrs Cator into our confidence, and they having invited Roseye to stay with them, we were all, on the following day, duly installed at Swalecliffe Park. Without delay I called upon the officer in charge of the listening-post—the whereabouts of which I do not intend to disclose—and, to my joy, found that he was a man named Moncrieff whom I had met many times at Hendon, and also at the club. Having told him of my intention to have a “go” at the next enemy airship that might come over, he readily promised that upon receiving the next alarm, he would make a point of ringing me up at Swalecliffe. Then, with the machine in readiness and already tested and re-tested, and also with a full petrol-tank, there was nothing further to do but to draw it out into the park each night, and await the alarm. It was on the first day of March when we had come down in Swalecliffe Park as strangers—on a Wednesday I remember —and the following days had been fully occupied with our preparations, while throughout each night Teddy and I, ready dressed for flight, sat in the colonel’s study wherein the telephone was installed. Thursday night passed quite uneventfully. During the earlier hours the colonel and Roseye sat with us, but the barometer being low, and the weather gusty, we had, even
at ten o’clock, decided that no Zeppelin would risk crossing the North Sea. On Friday night the four of us played bridge till half-past four, the Theeds being, of course, on duty outside. We had the consolation of knowing that, though the Invisible Hand might be searching for us, it had not yet discovered our place of concealment. Each evening we tested the telephone —through the local exchange—out to the listening-post, and each evening Moncrieff, who was in charge, answered cheerily: “Don’t fear, old chap, I’ll give you a ring as soon as anything is going on.” Saturday, the fourth of March, was bright and warm, but just before sunset a sharp easterly breeze sprang up and, with a falling barometer, we knew that our vigilance would remain unrewarded. So again we played bridge until Roseye grew sleepy and then retired. Certainly we did not appear to meet with any luck. On Sunday morning we all went to the pretty little church of Swalecliffe, and in the afternoon I went out for a pleasant stroll with Roseye through the park and leafless woods. Again I pressed her to reveal to me what she knew regarding that mysterious woman who was in association with the fellow Eastwell. But once again she steadfastly declined to reveal anything. “No, no!” she protested. “Please don’t ask me, Claude.” “But surely I have a right to know!” I declared. “Your enemies are mine; and we are fighting them together. We
have agreed to marry, Roseye, therefore you may surely trust me with your secret!” I had halted at a stile before crossing our path leading into the wood, and, as I held her hand in mine, I looked straight into her big blue eyes. She drew a long breath, and her gaze wavered. I saw that she now relented, and that she was unable to refute my argument. I pressed her hand and, in a deep, earnest voice, urged: “Tell me darling. Do tell me?” Again her chest heaved and fell beneath her furs. “Well, Claude. It’s—it’s a strange story—as strange as any woman has ever lived to tell,” she said at last, with great hesitation and speaking very slowly. “On that morning when I left I received a letter purporting to come from you, and urging me to meet you in secret on the departure platform of the Great Northern station at King’s Cross. Naturally, much puzzled, I went there, wondering what had happened. While waiting, a woman—the woman you have seen—came up to me and told me that you had sent her—that you wished to see me in secret in connexion with your invention, but that you were in hiding because you feared that some spies intended to obtain knowledge of the truth. She said that there were enemy spies on every hand, and that it would be best to go over to the hotel, and there wait till night before we went North to Grantham, whither you had gone.” “Grantham!” I echoed. “I’ve not been in Grantham for years.”
“But I believed that you were there, so plausible was the woman’s story,” she replied. “We left at night, travelling in a first-class compartment together. On the way, I suddenly suspected her. Somehow I did not like the look in those strange eyes of hers, and I accused her of deceiving me. Indeed, while dozing, I had seen her carefully take my chatelaine, put something into it, and drop it out of the window. We were in a tunnel, I believe.” “Then it was that woman who put the cipher-message into your card-case!” I exclaimed. “Yes, go on.” “Yes,” she replied. “I sprang up, and tried to pull the communication-cord as we came out of the tunnel, but she prevented me. She pushed a sponge saturated with some pungent-smelling liquid into my face, and then I knew nothing more until I found myself in a small room in a cottage somewhere remote in the country.” “Then you were detained there—eh?” “Yes. Forcibly. That awful woman tried, by every means in her power, to force or induce me to reveal the details of the experiments which you and Teddy were making at Gunnersbury. But I refused. Ah! how that hell-fiend tortured me day after day! “She nearly drove me mad by those fearful ordeals which, in a hundred ways, she put upon me—always promising to release me if I would but reveal details of what we had discovered. But I refused—refused always, Claude—because I knew that she was an enemy, and victory must be ours if I remained silent. Days—those terrible days—passed—so many that I lost count of them—yet I knew that the woman with the cruel eyes of a leopard had dosed me with some drug that sapped my senses, and she held me irrevocably in
her power, prompted no doubt by somebody who meant to work evil also upon you. In the end I must have lost my reason. I think she must have given me certain drugs in order to confuse me as to the past. Then, one day, I found myself in the town of Grantham, inquiring for the station. I was in a maid’s clothes, and in them I eventually returned to you. And you—Claude—you know all the rest.” And she burst into a torrent of tears. “Yes,” I said slowly. “And that blackguard Lionel Eastwell is the man who has directed all this intricate and dastardly intrigue against us.” Then I took my love into my arms, and pressing her to me, soothed her tears with my passionate kisses. What she had revealed to me amazed me. In the evening, just after the Sunday-night supper, Benton, the fat old butler, entered the drawing-room and, approaching me, said: “Mr Moncrieff is on the telephone, sir.” I sprang up with alacrity and, a few seconds later, spoke to my friend at the listening-post. “You there, Munro?” he asked. “We’ve just had a message to say that three Zeppelins are crossing the North Sea in the direction of the Norfolk coast.” “Right!” I said, and shut off at once. There was no time to lose. In a moment I told them of the alarm. Without much delay Teddy and I slipped into our air-kit, while Theed, with the
machine wheeled out into the park, reported that all was in readiness. I met Roseye in the corridor above the central staircase of the great old-world house, and there kissed her fondly. “For your dear sake I go, and for the sake of my King and country!” I whispered. “Good-bye, my darling. Keep a stout heart until you hear of me again!” “But—oh!—oh!—I fear, Claude!” she cried anxiously, clinging to me. “No, my darling. We must, to-day, all make sacrifices. There must be no fear. I shall be back with you to-morrow.” And then again I kissed her and disengaged those loving, clinging arms about me. Five minutes later Teddy and I were away in the air. The night was dull and overcast with a promise of clearing— yet bitterly cold. Of course with our big engine roaring we could hear nothing of the enemy’s approach, but I deemed it wise to rise high and, at the same time, to follow the railway line from Colchester towards London, because that, no doubt, was the route which the airships would follow. The alarm had been given, trains being darkened and brought to a standstill, station and signal-lights extinguished and towns blotted out, I quickly lost sight of the railway track and could only go very slowly to save petrol in case of a chase, and guide myself by my compass.
From a town somewhere on the coast I could see the long scintillating beams of a searchlight striking across the dark night sky, first directed in one quarter and then in another. I think it must have been the searchlight on the coast at T—. I saw Teddy was busy adjusting the Lewis machine-gun at his side as we climbed rapidly in the pitch darkness. The engine raced and hummed and the wind shrieked weirdly around us. I switched on the bulb over the instruments, in order to look at my altimeter, but so dark was it that the light got into my eyes and I was compelled to shut it off again. I flew in a wide circle at first, steadily climbing until the few faint twinkling lights below had disappeared entirely. We were getting nearer and nearer the Zeppelin altitude. Ah! how the engine throbbed and roared. Suddenly something black shot up close to me, rushing on as quickly as an express train. So suddenly did it rise up against me, that it gave me quite a start. It seemed a great, unholy thing, and quite shapeless. It was another aeroplane, like ourselves, out to destroy the enemy airship with bombs. And by Jove! we narrowly avoided a nasty collision. A second later we heard the loud report of a gun. Our anti- aircraft gunners had spotted their quarry somewhere in the vicinity. A moment afterwards upon our left, straight before us, two long beams of searchlight shot out, and then a sharp volley from the guns. They were possibly five miles distant, and in the direction of London—somewhere near Brentwood I thought.
Bang! bang!—bang! we could hear, even above the throb of our powerful engine. Teddy turned on the second engine, and then opened up the searchlight, sweeping it around before us. But we could see nothing save some thin filmy clouds. Suddenly the searchlights from below went out, and the guns ceased. With one eye upon the altimeter I peered over, hoping to pick up some landmark, but I could find absolutely none. That a Zeppelin was in the vicinity was certain. I tried to keep as cool as I possibly could, but I confess that at that moment it was difficult. I cruised about, knowing that I was now nearing the London area. Suddenly, deep below, yet some miles ahead, I saw a blood-red flash. The Zeppelin had dropped a bomb! Again I switched on the little light, and a glance at my altimeter showed that I was up eleven thousand feet, therefore I pushed straight along in the direction of that red glare. That it was an incendiary one I saw, because the flare continued far down in the misty workaday world below. The Zeppelin was executing its evil work upon the harmless civilian inhabitants. I craned and peered around on all sides, but could see nothing else—only the glare from the incendiary fire. The night was rapidly growing brighter, and we could see the stars. Again we heard a violent cannonade, and once
more half a dozen beams of searchlights swept the sky from several points evidently much nearer to London. More than once the searchlights picked us up and examined us with suspicion, blinding us with their glare the while. Once more from below there came up two loud detonations —high explosive bombs—yet we could see no Zeppelin, though we peered into the darkness again as soon as the searchlight left us. Blinded by the glare, I had banked a little too steeply, and nearly had another bad nose-dive. Teddy noticed it, and said something, but what it was I could not hear for the roar. That an enemy airship was about, and that it had dropped incendiary bombs was proved by the three or four red glares we could distinctly see beneath us. No doubt the Zeppelin was moving fast, dropping her bombs preparatory to rising and escaping beyond the zone of our anti-aircraft guns. I rose higher, but still no sign of it. Apparently the searchlights, having once located it, had again lost it, for once more all the guns were silent. I began to lose heart. How horribly cold it was! I was now over London, unless I was much mistaken. Several other of our bomb-dropping aeroplanes were circling below me, also unable to find the Zeppelin. Suddenly Teddy gave me a sharp nudge and pointed upward. I glanced in the direction he indicated, and there saw the great long dark hull of the airship hovering quite near us. We were then over eight thousand feet up, and the airship was perhaps another thousand feet higher. I could
distinguish its two gondolas, and as we passed near its stern its fins and planes were now plainly silhouetted against the bright, steely sky. With all speed possible I shot upward, but apparently the commander of the Zeppelin had discovered us, while at that very same moment a searchlight from somewhere below picked him up and revealed him, a huge silvery object, upon the side of which was painted in black a large iron- cross, the Hun badge of frightfulness, together with initial and number “L39.” Scarcely had I become aware of the close proximity of the enemy when I saw a little spurt of red flare from the forward gondola. It continued for several moments, and I knew that it was a machine-gun spitting forth its leaden hail upon us. Therefore I drew away and rose still higher, while, next second, the propellers of the monster airship began to whirr and it started away, nose upward and due east, evidently upon its homeward journey. Unfortunately the men manning our searchlights below kept one of their beams upon us as well as another upon the Zeppelin, and I must confess that both Teddy and I, in our excitement, consigned them to a place with an atmosphere slightly warmer than the one we were at that moment experiencing. It seemed as though the anti-aircraft gunners, knowing the airship to be now out of range, were seized by a sudden curiosity to see what we were doing chasing the Zeppelin away as we gradually rose above it. Ah! Shall I ever forget those exciting moments! Time after time the machine-gun on the monster airship fired upon us, but I was flying in such a manner that to hit us would, I
knew, be difficult. Yet just then a stray bullet struck one of my planes and went through it, while a second later another tore through the casing of the fuselage. The commander of the Zeppelin thought, no doubt, that our intention was to rise and drop a bomb upon him, and he was now travelling very quickly in order to try and outpace us. In this, however, he did not succeed. How far we travelled I have no idea. In those moments I lost all sense of time and of distance. I only know that, though so high, I could distinguish the Thames with its few dotted lights about, though we were rapidly leaving London behind. We were passing over Essex, for I could plainly see the Thames widening upon my right, and I was gradually overhauling the enemy. At that moment I steadied myself, for I knew that the smallest slip would mean death to us both. At signal from me Teddy—who had already had the dynamo running for some time—placed his hand upon the switch which controlled the unseen, but deadly current. Slowly I crept nearer and nearer. Four thousand yards off— three thousand—another spurt—then I judged I was only two thousand yards away. Yet try how I would, I could get no nearer. Again I set to work and, letting out my roaring engines to their full power, I slowly decreased the space between the fleeing monster and myself, Teddy still awaiting my signal. Next instant I saw yet another spurt of fire from the rear gondola of the Zeppelin, and felt a hot, burning sensation in my forearm.
Then I knew that I had been hit! I nudged Teddy, and he nodded. He understood and with the end of the box in which was the large, lens something like a camera, directed full upon the enemy, he pulled over the switch. The result was appalling. Next instant there was a blinding flash as the electric sparks flying from point to point all over the metal framework of the Zeppelin ignited the hydrogen; a huge red burst of flame came from the centre of the great airship, and following it was a terrific explosion, the frightful force of which would have turned us completely over had I not been prepared. I swerved quickly, in order to get out of the vicinity, for the danger at that instant was very great. Then, as I glanced aside, I saw the huge monster plunge down to earth, ablaze and flaring like a huge torch. A second terrific explosion of bombs occurred when it reached the ground, and the whole country-side, shaken as though by an earthquake, became instantly illuminated for miles around. Appalled at the sight, and yet relieved of the terrible tension, we both looked down and found that the enemy airship had, fortunately, fallen upon some flat land without houses—a wide, lonely marsh it appeared to be. I at once dropped to a thousand feet and then, with a final glance at our work of destruction, turned tail and set about finding a landmark.
It was difficult, but I discovered one at last and, half an hour later, finding old Theed’s flares in Swalecliffe Park, gently planed again to earth. Need I detail the congratulations showered upon Teddy and myself; of Roseye’s delight, or of her parent’s enthusiasm next day? Indeed, it seemed as though the world about us —our little world who knew the truth of our night-exploit— had gone mad with joy. On the following day I reported personally to the authorities, and afterwards had a long conference with certain high officials, who listened most intently to the description of my apparatus, and who heartily congratulated both Teddy and myself. That same night, indeed, my description being but superficial, experts came down with me to Swalecliffe, where the apparatus was thoroughly and satisfactorily tested, and declared to be an air-defence of the highest importance, and one which must soon prove our superiority against the Zeppelin menace. It was, I felt, my duty to reveal in the proper quarter the dastardly attempts made upon all three of us by our enemies, directed by the man Eastwell, who I feared knew something of our secret, whereupon orders were at once given to the Special Branch of Scotland Yard for his arrest under the Defence of the Realm Act. Two officers ascended to his rooms in Albemarle Street an hour later, but when he learnt they were detectives he dashed into his bedroom and, without hesitation and before they could prevent him, shot himself.
Welcome to our website – the ideal destination for book lovers and knowledge seekers. With a mission to inspire endlessly, we offer a vast collection of books, ranging from classic literary works to specialized publications, self-development books, and children's literature. Each book is a new journey of discovery, expanding knowledge and enriching the soul of the reade Our website is not just a platform for buying books, but a bridge connecting readers to the timeless values of culture and wisdom. With an elegant, user-friendly interface and an intelligent search system, we are committed to providing a quick and convenient shopping experience. Additionally, our special promotions and home delivery services ensure that you save time and fully enjoy the joy of reading. Let us accompany you on the journey of exploring knowledge and personal growth! textbookfull.com

Learning React Native Building Native Mobile Apps with JavaScript 2nd Edition Bonnie Eisenman

  • 1.
    Learning React NativeBuilding Native Mobile Apps with JavaScript 2nd Edition Bonnie Eisenman download https://textbookfull.com/product/learning-react-native-building- native-mobile-apps-with-javascript-2nd-edition-bonnie-eisenman/ Download more ebook from https://textbookfull.com
  • 2.
    We believe theseproducts will be a great fit for you. Click the link to download now, or visit textbookfull.com to discover even more! Fullstack React Native Create beautiful mobile apps with JavaScript and React Native 5th Edition Devin Abbott https://textbookfull.com/product/fullstack-react-native-create- beautiful-mobile-apps-with-javascript-and-react-native-5th- edition-devin-abbott/ React Native in Action Developing iOS and Android apps with JavaScript 1st Edition Nader Dabit https://textbookfull.com/product/react-native-in-action- developing-ios-and-android-apps-with-javascript-1st-edition- nader-dabit/ React Native in Action Developing iOS and Android apps with JavaScript 1st Edition Nader Dabit https://textbookfull.com/product/react-native-in-action- developing-ios-and-android-apps-with-javascript-1st-edition- nader-dabit-2/ Building Hybrid Android Apps with Java and JavaScript Applying Native Device APIs Japplying Native Device Apis 1st Edition Gok Nizamettin Khanna Nitin https://textbookfull.com/product/building-hybrid-android-apps- with-java-and-javascript-applying-native-device-apis-japplying- native-device-apis-1st-edition-gok-nizamettin-khanna-nitin/
  • 3.
    Progressive Web Appswith React Create Lightning Fast Web Apps With Native Power Using React and Firebase 1st Edition Scott Domes https://textbookfull.com/product/progressive-web-apps-with-react- create-lightning-fast-web-apps-with-native-power-using-react-and- firebase-1st-edition-scott-domes/ Cross-platform Localization for Native Mobile Apps with Xamarin 1st Edition Christopher Miller https://textbookfull.com/product/cross-platform-localization-for- native-mobile-apps-with-xamarin-1st-edition-christopher-miller/ Practical React Native: Build Two Full Projects and One Full Game using React Native 1st Edition Frank Zammetti https://textbookfull.com/product/practical-react-native-build- two-full-projects-and-one-full-game-using-react-native-1st- edition-frank-zammetti/ Learning React Modern Patterns for Developing React Apps 2nd Edition Alex Banks https://textbookfull.com/product/learning-react-modern-patterns- for-developing-react-apps-2nd-edition-alex-banks/ Building Progressive Web Apps Bringing the Power of Native to the Browser 1st Edition Tal Ater https://textbookfull.com/product/building-progressive-web-apps- bringing-the-power-of-native-to-the-browser-1st-edition-tal-ater/
  • 4.
    Bonnie Eisenman Learning React Native BUILDING NATIVEMOBILE APPS WITH JAVASCRIPT Learning React Native 2 n d E d i t i o n
  • 5.
    Bonnie Eisenman Learning ReactNative Building Native Mobile Apps with JavaScript SECOND EDITION Boston Farnham Sebastopol Tokyo Beijing Boston Farnham Sebastopol Tokyo Beijing
  • 6.
    978-1-491-98914-2 [LSI] Learning React Native byBonnie Eisenman Copyright © 2018 Bonnie Eisenman. All rights reserved. Printed in the United States of America. Published by O’Reilly Media, Inc., 1005 Gravenstein Highway North, Sebastopol, CA 95472. O’Reilly books may be purchased for educational, business, or sales promotional use. Online editions are also available for most titles (http://oreilly.com/safari). For more information, contact our corporate/insti‐ tutional sales department: 800-998-9938 or corporate@oreilly.com. Editor: Meg Foley Production Editor: Nicholas Adams Copyeditor: Rachel Monaghan Proofreader: Gillian McGarvey Indexer: Judith McConville Interior Designer: David Futato Cover Designer: Karen Montgomery Illustrator: Rebecca Demarest December 2015: First Edition November 2017: Second Edition Revision History for the Second Edition 2017-10-23: First Release See http://oreilly.com/catalog/errata.csp?isbn=9781491989142 for release details. The O’Reilly logo is a registered trademark of O’Reilly Media, Inc. Learning React Native, the cover image, and related trade dress are trademarks of O’Reilly Media, Inc. While the publisher and the author have used good faith efforts to ensure that the information and instructions contained in this work are accurate, the publisher and the author disclaim all responsibility for errors or omissions, including without limitation responsibility for damages resulting from the use of or reliance on this work. Use of the information and instructions contained in this work is at your own risk. If any code samples or other technology this work contains or describes is subject to open source licenses or the intellectual property rights of others, it is your responsibility to ensure that your use thereof complies with such licenses and/or rights.
  • 7.
    Table of Contents Preface.. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ix 1. What Is React Native?. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 Advantages of React Native 2 Developer Experience 2 Code Reuse and Knowledge Sharing 3 Risks and Drawbacks 4 Summary 4 2. Working with React Native. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 How Does React Native Work? 5 Rendering Lifecycle 7 Creating Components in React Native 8 Working with Views 8 Using JSX 9 Styling Native Components 10 Host Platform APIs 11 Summary 12 3. Building Your First Application. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 Setting Up Your Environment 13 Developer Setup: Create React Native App 14 Creating Your First Application with create-react-native-app 14 Previewing Your App on iOS or Android 15 Developer Setup: The Traditional Approach 16 Creating Your First Application with react-native 16 Running Your App on iOS 17 Running Your App on Android 18 iii
  • 8.
    Exploring the SampleCode 19 Building a Weather App 22 Handling User Input 24 Displaying Data 26 Fetching Data from the Web 29 Adding a Background Image 32 Putting It All Together 34 Summary 36 4. Components for Mobile. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39 Analogies Between HTML Elements and Native Components 39 The <Text> Component 40 The <Image> Component 42 Working with Touch and Gestures 44 Creating Basic Interactions with <Button> 44 Using the <TouchableHighlight> Component 45 Using the PanResponder Class 48 Working with Lists 54 Using the Basic <FlatList> Component 56 Updating the <FlatList> Contents 59 Integrating Real Data 63 Working with <SectionList> 65 Navigation 69 Other Organizational Components 70 Summary 71 5. Styles. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73 Declaring and Manipulating Styles 73 Using Inline Styles 74 Styling with Objects 75 Using StyleSheet.create 75 Concatenating Styles 76 Organization and Inheritance 77 Exporting Style Objects 77 Passing Styles as Props 78 Reusing and Sharing Styles 79 Positioning and Designing Layouts 80 Using Layouts with Flexbox 80 Using Absolute Positioning 84 Putting It Together 85 Summary 88 iv | Table of Contents
  • 9.
    6. Platform APIs.. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91 Using Geolocation 91 Reading the User’s Location 92 Handling Permissions 93 Testing Geolocation in Emulated Devices 94 Watching the User’s Location 95 Working Around Limitations 95 Updating the Weather Application 96 Accessing the User’s Images and Camera 98 Interacting with the CameraRoll Module 99 Requesting Images with GetPhotoParams 100 Rendering an Image from the Camera Roll 101 Uploading an Image to a Server 102 Storing Persistent Data with AsyncStorage 103 The SmarterWeather Application 104 The <WeatherProject> Component 104 The <Forecast> Component 107 The <Button> Component 108 The <LocationButton> Component 109 The <PhotoBackdrop> Component 110 Summary 112 7. Modules and Native Code. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113 Installing JavaScript Libraries with npm 113 Installing Third-Party Components with Native Code 115 Using the Video Component 116 Objective-C Native Modules 116 Writing an Objective-C Native Module for iOS 116 Exploring react-native-video for iOS 121 Java Native Modules 124 Writing a Java Native Module for Android 124 Exploring react-native-video for Java 127 Cross-Platform Native Modules 130 Summary 130 8. Platform-Specific Code. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133 iOS- or Android-Only Components 133 Components with Platform-Specific Implementations 134 Using Platform-Specific File Extensions 134 Using the Platform Module 137 When to Use Platform-Specific Components 137 Table of Contents | v
  • 10.
    9. Debugging andDeveloper Tools. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139 JavaScript Debugging Practices, Translated 139 Activating the Developer Options 139 Debugging with console.log 141 Using the JavaScript Debugger 143 Working with the React Developer Tools 144 React Native Debugging Tools 145 Using Inspect Element 145 Interpreting the Red Screen of Death 146 Debugging Beyond JavaScript 150 Common Development Environment Issues 151 Common Xcode Problems 151 Common Android Problems 152 The React Native Packager 153 Issues Deploying to an iOS Device 153 Simulator Behavior 155 Testing Your Code 155 Type Checking with Flow 156 Unit Testing with Jest 156 Snapshot Testing with Jest 157 When You’re Stuck 160 Summary 161 10. Navigation and Structure in Larger Applications. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 163 The Flashcard Application 163 Project Structure 166 Application Screens 167 Reusable Components 173 Styles 177 Data Models 178 Using React-Navigation 181 Creating a StackNavigator 182 Using navigation.navigate to Transition Between Screens 182 Configuring the Header with navigationOptions 185 Implementing the Rest 186 Summary 187 11. State Management in Larger Applications. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 189 Using Redux to Manage State 189 Actions 190 Reducers 192 Connecting Redux 195 vi | Table of Contents
  • 11.
    Persisting Data withAsyncStorage 203 Summary and Homework 206 Conclusion. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 207 A. Modern JavaScript Syntax. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 209 B. Deploying Your Application. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 215 C. Working with Expo Applications. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 219 Index. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 221 Table of Contents | vii
  • 13.
    Preface This book isan introduction to React Native, Facebook’s JavaScript framework for building mobile applications. Using your existing knowledge of JavaScript and React, you’ll be able to build and deploy fully featured mobile applications for both iOS and Android that truly render natively. There are plenty of advantages to working with React Native over traditional means of mobile development without needing to sacri‐ fice the native look and feel. We’ll start with the basics and work our way up to creating a full-fledged application with 100% code reuse between iOS and Android. In addition to the essentials of the framework, we’ll discuss how to work beyond it, including how to make use of third- party libraries and even how to write your own Java or Objective-C libraries to extend React Native. If you’re coming to mobile development from the perspective of a frontend software engineer or web developer, this is the book for you. React Native is a pretty amazing thing, and I hope you’re as excited to explore it as I am! Prerequisites This book is not an introduction to React, in general. We’ll assume that you have some working knowledge of React. If you’re brand new to React, I suggest reading through a tutorial or two before coming back to take the plunge into mobile develop‐ ment. Specifically, you should be familiar with the role of props and state, the com‐ ponent lifecycle, and how to create React components. We’ll also be using some modern JavaScript syntax, as well as JSX. If you aren’t famil‐ iar with these, don’t worry; we’ll cover JSX in Chapter 2, and modern JavaScript syn‐ tax in Appendix A. These features are essentially 1:1 translations of the JavaScript code you’re already accustomed to writing. This book focuses on using React Native to write iOS and Android applications, though React Native can also be used to write applications targeting Ubuntu, ix
  • 14.
    Windows, and macOS.Linux and Windows users can use React Native to develop Android applications, but in order to write iOS applications, you will need to develop on macOS. Conventions Used in This Book The following typographical conventions are used in this book: Italic Indicates new terms, URLs, email addresses, filenames, and file extensions. Constant width Used for program listings, as well as within paragraphs to refer to program ele‐ ments such as variable or function names, databases, data types, environment variables, statements, and keywords. Constant width bold Shows commands or other text that should be typed literally by the user. Constant width italic Shows text that should be replaced with user-supplied values or by values deter‐ mined by context. This element signifies a tip or suggestion. This element signifies a general note. This element indicates a warning or caution. x | Preface
  • 15.
    Using Code Examples Supplementalmaterial (code examples, exercises, etc.) is available for download at https://github.com/bonniee/learning-react-native. This book is here to help you get your job done. In general, if example code is offered with this book, you may use it in your programs and documentation. You do not need to contact us for permission unless you’re reproducing a significant portion of the code. For example, writing a program that uses several chunks of code from this book does not require permission. Selling or distributing a CD-ROM of examples from O’Reilly books does require permission. Answering a question by citing this book and quoting example code does not require permission. Incorporating a signifi‐ cant amount of example code from this book into your product’s documentation does require permission. We appreciate, but do not require, attribution. An attribution usually includes the title, author, publisher, and ISBN. For example: “Learning React Native, Second Edi‐ tion, by Bonnie Eisenman (O’Reilly). Copyright 2018 Bonnie Eisenman, 978-1-491-98914-2.” If you feel your use of code examples falls outside fair use or the permission given above, feel free to contact us at permissions@oreilly.com. O’Reilly Safari Safari (formerly Safari Books Online) is a membership-based training and reference platform for enterprise, government, educators, and individuals. Members have access to thousands of books, training videos, Learning Paths, interac‐ tive tutorials, and curated playlists from over 250 publishers, including O’Reilly Media, Harvard Business Review, Prentice Hall Professional, Addison-Wesley Profes‐ sional, Microsoft Press, Sams, Que, Peachpit Press, Adobe, Focal Press, Cisco Press, John Wiley & Sons, Syngress, Morgan Kaufmann, IBM Redbooks, Packt, Adobe Press, FT Press, Apress, Manning, New Riders, McGraw-Hill, Jones & Bartlett, and Course Technology, among others. For more information, please visit http://oreilly.com/safari. Preface | xi
  • 16.
    How to ContactUs Please address comments and questions concerning this book to the publisher: O’Reilly Media, Inc. 1005 Gravenstein Highway North Sebastopol, CA 95472 800-998-9938 (in the United States or Canada) 707-829-0515 (international or local) 707-829-0104 (fax) We have a web page for this book, where we list errata, examples, and any additional information. You can access this page at http://bit.ly/learning-react-native-2e. To comment or ask technical questions about this book, send email to bookques‐ tions@oreilly.com. For more information about our books, courses, conferences, and news, see our web‐ site at http://www.oreilly.com. Find us on Facebook: http://facebook.com/oreilly Follow us on Twitter: http://twitter.com/oreillymedia Watch us on YouTube: http://www.youtube.com/oreillymedia Resources It’s dangerous to go alone! Well, not really, but that doesn’t mean you have to. Here are some resources you may find useful as you work through the book: • The GitHub repository for this book contains all of the code samples we’ll be dis‐ cussing. If you get stumped or want more context, try looking here first. • Join the mailing list at LearningReactNative.com for follow-up articles, sugges‐ tions, and helpful resources. • The official documentation has a lot of good reference material. Additionally, the React Native community is a useful resource: • The react-native tag on Stack Overflow • The Reactiflux chat group includes many core contributors and other helpful folks • #reactnative (irc.lc/freenode/reactnative) on Freenode xii | Preface
  • 17.
    Acknowledgments As is traditional:this book would not have been possible without the help and sup‐ port of many others. Thank you to my editor, Meg Foley, and the rest of the O’Reilly team for bringing this project into the world. Thank you also to my technical review‐ ers for your time and insightful feedback: Ryan Hurley, Dave Benjamin, David Bieber, Jason Brown, Erica Portnoy, and Jonathan Stark. I would also like to thank the React Native team, without whose stellar work this book would naturally be impossible. Thanks also to Zachary Elliott for his help with the Flashcard application, Android testing, and support throughout. Mi estas dankplena pro via subteno. And many thanks are owed to my dear friends and family, who put up with me throughout this process and provided moral support, guidance, and distraction as the situation required. Thank you. Preface | xiii
  • 19.
    CHAPTER 1 What IsReact Native? React Native is a JavaScript framework for writing real, natively rendering mobile applications for iOS and Android. It’s based on React, Facebook’s JavaScript library for building user interfaces, but instead of targeting the browser, it targets mobile platforms. In other words, it enables web developers to write mobile applications that look and feel truly “native,” all from the comfort of a familiar JavaScript library. Plus, because most of the code you write can be shared between platforms, React Native makes it easy to simultaneously develop for both Android and iOS. Similar to React for the web, React Native applications are written with a mixture of JavaScript and XML-esque markup, known as JSX. Then, under the hood, the React Native “bridge” invokes the native rendering APIs in Objective-C (for iOS) or Java (for Android). Thus, your application will render using real mobile UI components, not webviews, and will look and feel like any other mobile application. React Native also exposes JavaScript interfaces for platform APIs, so your React Native apps can access platform features like the phone camera or the user’s location. The core React Native project supports writing mobile applications for both iOS and Android. Community implementations also provide support for Windows, Ubuntu, the web, and more. In this book, we’ll build both Android and iOS apps with React Native. The vast majority of the code we write will be cross-platform. And, yes, you can really use React Native to build production-ready mobile applica‐ tions. Some anecdata: Facebook, Airbnb, Walmart, and Baidu are already using it in production for user-facing applications. 1
  • 20.
    Advantages of ReactNative The fact that React Native renders using its host platform’s standard rendering APIs distinguishes it from most existing methods of cross-platform application develop‐ ment, like Cordova or Ionic. Existing methods of writing mobile applications use combinations of JavaScript, HTML, and CSS and typically render using webviews. While this approach can work, it also comes with drawbacks, especially around per‐ formance. Additionally, these methods do not usually have access to the host plat‐ form’s set of native UI elements. When these frameworks do try to mimic native UI elements, the results usually feel just a little off. In addition, reverse-engineering all the fine details of things like animations takes an enormous amount of effort, and they can quickly become outdated. In contrast, React Native actually translates your markup to real, native UI elements, leveraging existing means of rendering views on whatever platform you are working with. Additionally, React works separately from the main UI thread, so your applica‐ tion can maintain high performance without sacrificing capability. The update cycle in React Native is the same as in React: when props or state change, React Native re- renders the views. The major difference between React Native and React in the browser is that React Native does this by leveraging the UI libraries of its host plat‐ form, rather than using HTML and CSS markup. For developers accustomed to working on the web with React, this means you can write mobile apps with the performance and look and feel of a native application, while using familiar tools. React Native also represents an improvement over normal mobile development in two other areas: developer experience and cross-platform development potential. Developer Experience If you’ve developed for mobile before, you might be surprised by how easy React Native is to work with. The React Native team has baked strong developer tools and meaningful error messages into the framework so that working with robust tools is a natural part of your development experience. For instance, because React Native is “just” JavaScript, you don’t need to rebuild your application in order to see your changes reflected; instead, you can refresh your appli‐ cation just as you would any other web page. All of those minutes spent waiting for your application to build can really add up, and in contrast React Native’s quick itera‐ tion cycle feels like a godsend. Additionally, React Native lets you take advantage of intelligent debugging tools and error reporting. If you are comfortable with Chrome or Safari’s developer tools (Figure 1-1), you will be happy to know that you can use them for mobile develop‐ ment as well. Likewise, you can use whatever text editor you prefer for JavaScript 2 | Chapter 1: What Is React Native?
  • 21.
    editing. React Nativedoes not force you to work in Xcode to develop for iOS or in Android Studio for Android development. Figure 1-1. Using the Chrome Debugger with React Native Besides the day-to-day improvements to your development experience, React Native also has the potential to positively impact your product release cycle. For instance, Apple and Google both permit you to load JavaScript-only changes to an app’s behav‐ ior without going through the standard review process. This is particularly nice on iOS, where application updates typically require several days or weeks of review. All of these small perks add up to saving you and your fellow developers time and energy, allowing you to focus on the more interesting parts of your work and be more productive overall. Code Reuse and Knowledge Sharing Working with React Native can dramatically shrink the resources required to build mobile applications. Any developer who knows how to write React code can target the web, iOS, and Android, all with the same skill set. By removing the need to “silo” developers based on their target platform, React Native lets your team iterate more quickly and share knowledge and resources more effectively. Not only can you share knowledge, but much of your code can be shared, too. Not all the code you write will be cross-platform, and depending on the functionality you Advantages of React Native | 3
  • 22.
    need on aspecific platform, you may occasionally need to dip into Objective-C or Java (we’ll cover how so-called native modules work in Chapter 7). But reusing code across platforms is surprisingly easy with React Native. For example, the Facebook Ads Manager application for Android shares 87% of its codebase with the iOS ver‐ sion. The final application we’ll look at in this book, a flashcard app, has total code reuse between Android and iOS. It’s hard to beat that! Risks and Drawbacks As with anything, using React Native is not without its downsides, and whether or not it is a good fit for your team really depends on your individual situation. Because React Native introduces another layer to your project, it can make debugging hairier, especially at the intersection of React and the host platform. We’ll cover debugging for React Native in more depth in Chapter 9 and try to address some of the most common issues. Along the same lines, when updates are released for the host platform—say, a new suite of APIs in a new version of Android—there will be a lag before they are fully supported in React Native. The good news is that in the vast majority of cases, you can implement support for missing APIs yourself, which we’ll cover in Chapter 7. Also, if you do hit a roadblock, you won’t be locked in to using React Native—many companies have successfully implemented hybrid approaches to app development. Changing the platform you use to write your applications is a big choice. Still, I think you’ll see that the benefits of React Native outweigh the risks. Summary React Native is an exciting framework that enables web developers to create robust mobile applications using their existing JavaScript knowledge. It offers faster mobile development and more efficient code sharing across iOS, Android, and the web without sacrificing the end user’s experience or application quality. The tradeoff is that it adds some complexity to your application setup. If your team can handle that and wants to develop mobile applications for more than just one platform, you should be looking at React Native. In the next chapter, we go over some of the main ways in which React Native differs from React for the web, and cover some key concepts. If you’d like to skip straight to developing, feel free to jump to Chapter 3, in which we set up our development envi‐ ronment and write our very first React Native application. 4 | Chapter 1: What Is React Native?
  • 23.
    CHAPTER 2 Working withReact Native In this chapter, we’ll cover the bridge, and review how React Native works under the hood. Then, we’ll look at how React Native components differ from their web coun‐ terparts, and cover what you’ll need to know in order to create and style components for mobile. If you’d prefer to dig into the development process and see React Native in action, feel free to jump ahead to Chapter 3. How Does React Native Work? The idea of writing mobile applications in JavaScript feels a little odd. How is it possi‐ ble to use React in a mobile environment? In order to understand the technical underpinnings of React Native, we first need to recall one of React’s concepts: the Vir‐ tual DOM. In React, the Virtual DOM acts as a layer between the developer’s description of how things ought to look and the work done to actually render your application onto the page. To render interactive user interfaces in a browser, developers must edit the browser’s DOM, or Document Object Model. This is an expensive step, and excessive writes to the DOM have a significant impact on performance. Rather than directly render changes on the page, React computes the necessary changes in-memory and rerenders the minimal amount necessary. Figure 2-1 shows how this works. 5
  • 24.
    Figure 2-1. Performingcalculations in the Virtual DOM limits rerendering in the brows‐ er’s DOM In the context of React on the web, most developers think of the Virtual DOM as a performance optimization. The Virtual DOM certainly has performance benefits, but its real potential lies in the power of its abstraction. Placing a clean abstraction layer between the developer’s code and the actual rendering opens up a lot of interesting possibilities. What if React could render to a target other than the browser’s DOM? After all, React already “understands” what your application is supposed to look like. Indeed, this is how React Native works, as shown in Figure 2-2. Instead of rendering to the browser’s DOM, React Native invokes Objective-C APIs to render to iOS com‐ ponents, or Java APIs to render to Android components. This sets React Native apart from other cross-platform app development options, which often end up rendering web-based views. Figure 2-2. React can render to different targets 6 | Chapter 2: Working with React Native
  • 25.
    This is allpossible because of the bridge, which provides React with an interface into the host platform’s native UI elements. React components return markup from their render function, which describes how they should look. With React for the web, this translates directly to the browser’s DOM. For React Native, this markup is translated to suit the host platform, so a <View> might become an iOS-specific UIView. The core React Native project supports iOS and Android. Because of the abstraction layer provided by the Virtual DOM, React Native can target other platforms, too— someone just needs to write the bridge. For example, there are community imple‐ mentations of React Native for Windows and Ubuntu, so you can also use React Native to create desktop applications. Rendering Lifecycle If you are accustomed to working in React, the React lifecycle should be familiar to you. When React runs in the browser, the render lifecycle begins by mounting your React components (Figure 2-3). Figure 2-3. Mounting components in React After that, React handles the rendering and rerendering of your component as neces‐ sary (Figure 2-4). Figure 2-4. Rerendering components in React For the render stage, the developer returns HTML markup from a React component’s render method, which React then renders directly into the page as necessary. For React Native, the lifecycle is the same, but the rendering process is slightly differ‐ ent because React Native depends on the bridge. We looked at the bridge briefly in Figure 2-2. The bridge translates JavaScript calls and invokes the host platform’s underlying APIs and UI elements (i.e., in Objective-C or Java, as appropriate). Because React Native doesn’t run on the main UI thread, it can perform these asyn‐ chronous calls without impacting the user’s experience. Rendering Lifecycle | 7
  • 26.
    Creating Components inReact Native All React code lives in React components. React Native components are largely the same as ordinary React components, with some important differences around ren‐ dering and styling. Working with Views When writing in React for the web, you render normal HTML elements (<div>, <p>, <span>, <a>, etc.). With React Native, all of these elements are replaced by platform- specific React components (see Table 2-1). The most basic is the cross-platform <View>, a simple and flexible UI element that can be thought of as analogous to the <div>. On iOS, for instance, the <View> component renders to a UIView, whereas on Android it renders to a View. Table 2-1. Basic React elements for the web compared with React Native React React Native <div> <View> <span> <Text> <li>, <ul> <FlastList>, child items <img> <Image> Other components are platform-specific. For instance, the <DatePickerIOS> compo‐ nent (predictably) renders the iOS standard date picker (Figure 2-5). Here is an excerpt from the RNTester sample app, demonstrating an iOS date picker. The usage is straightforward, as you would expect: <DatePickerIOS date={this.state.date} mode="time" /> Figure 2-5. The <DatePickerIOS> component is, as the name suggests, iOS-specific 8 | Chapter 2: Working with React Native
  • 27.
    Because all ofour UI elements are now React components rather than basic HTML elements like the <div>, you will need to explicitly import each component you want to use. For instance, we need to import the <DatePickerIOS> component like so: import { DatePickerIOS } from "react-native"; The RNTester application, which is bundled into the React Native GitHub project, allows you to view all of the supported UI elements. I encourage you to examine the various elements included in the RNTester app. It also demonstrates many styling options and interactions. Platform-specific components and APIs have special tags in the documentation, and typically use the platform name as a suffix —for example, <TabBarIOS> and <ToolbarAndroid>. Because these components vary from platform to platform, how you structure your React components becomes even more important when you’re working in React Native. In React for the web, we often have a mix of React components: some manage logic and their child components, while others render raw markup. If you want to reuse code when working in React Native, maintaining separation between these types of components becomes critical. A React <DatePickerIOS> component obvi‐ ously cannot be reused for Android. However, a component that encapsulates the associated logic can be reused. Then the visual component can be swapped out based on your platform. You can also designate platform-specific versions of components if you want, so you could have a picker.ios.js and a picker.android.js file, each with a sep‐ arate implementation of the same component. We’ll cover this in “Components with Platform-Specific Implementations” on page 134. Using JSX In React Native, just as in React, we write our views using JSX, combining markup and the JavaScript that controls it into a single file. JSX met with strong reactions when React first debuted. For many web developers, the separation of files based on technologies is a given: you keep your CSS, HTML, and JavaScript files separate. The idea of combining markup, control logic, and even styling into one language can be confusing. JSX prioritizes the separation of concerns over the separation of technologies. In React Native, this is even more strictly enforced. In a world without the browser, it makes even more sense to unify our styles, markup, and behavior in a single file for each component. Accordingly, your .js files in React Native are in fact JSX files. If you’ve been using vanilla JavaScript when working with React for the web, you will want to transition to JSX syntax for your work in React Native. Creating Components in React Native | 9
  • 28.
    If you’ve neverseen JSX before, don’t worry: it’s pretty simple. As an example, a pure- JavaScript React component for the web might look something like this: class HelloMessage extends React.Component { render() { return React.createElement( "div", null, "Hello ", this.props.name ); } } ReactDOM.render( React.createElement(HelloMessage, { name: "Bonnie" }), mountNode); We can render this more succinctly by using JSX. Instead of calling React.createElement and passing in a list of HTML attributes, we use XML-like markup: class HelloMessage extends Component { render() { // Instead of calling createElement, we return markup return <div>Hello {this.props.name}</div>; } } // We no longer need a createElement call here ReactDOM.render(<HelloMessage name="Bonnie" />, mountNode); Both of these will render the following HTML onto the page: <div>Hello Bonnie</div> Styling Native Components On the web, we style React components using CSS, just as we would any other HTML element. Whether you love it or hate it, CSS is a necessary part of the web. React usu‐ ally does not affect the way we write CSS. It does make it easier to dynamically build class names based on props and state, but otherwise React is mostly agnostic about how we handle styles on the web. Non-web platforms have a wide array of approaches to layout and styling. When we work with React Native, thankfully, we utilize one standardized approach to styling. Part of the bridge between React and the host platform includes the implementation of a heavily pruned subset of CSS. This narrow implementation of CSS relies primar‐ ily on flexbox for layout, and focuses on simplicity rather than implementing the full range of CSS rules. Unlike the web, where CSS support varies across browsers, React Native is able to enforce consistent support of style rules. As with the various UI 10 | Chapter 2: Working with React Native
  • 29.
    elements, you cansee many examples of supported styles in the RNTester application, which is one of the examples that ships with React Native. React Native also insists on the use of inline styles, which exist as JavaScript objects. The React team has advocated for this approach before in React for web applications. If you have previously experimented with inline styles in React, the syntax will look familiar to you: // Define a style... const style = { backgroundColor: 'white', fontSize: '16px' }; // ...and then apply it. const txt = ( <Text style={style}> A styled Text </Text>); React Native also provides some utilities for creating and extending style objects that make dealing with inline styles a more manageable process. We will explore those later in Chapter 5. Does looking at inline styles make you twitch? If you’re coming from a web-based background, this is a break from standard practices. Working with style objects, as opposed to stylesheets, takes some mental adjustments and changes the way you need to approach writing styles. However, in the context of React Native, it is a useful shift. We will be discussing styling best practices and workflow in Chapter 5. Just try not to be surprised when you see them in use! Host Platform APIs Perhaps the biggest difference between React for the web and React Native is the way we think about host platform APIs. On the web, we often deal with fragmentation and inconsistent adoption of standards; still, most browsers support a common core of shared features. With React Native, however, platform-specific APIs play a much larger role in creating an excellent, natural-feeling user experience. There are also many more options to consider. Mobile APIs include everything from data storage to location services to accessing hardware such as the camera. Unconventional plat‐ forms lead to even more interesting APIs—what should the interface look like between React Native and a virtual reality headset, for instance? By default, React Native for iOS and Android includes support for many commonly used features, and React Native can support any asynchronous native API. We will take a look at many of them throughout this book. React Native makes it straightfor‐ ward and simple to use host platform APIs, so you can experiment freely. Be sure to Host Platform APIs | 11
  • 30.
    think about whatfeels right for your target platform, and design with natural interac‐ tions in mind. Inevitably, the React Native bridge will not expose all host platform functionality. If you find yourself in need of an unsupported feature, you have the option of adding it to React Native yourself. Alternatively, chances are good that someone else has done so already, so be sure to check for community implementations. We’ll cover this in Chapter 7. It is also worth noting that utilizing host platform APIs has implications for code reuse. React components that need platform-specific functionality will be platform- specific as well. Isolating and encapsulating those components will bring added flexi‐ bility to your application. Of course, this applies for the web, too: if you plan on sharing code between React Native and React, keep in mind that things like the DOM do not actually exist in React Native. Summary Writing components for mobile is a bit different in React Native when compared with React for the web. JSX is mandatory, and our basic building blocks are now compo‐ nents such as <View> in lieu of HTML elements such as <div>. Styling is also quite different, based on a subset of CSS, and we assign styles with inline syntax. Still, these adjustments are quite manageable. In the next chapter, we’ll put this into practice as we build our first application! 12 | Chapter 2: Working with React Native
  • 31.
    CHAPTER 3 Building YourFirst Application In this chapter, we will cover how to set up your local development environment for working with React Native. Then we will go through the basics of creating a simple application that you can deploy to your own iOS or Android device. Setting Up Your Environment Setting up your development environment will enable you to follow along with the examples in the book and write your own applications. There are two general approaches to setting up a development environment for React Native. The first, a tool called Create React Native App, gives you a quicker, easier installation but supports only pure-JavaScript applications. The second, more tradi‐ tional approach involves fully installing React Native and all of its dependencies. Think of Create React Native App as a shortcut for easier testing and prototyping. Information on migrating from Create React Native App to a full React Native project can be found in Appendix C. Which approach should you take? I recommend that beginners use Create React Native App for educational purposes and quick proto‐ typing. Eventually, if you’re working on a React Native app professionally or writing a hybrid app that uses both JavaScript and native Java, Objective-C, or Swift code, you’ll want to install the full React Native developer setup. 13
  • 32.
    Both approaches aredescribed next. The example code in subsequent chapters will typically work with either approach; when something is incompatible with Create React Native App and requires a full React Native project, it will be noted. Developer Setup: Create React Native App Create React Native App is a command-line tool that allows you to quickly create and run React Native applications without needing to install Xcode or Android Studio. If you want to get up and running quickly, then Create React Native App is the right choice. Create React Native App is a great tool, but as mentioned earlier it supports only pure-JavaScript applications. Later in this book, we’ll discuss ways of integrating React Native applications with native code written in Java or Objective-C. Don’t worry: if you begin with Create React Native App, you can still “eject” into a full React Native project. Let’s start by installing the create-react-native-app package from npm. React Native uses npm, the Node.js package manager, to manage dependencies. The npm registry includes packages for all sorts of JavaScript projects, not just Node. npm install -g create-react-native-app Creating Your First Application with create-react-native-app To create a new project with Create React Native App, run the following command: create-react-native-app first-project This will install some JavaScript dependencies, as well as create the boilerplate for your application. Your project directory will look something like this: . ├── App.js ├── App.test.js ├── README.md ├── app.json ├── node_modules ├── package.json └── yarn.lock This structure looks like what you might expect from a simple JavaScript project. There is a package.json file, which contains metadata about the project and its depen‐ dencies. The README.md file includes information for running the project. App.test.js includes a simple test file. The code for your application is located in 14 | Chapter 3: Building Your First Application
  • 33.
    Exploring the Varietyof Random Documents with Different Content
  • 34.
    “Well—” she respondedat last, “yes, Claude—I do! But,” she added, “the whole affair is too mystifying—too utterly amazing. When, one day, I can tell you what happened to me you will, I know, stand aghast. Ah! when I think of it all,” she cried hoarsely, “I often regard it as a miracle that I am alive and at your side again—at the side of the man I love!” More than this she refused to tell me. I had, at last, established that the hand of Lionel Eastwell, the popular pilot at Hendon, was the hand of the enemy. I had suspected it, but here was proof! His association with the mysterious woman was, of course, still an enigma, but I saw that Roseye herself held the key to it, and now that we had agreed that Eastwell was playing us both false, I hoped that this, in itself, would induce her to tell me the frank and open truth. When Teddy returned he heard from my lips what had happened during our absence, and he stood speechless. “Let’s run the dynamo, light up, and examine the machine,” he suggested, and though it was already midnight we readily adopted his suggestion. That it had again been tampered with I felt no doubt. That statement of old Theed’s that he had heard “sawing” made it plain that some devil’s work had been done—and by Eastwell no doubt, because he was an expert in aviation. The expert knows exactly the point at which he can weaken the strongest aeroplane. Well, we soon ran the dynamo, and had a good light going, one that was almost too glaring in that confined space. All
  • 35.
    of us werepresent, including the maid Mulliner, as slowly we examined and tested, piece by piece, every bolt, nut, strainer, and indeed every part of the machine. It was past three o’clock in the morning ere we finished, yet we could find absolutely nothing wrong. The engines worked well: the dynamo was in order, the intensified current for the working of the invisible wave was up to the high voltage as before, and as far as we could discover the machine had not been tampered with in any way. “They intended to investigate the secrets of the box,” Teddy remarked. “No doubt that’s what they were after.” “Well—they didn’t see very much!” I laughed, for already I had been up to the locked attic to which we had carried it on the previous night, and found it there with the door still secure. Then, having satisfied ourselves that no damage had been done, we all retired to rest. But sleep did not come to my eyes. Hour after hour I lay awake until the grey dawn, pondering over the events of that night. That a desperate plot of the enemy was afoot against us could not be doubted, and I realised that it would take all our ingenuity and foresight to combat the plans of an unscrupulous enemy well provided with money, and desperate upon a resolve. To go boldly to the authorities and denounce Lionel Eastwell as a spy would avail me nothing. Indeed, there was no actual evidence of it. No more popular man at Hendon, at Brooklands, or at the Royal Automobile Club was there than Eastwell. Yet, was not that popularity, purchased by the ample means at his disposal, and the constant dinners and
  • 36.
    luncheons which hegave regardless of their cost, proof in itself that he was acting secretly against the interests of Great Britain? Long ago I had suspected that his was the Invisible Hand that sent every secret of our progress in aviation to Germany by way of the United States. He had several American friends to whom I had been introduced, apparently business men who had come over for various reasons, and it was, no doubt, those men who conveyed back to New York secret information which, later on, returned across the Atlantic and was duly docketed in the Intelligence Bureau of the German General Staff at Berlin. Truly the wily Teuton leaves nothing to chance, and has his secret agents in the most unsuspected places. Yet, reflecting as I did in those long wakeful hours, I saw that it was not surprising, and that the enemy would, naturally, have kept a very watchful eye upon anyone who had devised a means of fighting Zeppelins, and, if possible, defeat him in his attempt. This thought decided me. I meant, at all hazards, to try my device against an enemy airship, even though I might fail. I had foreseen all the risks of machine-guns mounted upon the top of the latest airship, of the dangers of night-flying, of landing difficulties even if successful, and the hundred and one mishaps which might occur in the excitement and darkness. Indeed, in following a Zeppelin at a high altitude and in clouds, I might very easily be mistaken for an enemy attendant aeroplane, and thus draw the fire of our own anti- aircraft guns. In addition, I held no official position in the anti-aircraft service. As far as the newly-formed Joint Naval and Military Air Committee were concerned, I might be a mere man-in-the-street. Therefore I should be compelled to act upon my own initiative. Indeed, I had already offered
  • 37.
    my invention tothe proper official quarter, but had only received a type-written acknowledgment. I, however, was not surprised, because that Department had, I knew, been flooded by the devices of hot-air cranks. Still, as I lay reflecting, I remembered that we could build 1,700 aeroplanes for the cost of one Dreadnought, and a Zeppelin would cost a good deal less than a destroyer. I did not approve of that shrieking section of the Press which was loudly declaring that we had lost the supremacy in aeroplanes which we possessed at the beginning of the war. That was not a fact. We, of course, had no dirigibles worth the name and, perhaps, we were asking pilots to fly machines inferior to the Fokker. Yet we had brought Fokkers down at the front, and with good experimental work and a speedy policy of construction we should, I believed, soon be far ahead of the Central Powers as far as aircraft was concerned. Those days were dark and perilous days for Britain. That something must be done, every one was agreed. Yet, as I tossed upon my bed in that narrow little room in the obscure farm-house, I knew that within my hand I possessed a great, and yet mysterious power—and that power I intended to use and prove at the earliest opportunity. Still I had to reckon with enemies; cool, clever, cunning persons who would hesitate at nothing in order to nullify my efforts, and wreck my machine and all my hopes. Ah! If only Roseye, my well-beloved, would reveal to me the truth. Why did she so persistently refuse?
  • 38.
  • 39.
    Chapter Twenty Two. MoreDevil’s Work. Next day I decided that, in view of the fact that our enemies had traced us, it would be best to at once remove our headquarters. Further, in order to attack a Zeppelin, as I intended, we ought to station ourselves upon the line of their advance from the East Coast towards London, and somewhere in proximity to an anti-aircraft listening-post. All three of us held council and decided that, as I knew of a listening-post in East Anglia, I should fly the machine to that neighbourhood, rather than dismantle it and take it by road. It was arranged that Teddy should accompany me, and that Theed should drive Roseye, Mulliner and his father in the car. By this rapid and unexpected flight we hoped to at least evade the unwelcome attentions of that mysterious woman whom Roseye described as having leopard’s eyes. Experience had taught us that in the Zeppelin raids upon England the airships generally approached by crossing the coast-line between Lowestoft and Margate, therefore I decided upon a district that would be the centre of a danger-zone. Having studied my map I saw that my most direct route would be over Tonbridge, thence by the railway line to Sevenoaks, and then north-east till I could pick up Gravesend—which would be easy on account of the river Thames—and afterwards due north would bring me to G—, which would be easily distinguishable by certain landmarks. We had wheeled out the machine, and I was tuning her up before starting, both Teddy and I ready in our air-clothes,
  • 40.
    when Theed, whowas giving the machine a final look round, suddenly gave vent to an ejaculation of dismay. “Why look, sir!” he cried. “What’s this?” I hopped quickly out of the pilot’s seat and, joining him, saw to my surprise that, beneath the wooden petrol-tank a fine insulated twin-wire had been, placed, and upon it, tacked lightly to the wood, was a small disc of some black- looking material through which the fine wire ran. In breathless eagerness I traced the wire and, to my horror, saw what a devilish contrivance it was. The twin-wire had been connected up to the battery that ran the lamp over my map and instruments, therefore had I switched on the light at night, it would have failed, for it was intended that the current should ignite that little disc of inflammable material and explode my petrol-tank behind me! Truly, the device of those crafty and subtle enemies was a devilish one. That wire had been connected up by an Invisible Hand—by the hand of one who certainly knew the most vulnerable point of the machine. Teddy and Roseye both stood aghast at this latest revelation. Then, when I had disconnected the wire, I placed it with the little black incendiary disc upon the ground and connected up the wires to an accumulator from the car. In a moment the black substance shot into a fierce red flame which burned and spluttered with intense heat for fully five minutes. From the barn, a few minutes later, Theed emerged carrying a piece of the wire, evidently discarded by the intruder who
  • 41.
    had so swiftlyand so cunningly prepared another death- trap for me. A further hour we spent in making a second examination of the machine, and then having appointed to meet that evening at the old King’s Head, in G—, at seven o’clock, I climbed into the pilot’s seat and, with Teddy at my side, we shot forward and soon left the ground heading for the railway line which I knew would run from right to left across our track at Tonbridge. I was really glad to place Holly Farm behind me. It certainly was not a “healthy” spot, as far as we were concerned. The low-down cunning of our enemies had once more been revealed. Yet how I longed for Roseye to tell me the actual truth! Why did she so persistently refuse? What could she have to hide from me—the man who loved her so very dearly. We trusted each other. She had trusted her life to me in the air on many occasions—even on the previous night. Yet she remained silent. The day was bright and crisp, with a slight north-westerly wind and a few scudding clouds. Very soon, when we had risen to about four thousand feet—for I had determined to fly high again—I saw a big seaplane coming up from the coast. It passed us about four miles distant and then I gave over the dual controls to Teddy, so that he might get used to them ready for the crucial test when it must mean either destruction to a Zeppelin, or to ourselves. Teddy was a first-rate patriot. There was nothing of the milk-and-water type about him, and yet, at the same time, he was nothing of a lady’s man. He was always courteous, humorous, and charming with the fair sex, but he preferred
  • 42.
    to read andsmoke his rather foul briar pipe, than to go out of an evening into the glitter and clatter of London life. But we were friends—firm friends, and he was just as prepared and keen to take the risk as I was. We found Tonbridge quite easily. Below us what looked like a toy-train was puffing along towards Dover, leaving a white streak of steam behind. For a few minutes I made a short circuit over the town in order to find the line that ran across to Sevenoaks, and at last, distinguishing it, I made my way over that rather scattered place and then struck another railway line at a place marked upon the map as Fawkham, after which I soon picked out the shining river with Gravesend on one bank and Tilbury on the other. I glanced at the altimeter. We were 10,500 feet up. Below us all was misty in the valley of the river. Then over the brown land of Essex I sped forward until I again found another railway line at Brentwood and, following it, soon saw my landmark—one which I need not refer to here, for I have no desire to instruct enemy airmen. Nothing extraordinary had met my eye. I was used to the patchwork landscape. Then began a search for a convenient field in which to land. I came down from ten thousand to a thousand feet in long sweeping circles, examining each grass meadow as I went. The lower I came, the more easily could I distinguish the pastures and ploughed land and woods. A train was passing and I noted the direction of the smoke —most important in making a landing. Teddy at my side, as practised as I was myself in flying, had never moved. Through his big goggles he was gazing down, trying to decide upon a landing-place, just as I was.
  • 43.
    I banked fora moment. Then put her nose down and then, finding no spot attractive, climbed again. I did not want to land too near the town, for I had no desire to attract undue attention. I was trying to find a certain main road, for, truth to tell, I had been up very early that morning consulting my maps. On that main road were two or three farms in which I hoped I could shelter my machine, just as I had done at Holly Farm. I suppose we spent perhaps nearly half an hour in the air before, after critical examination, I decided to descend into a large park before a good-sized old Georgian house belonging, no doubt, to some county family. Parks, provided they have few trees, are always desired by the aviator as landing-places. Indeed, as I circled round I could plainly see that several figures, attracted by the heavy, roar of my engine, were standing outside watching us. Two minutes later I brought the machine round to the wind. Down went her nose—down, down. The air screamed about our ears. The earth rushed up to meet us, as it always seems to do. Truth to tell, by my own fault, I had had a nasty nose-dive, but I righted her and, touching the grass, managed to pull up dead. Teddy, who had been watching it all, never turned a hair. Only when I shut off the roar of the engine, he remarked:
  • 44.
    “By Jove! Devilishgood landing! That nose-dive was rather a nasty one, Claude—wasn’t it?” And, unstrapping himself, he hopped out and sought his cigarette-case from his hip-pocket, as was his habit. We were close against the big, rather ugly country house, therefore, leaving the machine, we went up and soon found its owner—a retired colonel of the usual JP type—hard on poachers when on the County Bench, I expect. Still, he welcomed us warmly and was, we found, quite a good sort. I asked him to take us aside, and he conducted us to the library, a fine old-fashioned room lined with brown-backed books. There I told him the truth—of what we were after. “Well,” said the white-haired old man, looking me up and down, “you seem a pretty keen young fellow, and your friend also. If you are over here on such a mission then I hope you will, both of you, consider yourselves my guests. I’ve a big barn beyond the stables where I can garage your machine quite well.” Then I told him of the trio who were on their way to the King’s Head, in G—. “I shall only be too delighted to be their host,” he replied at once. “I know Sir Herbert and Lady Lethmere well, but I don’t believe I’ve ever met their daughter.” Then he introduced his wife, a rather youngly-dressed woman, whose eyes were “made-up” and the artificiality of
  • 45.
    whose cheeks werejust a trifle too transparent. But artificiality seems fashionable to-day. We duly put the machine away into the barn and later, when we sat at tea in the drawing-room, the conversation naturally turned upon Zeppelins. Colonel Cator, for such we had found our host’s name to be, held rather sceptical views regarding the power of aeroplanes to combat airships, and he waxed distinctly humorous as we sat together. “There have been so many fables told us about aircraft,” declared the erect old man, “that one does not really know what to believe.” “There have been a good many improvements recently in aircraft of all sorts, so that most of the pre-war types have been already scrapped,” I said. “Yes, yes, I know,” exclaimed our host. “But what I object is to the fairy-tales that we’ve been told in the past—how we’ve been reassured.” “But does the past really affect the present very much?” I queried. “I contend that it does. We should have been told the truth,” he declared emphatically and, rising, he took from beneath a table a large scrap-book. Then, returning to his chair, he said: “I have here a cutting from The Times of March 20, 1913. I came across it only the other day. Listen—and I’ll read it to you, because it is most illuminating to you airmen.” And then he read to us as follows:—
  • 46.
    “Colonel Seeley, Secretaryof State for War, said yesterday: We have decided that the Army should have small dirigibles which could be packed up in boxes, put in motor-lorries or in ships, and sent wherever they are required. These we have got. These dirigibles, I say without hesitation—and all who understand the matter will agree—are superior to any other kind of portable airship. They have various mechanical advantages, which I do not wish to dwell upon, because those concerned believe the secret is our own, enabling them to rise more rapidly in the air, and enabling them, above all, to avoid having to part with hydrogen when they rise, and therefore there is no need for reinforcing the hydrogen when they fall. They have these advantages, which we believe are superior to those of any other nation.” Then, pausing, the colonel raised his eyes to mine, and, with a merry laugh, asked: “Now. What do you think of that for a Ministerial statement eh?” “Perhaps, instead of putting them in boxes, we might have had them put into paper bags, and distributed with pounds of tea?” suggested Teddy. “Why not?” “But I don’t see how it affects the present situation at all,” I argued. “We are surely much wiser now than we were three years ago.” “Well—let’s hope so,” laughed the colonel. “But that speech is full of grim humour—is it not?” And with that we were compelled to agree.
  • 48.
    Chapter Twenty Three. The“L39.” Having taken Colonel and Mrs Cator into our confidence, and they having invited Roseye to stay with them, we were all, on the following day, duly installed at Swalecliffe Park. Without delay I called upon the officer in charge of the listening-post—the whereabouts of which I do not intend to disclose—and, to my joy, found that he was a man named Moncrieff whom I had met many times at Hendon, and also at the club. Having told him of my intention to have a “go” at the next enemy airship that might come over, he readily promised that upon receiving the next alarm, he would make a point of ringing me up at Swalecliffe. Then, with the machine in readiness and already tested and re-tested, and also with a full petrol-tank, there was nothing further to do but to draw it out into the park each night, and await the alarm. It was on the first day of March when we had come down in Swalecliffe Park as strangers—on a Wednesday I remember —and the following days had been fully occupied with our preparations, while throughout each night Teddy and I, ready dressed for flight, sat in the colonel’s study wherein the telephone was installed. Thursday night passed quite uneventfully. During the earlier hours the colonel and Roseye sat with us, but the barometer being low, and the weather gusty, we had, even
  • 49.
    at ten o’clock,decided that no Zeppelin would risk crossing the North Sea. On Friday night the four of us played bridge till half-past four, the Theeds being, of course, on duty outside. We had the consolation of knowing that, though the Invisible Hand might be searching for us, it had not yet discovered our place of concealment. Each evening we tested the telephone —through the local exchange—out to the listening-post, and each evening Moncrieff, who was in charge, answered cheerily: “Don’t fear, old chap, I’ll give you a ring as soon as anything is going on.” Saturday, the fourth of March, was bright and warm, but just before sunset a sharp easterly breeze sprang up and, with a falling barometer, we knew that our vigilance would remain unrewarded. So again we played bridge until Roseye grew sleepy and then retired. Certainly we did not appear to meet with any luck. On Sunday morning we all went to the pretty little church of Swalecliffe, and in the afternoon I went out for a pleasant stroll with Roseye through the park and leafless woods. Again I pressed her to reveal to me what she knew regarding that mysterious woman who was in association with the fellow Eastwell. But once again she steadfastly declined to reveal anything. “No, no!” she protested. “Please don’t ask me, Claude.” “But surely I have a right to know!” I declared. “Your enemies are mine; and we are fighting them together. We
  • 50.
    have agreed tomarry, Roseye, therefore you may surely trust me with your secret!” I had halted at a stile before crossing our path leading into the wood, and, as I held her hand in mine, I looked straight into her big blue eyes. She drew a long breath, and her gaze wavered. I saw that she now relented, and that she was unable to refute my argument. I pressed her hand and, in a deep, earnest voice, urged: “Tell me darling. Do tell me?” Again her chest heaved and fell beneath her furs. “Well, Claude. It’s—it’s a strange story—as strange as any woman has ever lived to tell,” she said at last, with great hesitation and speaking very slowly. “On that morning when I left I received a letter purporting to come from you, and urging me to meet you in secret on the departure platform of the Great Northern station at King’s Cross. Naturally, much puzzled, I went there, wondering what had happened. While waiting, a woman—the woman you have seen—came up to me and told me that you had sent her—that you wished to see me in secret in connexion with your invention, but that you were in hiding because you feared that some spies intended to obtain knowledge of the truth. She said that there were enemy spies on every hand, and that it would be best to go over to the hotel, and there wait till night before we went North to Grantham, whither you had gone.” “Grantham!” I echoed. “I’ve not been in Grantham for years.”
  • 51.
    “But I believedthat you were there, so plausible was the woman’s story,” she replied. “We left at night, travelling in a first-class compartment together. On the way, I suddenly suspected her. Somehow I did not like the look in those strange eyes of hers, and I accused her of deceiving me. Indeed, while dozing, I had seen her carefully take my chatelaine, put something into it, and drop it out of the window. We were in a tunnel, I believe.” “Then it was that woman who put the cipher-message into your card-case!” I exclaimed. “Yes, go on.” “Yes,” she replied. “I sprang up, and tried to pull the communication-cord as we came out of the tunnel, but she prevented me. She pushed a sponge saturated with some pungent-smelling liquid into my face, and then I knew nothing more until I found myself in a small room in a cottage somewhere remote in the country.” “Then you were detained there—eh?” “Yes. Forcibly. That awful woman tried, by every means in her power, to force or induce me to reveal the details of the experiments which you and Teddy were making at Gunnersbury. But I refused. Ah! how that hell-fiend tortured me day after day! “She nearly drove me mad by those fearful ordeals which, in a hundred ways, she put upon me—always promising to release me if I would but reveal details of what we had discovered. But I refused—refused always, Claude—because I knew that she was an enemy, and victory must be ours if I remained silent. Days—those terrible days—passed—so many that I lost count of them—yet I knew that the woman with the cruel eyes of a leopard had dosed me with some drug that sapped my senses, and she held me irrevocably in
  • 52.
    her power, promptedno doubt by somebody who meant to work evil also upon you. In the end I must have lost my reason. I think she must have given me certain drugs in order to confuse me as to the past. Then, one day, I found myself in the town of Grantham, inquiring for the station. I was in a maid’s clothes, and in them I eventually returned to you. And you—Claude—you know all the rest.” And she burst into a torrent of tears. “Yes,” I said slowly. “And that blackguard Lionel Eastwell is the man who has directed all this intricate and dastardly intrigue against us.” Then I took my love into my arms, and pressing her to me, soothed her tears with my passionate kisses. What she had revealed to me amazed me. In the evening, just after the Sunday-night supper, Benton, the fat old butler, entered the drawing-room and, approaching me, said: “Mr Moncrieff is on the telephone, sir.” I sprang up with alacrity and, a few seconds later, spoke to my friend at the listening-post. “You there, Munro?” he asked. “We’ve just had a message to say that three Zeppelins are crossing the North Sea in the direction of the Norfolk coast.” “Right!” I said, and shut off at once. There was no time to lose. In a moment I told them of the alarm. Without much delay Teddy and I slipped into our air-kit, while Theed, with the
  • 53.
    machine wheeled outinto the park, reported that all was in readiness. I met Roseye in the corridor above the central staircase of the great old-world house, and there kissed her fondly. “For your dear sake I go, and for the sake of my King and country!” I whispered. “Good-bye, my darling. Keep a stout heart until you hear of me again!” “But—oh!—oh!—I fear, Claude!” she cried anxiously, clinging to me. “No, my darling. We must, to-day, all make sacrifices. There must be no fear. I shall be back with you to-morrow.” And then again I kissed her and disengaged those loving, clinging arms about me. Five minutes later Teddy and I were away in the air. The night was dull and overcast with a promise of clearing— yet bitterly cold. Of course with our big engine roaring we could hear nothing of the enemy’s approach, but I deemed it wise to rise high and, at the same time, to follow the railway line from Colchester towards London, because that, no doubt, was the route which the airships would follow. The alarm had been given, trains being darkened and brought to a standstill, station and signal-lights extinguished and towns blotted out, I quickly lost sight of the railway track and could only go very slowly to save petrol in case of a chase, and guide myself by my compass.
  • 54.
    From a townsomewhere on the coast I could see the long scintillating beams of a searchlight striking across the dark night sky, first directed in one quarter and then in another. I think it must have been the searchlight on the coast at T—. I saw Teddy was busy adjusting the Lewis machine-gun at his side as we climbed rapidly in the pitch darkness. The engine raced and hummed and the wind shrieked weirdly around us. I switched on the bulb over the instruments, in order to look at my altimeter, but so dark was it that the light got into my eyes and I was compelled to shut it off again. I flew in a wide circle at first, steadily climbing until the few faint twinkling lights below had disappeared entirely. We were getting nearer and nearer the Zeppelin altitude. Ah! how the engine throbbed and roared. Suddenly something black shot up close to me, rushing on as quickly as an express train. So suddenly did it rise up against me, that it gave me quite a start. It seemed a great, unholy thing, and quite shapeless. It was another aeroplane, like ourselves, out to destroy the enemy airship with bombs. And by Jove! we narrowly avoided a nasty collision. A second later we heard the loud report of a gun. Our anti- aircraft gunners had spotted their quarry somewhere in the vicinity. A moment afterwards upon our left, straight before us, two long beams of searchlight shot out, and then a sharp volley from the guns. They were possibly five miles distant, and in the direction of London—somewhere near Brentwood I thought.
  • 55.
    Bang! bang!—bang! wecould hear, even above the throb of our powerful engine. Teddy turned on the second engine, and then opened up the searchlight, sweeping it around before us. But we could see nothing save some thin filmy clouds. Suddenly the searchlights from below went out, and the guns ceased. With one eye upon the altimeter I peered over, hoping to pick up some landmark, but I could find absolutely none. That a Zeppelin was in the vicinity was certain. I tried to keep as cool as I possibly could, but I confess that at that moment it was difficult. I cruised about, knowing that I was now nearing the London area. Suddenly, deep below, yet some miles ahead, I saw a blood-red flash. The Zeppelin had dropped a bomb! Again I switched on the little light, and a glance at my altimeter showed that I was up eleven thousand feet, therefore I pushed straight along in the direction of that red glare. That it was an incendiary one I saw, because the flare continued far down in the misty workaday world below. The Zeppelin was executing its evil work upon the harmless civilian inhabitants. I craned and peered around on all sides, but could see nothing else—only the glare from the incendiary fire. The night was rapidly growing brighter, and we could see the stars. Again we heard a violent cannonade, and once
  • 56.
    more half adozen beams of searchlights swept the sky from several points evidently much nearer to London. More than once the searchlights picked us up and examined us with suspicion, blinding us with their glare the while. Once more from below there came up two loud detonations —high explosive bombs—yet we could see no Zeppelin, though we peered into the darkness again as soon as the searchlight left us. Blinded by the glare, I had banked a little too steeply, and nearly had another bad nose-dive. Teddy noticed it, and said something, but what it was I could not hear for the roar. That an enemy airship was about, and that it had dropped incendiary bombs was proved by the three or four red glares we could distinctly see beneath us. No doubt the Zeppelin was moving fast, dropping her bombs preparatory to rising and escaping beyond the zone of our anti-aircraft guns. I rose higher, but still no sign of it. Apparently the searchlights, having once located it, had again lost it, for once more all the guns were silent. I began to lose heart. How horribly cold it was! I was now over London, unless I was much mistaken. Several other of our bomb-dropping aeroplanes were circling below me, also unable to find the Zeppelin. Suddenly Teddy gave me a sharp nudge and pointed upward. I glanced in the direction he indicated, and there saw the great long dark hull of the airship hovering quite near us. We were then over eight thousand feet up, and the airship was perhaps another thousand feet higher. I could
  • 57.
    distinguish its twogondolas, and as we passed near its stern its fins and planes were now plainly silhouetted against the bright, steely sky. With all speed possible I shot upward, but apparently the commander of the Zeppelin had discovered us, while at that very same moment a searchlight from somewhere below picked him up and revealed him, a huge silvery object, upon the side of which was painted in black a large iron- cross, the Hun badge of frightfulness, together with initial and number “L39.” Scarcely had I become aware of the close proximity of the enemy when I saw a little spurt of red flare from the forward gondola. It continued for several moments, and I knew that it was a machine-gun spitting forth its leaden hail upon us. Therefore I drew away and rose still higher, while, next second, the propellers of the monster airship began to whirr and it started away, nose upward and due east, evidently upon its homeward journey. Unfortunately the men manning our searchlights below kept one of their beams upon us as well as another upon the Zeppelin, and I must confess that both Teddy and I, in our excitement, consigned them to a place with an atmosphere slightly warmer than the one we were at that moment experiencing. It seemed as though the anti-aircraft gunners, knowing the airship to be now out of range, were seized by a sudden curiosity to see what we were doing chasing the Zeppelin away as we gradually rose above it. Ah! Shall I ever forget those exciting moments! Time after time the machine-gun on the monster airship fired upon us, but I was flying in such a manner that to hit us would, I
  • 58.
    knew, be difficult.Yet just then a stray bullet struck one of my planes and went through it, while a second later another tore through the casing of the fuselage. The commander of the Zeppelin thought, no doubt, that our intention was to rise and drop a bomb upon him, and he was now travelling very quickly in order to try and outpace us. In this, however, he did not succeed. How far we travelled I have no idea. In those moments I lost all sense of time and of distance. I only know that, though so high, I could distinguish the Thames with its few dotted lights about, though we were rapidly leaving London behind. We were passing over Essex, for I could plainly see the Thames widening upon my right, and I was gradually overhauling the enemy. At that moment I steadied myself, for I knew that the smallest slip would mean death to us both. At signal from me Teddy—who had already had the dynamo running for some time—placed his hand upon the switch which controlled the unseen, but deadly current. Slowly I crept nearer and nearer. Four thousand yards off— three thousand—another spurt—then I judged I was only two thousand yards away. Yet try how I would, I could get no nearer. Again I set to work and, letting out my roaring engines to their full power, I slowly decreased the space between the fleeing monster and myself, Teddy still awaiting my signal. Next instant I saw yet another spurt of fire from the rear gondola of the Zeppelin, and felt a hot, burning sensation in my forearm.
  • 59.
    Then I knewthat I had been hit! I nudged Teddy, and he nodded. He understood and with the end of the box in which was the large, lens something like a camera, directed full upon the enemy, he pulled over the switch. The result was appalling. Next instant there was a blinding flash as the electric sparks flying from point to point all over the metal framework of the Zeppelin ignited the hydrogen; a huge red burst of flame came from the centre of the great airship, and following it was a terrific explosion, the frightful force of which would have turned us completely over had I not been prepared. I swerved quickly, in order to get out of the vicinity, for the danger at that instant was very great. Then, as I glanced aside, I saw the huge monster plunge down to earth, ablaze and flaring like a huge torch. A second terrific explosion of bombs occurred when it reached the ground, and the whole country-side, shaken as though by an earthquake, became instantly illuminated for miles around. Appalled at the sight, and yet relieved of the terrible tension, we both looked down and found that the enemy airship had, fortunately, fallen upon some flat land without houses—a wide, lonely marsh it appeared to be. I at once dropped to a thousand feet and then, with a final glance at our work of destruction, turned tail and set about finding a landmark.
  • 60.
    It was difficult,but I discovered one at last and, half an hour later, finding old Theed’s flares in Swalecliffe Park, gently planed again to earth. Need I detail the congratulations showered upon Teddy and myself; of Roseye’s delight, or of her parent’s enthusiasm next day? Indeed, it seemed as though the world about us —our little world who knew the truth of our night-exploit— had gone mad with joy. On the following day I reported personally to the authorities, and afterwards had a long conference with certain high officials, who listened most intently to the description of my apparatus, and who heartily congratulated both Teddy and myself. That same night, indeed, my description being but superficial, experts came down with me to Swalecliffe, where the apparatus was thoroughly and satisfactorily tested, and declared to be an air-defence of the highest importance, and one which must soon prove our superiority against the Zeppelin menace. It was, I felt, my duty to reveal in the proper quarter the dastardly attempts made upon all three of us by our enemies, directed by the man Eastwell, who I feared knew something of our secret, whereupon orders were at once given to the Special Branch of Scotland Yard for his arrest under the Defence of the Realm Act. Two officers ascended to his rooms in Albemarle Street an hour later, but when he learnt they were detectives he dashed into his bedroom and, without hesitation and before they could prevent him, shot himself.
  • 61.
    Welcome to ourwebsite – the ideal destination for book lovers and knowledge seekers. With a mission to inspire endlessly, we offer a vast collection of books, ranging from classic literary works to specialized publications, self-development books, and children's literature. Each book is a new journey of discovery, expanding knowledge and enriching the soul of the reade Our website is not just a platform for buying books, but a bridge connecting readers to the timeless values of culture and wisdom. With an elegant, user-friendly interface and an intelligent search system, we are committed to providing a quick and convenient shopping experience. Additionally, our special promotions and home delivery services ensure that you save time and fully enjoy the joy of reading. Let us accompany you on the journey of exploring knowledge and personal growth! textbookfull.com