Mobile Application Development Using the Reactivex Framework
Total Page:16
File Type:pdf, Size:1020Kb
Masaryk University Faculty of Informatics Mobile application development using the ReactiveX framework Bachelor’s Thesis Robin Křenecký Brno, Spring 2018 Masaryk University Faculty of Informatics Mobile application development using the ReactiveX framework Bachelor’s Thesis Robin Křenecký Brno, Spring 2018 This is where a copy of the official signed thesis assignment and a copy ofthe Statement of an Author is located in the printed version of the document. Declaration Hereby I declare that this paper is my original authorial work, which I have worked out on my own. All sources, references, and literature used or excerpted during elaboration of this work are properly cited and listed in complete reference to the due source. Robin Křenecký Advisor: RNDr. Jaroslav Škrabálek i Acknowledgements I would like to thank the supervisor of my bachelor’s thesis, RNDr. Jaroslav Škrabálek, for his helpful attitude, valuable insights, and his contribution to my thesis. iii Abstract The objective of this bachelor’s thesis is to introduce reactive program- ming and to examine ReactiveX library, examine its application in mobile application development and evaluate advantages and disad- vantages of its usage on a real world example. iv Keywords Reactive programming, ReactiveX, iOS, Android, RxSwift, Swift, ... v Contents 1 Introduction 1 1.1 Thesis structure ........................2 2 Mobile application development 3 2.1 Mobile development platforms ................3 2.2 Types of mobile applications .................4 2.3 Programming languages used in mobile application devel- opment ............................4 2.4 Design patterns used in mobile application development ..5 2.4.1 Delegate pattern . .5 2.4.2 Observer pattern . .6 2.4.3 Iterator pattern . .7 2.5 Architectural patterns used in mobile application development 8 2.5.1 Model-View-Controller . .8 2.5.2 Model-View-ViewModel . .9 3 Functional Reactive Programming 11 3.1 Brief history and development of FRP ............ 11 3.1.1 Classical FRP . 11 3.1.2 Real-Time and Event-Driven FRP . 12 3.1.3 Arrowized FRP . 12 3.2 Reactive manifesto ...................... 13 3.3 Advantages of FRP ...................... 15 3.4 FRP in mobile application development ........... 16 4 ReactiveX framework – an in-depth look 17 4.1 Brief history of the ReactiveX framework ........... 17 4.2 Overview of the ReactiveX framework ............ 17 4.3 Foundation of ReactiveX ................... 18 4.3.1 Observable . 18 4.3.2 Scheduler . 21 4.3.3 Operators . 21 4.3.4 Single . 24 4.3.5 Subject . 25 4.4 ReactiveX in mobile application development ........ 26 4.4.1 Advantages . 26 vii 4.4.2 Disadvantages . 26 4.4.3 Major iOS frameworks . 27 4.4.4 Major Android frameworks . 27 4.4.5 Major multiplatform frameworks . 28 5 Practical demonstration 29 5.1 Application structure ..................... 29 5.1.1 Dashboard screen . 30 5.1.2 Tasks screen . 31 5.1.3 Task detail screen . 31 5.1.4 Search screen . 32 5.2 Used technologies and architecture .............. 33 5.2.1 Programming language . 33 5.2.2 Tools . 33 5.2.3 Frameworks . 34 5.2.4 External services . 36 5.2.5 Architecture pattern . 36 5.3 Implementation ........................ 37 5.3.1 Implementation without ReactiveX framework . 38 5.3.2 Implemetation with ReactiveX framework . 38 5.4 Evaluation criteria ...................... 39 5.4.1 Objective criteria . 39 5.4.2 Subjective criteria . 40 5.5 Criteria evaluation ...................... 40 5.5.1 Objective criteria evaluation . 40 5.5.2 Subjective criteria evaluation . 42 5.5.3 Summary of criteria evaluations . 45 6 Conclusion 47 Bibliography 49 A Code snippets 57 A.1 ViewController – ViewModel communication ........ 57 A.1.1 ViewController – ViewModel communication without ReactiveX . 57 A.1.2 ViewController – ViewModel communication with ReactiveX . 58 viii A.2 Address searching ....................... 59 A.2.1 Address searching without ReactiveX . 59 A.2.2 Address searching with ReactiveX . 60 A.3 Timer creation ......................... 61 A.3.1 Timer creation without ReactiveX . 61 A.3.2 Timer creation with ReactiveX . 61 A.4 Image downloading ...................... 62 A.4.1 Image downloading without ReactiveX . 62 A.4.2 Image downloading with ReactiveX . 63 A.5 Tab Bar interaction ...................... 64 A.5.1 Tab Bar interaction without ReactiveX . 64 A.5.2 Tab Bar interaction with ReactiveX . 65 ix List of Tables 5.1 Performance tests results 41 5.2 Code analysis tests results 42 xi List of Figures 2.1 UML diagram of the delegate pattern. 6 2.2 UML diagram of the observer pattern. 7 2.3 UML diagram of the iterator pattern. 7 2.4 Model-View-Controller [24] 8 2.5 Model-View-ViewModel [24] 9 3.1 Reactive traits [32] 14 4.1 Marble diagram for map operator [50] 22 5.1 A use case diagram of the demonstrative application. 29 5.2 Screenshot of the dashboard screen. 30 5.3 Screenshot of the tasks screen. 31 5.4 Screenshots of task detail and address selection screens. 32 5.5 Screenshots of the search screen. 33 5.6 Model-View-ViewModel-Coordinator [83] 36 5.7 Screenshot of the project folder structure 37 xiii 1 Introduction Mobile applications are continually gaining in complexity these days, and there are three main reasons behind it [1]. One reason is that it’s not just smartphones anymore that are considered to be mobile devices. The mobile device catalog spans smartphones, tablets, phablets, convertible laptops, and wearables. Supporting all these devices is necessary in order to succeed in the mobile application industry. There is also a near-constant pace of upgrades of operating systems (OS) with little notice in advance. That was not a factor in the desktop environment where OS updates were expected every two to three years. Nowadays a major update takes place every six to twelve months. The final reason is the pressure for always-on availability and quick application responses. That means that there is a very little room for bugs and errors in mobile application development. The rising complexity means that developing a feature-rich mobile application has become a very demanding task. To create a responsive and robust app developers have to deal with a multitude of concurrent tasks like user input handling, playing audio, or making networking calls. That can cause a lot of trouble. The ReactiveX framework aims to help developers with these de- manding tasks by solving the issues related to asynchronous program- ming. In a mobile application development, ReactiveX is one of the hottest topics today as a presentation about it is given at almost every international conference or even a local meetup [2]. The goal of this thesis is to introduce functional reactive program- ming and to examine ReactiveX framework, specifically focusing on its application in mobile application development, and comparing the development of a mobile app with and without the ReactiveX framework. 1 1. Introduction 1.1 Thesis structure The thesis is divided into four parts. The first part describes mobile application development froma technological point of view. It focuses on used technologies such as programming languages and design patterns. The second part describes Functional Reactive Programming, its history, advantages and its use in mobile application development. The third part provides an in-depth look into the ReactiveX frame- work, describes its history, elements of its interface and its use in mobile application development. Finally, in the fourth part, a comparative practical demonstration of the ReactiveX framework usage is presented and evaluated. 2 2 Mobile application development Mobile application development is the set of processes and procedures involved in writing software for small, wireless computing devices such as smartphones or tablets [3]. It has been gaining in popularity as mobile devices become more and more important1. Today, over 20 % of all developers work as mobile application developers while in 2013 it was just above 7 % [5, 6]. This chapter introduces available mobile development platforms, discusses different approaches to mobile application development, and also deals with the use of programming languages and design and architectural patterns. 2.1 Mobile development platforms As of today, there are two leading platforms for which mobile apps can be developed: Android and iOS. Together they cover over 99.5 % of total market share [7]. • Android An open-source mobile operating system developed by Google and unveiled in 2007 [8]. It is based on a modified version of the Linux kernel and it is designed primarily for touchscreen mobile devices. Google has also developed versions of Android for televisions, cars and wrist watches. Nowadays it is the most commonly used operating system in mobile devices2. • iOS A mobile operating system created and developed by Apple exclusively for its hardware. It was originally unveiled in 2007. As of today, it powers iPhone, iPad and iPod Touch.[9] 1. For example, in 2017 63 % of web traffic came from mobile devices in US[4]. 2. With over 87 % of total market share [7] 3 2. Mobile application development 2.2 Types of mobile applications In general, there are three types of mobile applications: native, hybrid and web [10]. • Native applications Native apps are developed for a single mobile operating system exclusively. They have to be developed using tools required by the specific platform, such as programming language or development environment. These apps are usually harder to build, but in return, they offer higher performance and better user experience as they use the native device user interface. • Web applications Web apps consist of a web page that is optimized for a mobile device, and they use an internet browser to run. Their advantage is that they don’t need to be downloaded and the development is easier and faster, but their usability is limited to the web browser. • Hybrid applications Hybrid apps are a combination of native and web applica- tions.