Masaryk University Faculty of Informatics

Cross-platform Mobile Application Development Comparison

Master’s Thesis

Bc. Michal Zopp

Brno, Fall 2020 Masaryk University Faculty of Informatics

Cross-platform Mobile Application Development Comparison

Master’s Thesis

Bc. Michal Zopp

Brno, Fall 2020 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.

Bc. Michal Zopp

Advisor: RNDr. Vít Rusňák, Ph..

i Acknowledgements

I would like to thank my advisor RNDr. Vít Rusňák, Ph.D. for his guidance, friendly approach and valuable advice during the creation of the applications as well as this thesis. I would also like to thank the professors and teachers of this faculty that gave me the broad outlook in the field of computer science.

ii Abstract

This thesis focuses on comparing mobile application development approaches from development, empirical, and user experience stand- points. It compares NativeScript and React Native frameworks, which are two common JavaScript frameworks for developing cross-platform applications. Finally, it compares these cross-platform development approaches with native development for iOS devices using the Swift programming language.

iii Keywords

Android, iOS, mobile application, React Native, NativeScript

iv Contents

1 Introduction 1

2 SkautIS – Information System of Junák 3 2.1 SkautIS Agendas ...... 3 2.2 SkautIS API and Web Services ...... 4 2.3 Testing Environment ...... 6

3 Mobile Application Development 7 3.1 Native Approach ...... 7 3.1.1 Native iOS Application Development ...... 8 3.1.2 Native Android Application Development . . . 12 3.2 Cross-platform Application Development ...... 16 3.2.1 NativeScript ...... 16 3.2.2 React Native ...... 19

4 Current NativeScript Mobile Application 24 4.1 Design ...... 24 4.1.1 Project Structure ...... 24 4.1.2 Agendas ...... 26 4.1.3 State Logic ...... 27 4.2 Issues ...... 28 4.2.1 Navigation ...... 28 4.2.2 Empty State ...... 29

5 Implementation of the React Native Mobile Application 32 5.1 Design ...... 32 5.1.1 Project Structure ...... 33 5.1.2 Agendas ...... 34 5.1.3 Navigation ...... 34 5.2 Implementation Details ...... 35 5.2.1 NPM Libraries ...... 35 5.2.2 API Calls ...... 36 5.2.3 Empty state and error response ...... 37 5.3 Future Improvements ...... 38 5.3.1 Application Reset ...... 38 5.3.2 Edge API Cases ...... 39

v 6 Implementation of the Swift Mobile Application 40 6.1 Design ...... 40 6.1.1 Project Structure ...... 41 6.1.2 Agendas ...... 42 6.1.3 Navigation ...... 42 6.2 Implementation Details ...... 43 6.2.1 Screen Implementation ...... 43 6.2.2 Charts ...... 44 6.2.3 API Calls ...... 45 6.3 XML Parsing Barrier ...... 46

7 Comparison and User Evaluation 48 7.1 Development Process Comparison ...... 48 7.1.1 Project Preparation ...... 48 7.1.2 Application Development ...... 53 7.1.3 Lessons Learned ...... 57 7.2 Empirical Comparison ...... 59 7.2.1 Project Size ...... 60 7.2.2 Application Size ...... 61 7.2.3 Clean Build Time ...... 63 7.2.4 Clean Start Time ...... 65 7.2.5 CPU and Memory Usage ...... 67 7.2.6 Lessons Learned ...... 70 7.3 Survey ...... 72 7.3.1 Participants ...... 72 7.3.2 Survey Structure ...... 73 7.3.3 Tested Tasks ...... 74 7.3.4 Overall Evaluation ...... 79 7.3.5 Lessons Learned ...... 80

8 Conclusion 82

Bibliography 84

A List of Electronic Attachments 87

B Installation Manual for Developed Applications 88

C Conducted Survey 89

vi D Charts From the Conducted Survey 94

vii 1 Introduction

Mobile development has become prevalent in recent years due to an increasing number of mobile users across the globe [1]. Although many corporations and independent projects are trying to enter the mobile operating system market, to bring a better experience to its customers, iOS and Android are the only two market leaders. Together they have 99.45% of mobile operating system market share with 72.92% and 26.53% respectively [2]. It seems that nowadays there is a mobile application available for anything we can think of. Application that calculates how high users can throw their phone (S.M.T.H.1), applica- tion that lets them control a bread slice (I am Bread2) or even a dating application for their pets (My Pet Dating3). These applications may be useless, in their essence. However, it paints the picture that the development process has become more accessible to people as these applications could be created as a joke and not have real-world usage. Junák – Czech Scouting is the largest recognised scout organisation in the Czech Republic. Its roots can be traced back to 1914. Its primary role is to organise and strengthen its community relationships, espe- cially for youth members. Junák also hosts several events throughout the year that are organised on many levels, such as local, regional, nationwide or even worldwide. For members of Junák, there exists an information system which helps them to access and manage important information about the organisation, its members and events. This sys- tem is called skautIS, and it is available at https://www.is.skaut.cz. Furthermore, a recent project Pocket skautIS brings some of its core features right into its members’ mobile devices. The application is available for download in the Google Play and App Store. This thesis aims to compare cross-platform development approaches and native development approach regarding technical specifications and empirical evaluations. Instead of some generic tutorial applica- tion, we have chosen the Pocket skautIS application because it presents many useful features to its users and has an active user base. We will

1. https://play.google.com/store/apps/details?id=com.carrotpop.www. smth&hl=en&gl=US 2. https://apps.apple.com/us/app/i-am-bread/id946903436 3. https://apps.apple.com/us/app/my-pet-dating/id1489555719

1 1. Introduction

be comparing the current Native Script cross-platform development approach used for the Pocket skautIS application with another pop- ular cross-platform development approach called React Native. We only focus on Android and iOS platforms (although mentioned cross- platform approaches can build to even more platforms). We have also chosen a pure native development approach for iOS platform using the Swift programming language and native iOS frameworks. These applications need to mimic the user interface and the be- haviour as close as possible to the current Pocket skautIS application in order for us to focus only on the differences. These two new appli- cations need to be implemented first in order for us to compare our experiences with the given development approach thoroughly. We have also conducted a survey that required the participant to install the current Pocket skautIS application and the newly developed ap- plication using React Native on their device. They were given a set of tasks resembling a common application use for the average user and questions surrounding the differences between the applications. In Chapter 2, we will present the current state of skautIS, what it offers to its users and the developers. Details for development ina native environment and the cross-platform development approaches of NativeScript and React Native are described in Chapter 3. Chapter 4 talks about the current Pocket skautIS application in more detail, espe- cially the code design logic used in the project. Next, Chapter 5 states implementation details for the cross-platform application explicitly made for this thesis. Chapter 6 discusses the design and implementa- tion detail for the iOS mobile application developed using the Swift programming language. This thesis’s core is in Chapter 7, where we introduce the development process comparison, our empirical compar- ison between NativeScript, React Native, and native Swift development approaches and the conducted survey. Finally, Chapter 8 concludes this thesis and all of the studied development approaches and gives a recommendation when choosing a mobile application development approach.

2 2 SkautIS – Information System of Junák

Junák - Czech Scouting with its 67 000 members is the biggest non- governmental organization for youth education in the Czech Republic. The organization has a hierarchical structure that follows the territorial- administrative arrangement in the Czech Republic. A scout troop is a base educational group. On average, it consists of 15 to 30 mem- bers, but bigger ones are no exception. Several troops form a scout unit that provides management services and facilities to its members. Units are organized in scout districts and scout regions. To simplify the organization management, Junák uses an information system skautIS. Even though anybody can create an account within skautIS, the full access will only be granted after the account is verified by troop or unit leaders. Many of the functionalities within skautIS are only available to users with specific roles that the user’s account has to have in order to access such functionality. In this chapter, we briefly present the skautIS information system and its main agendas. Next, we discuss its web services API (Applica- tion Programming Interface) and the testing version of skautIS, used for the development purposes.

2.1 SkautIS Agendas

SkautIS started as a system for simplifying the registration process of Junák’s members over a decade ago and is continuously being developed ever since. Currently, it contains multiple agendas including unit manage- ment, events, quality assessment, grants or benefits and many others. For the purpose of this thesis, we will only talk in more detail about the agendas implemented in the mobile Pocket skautIS application. These agendas are Profile, Unit and Services. Profile agenda contains user profile information and his/her avail- able skautIS roles. Every user can also look up other people in the skautIS environment here, either by searching his unit or the scout directory. Although these pieces of information can be found in the skautIS web application under one agenda, for the mobile application, they are located in two different sections. User information is located

3 2. SkautIS – Information System of Junák

in the Profile section, and searching for people is located in the People section. Unit agenda provides information about the user’s unit. This in- formation depends on what role the user currently has selected, as one user can be a member of more than one unit at a time. This unit information includes general information about units such as name, postal address, members in functions for unit and other related units (upper and lower). This agenda can be found in the Unit section of the mobile application.

Figure 2.1: Unit agenda in the testing environment of skautIS.

The last agenda implemented in the mobile application is Services. The user can view usage statistics of his/her phone number registered in the Scout Telephone Service, book scout bases (cottages or club- houses for rent), or borrow various tools and properties offered by other units (e.g., tools, climbing equipment, or big tents).

2.2 SkautIS API and Web Services

SkautIS has its API (Application Programming Interface) available publicly at the URL: https://ws.skautis.cz/. It enables developers

4 2. SkautIS – Information System of Junák

to integrate and use skautIS data in their applications. However, it is necessary to register and obtain a unique API key. The complete list of web services is available at https://test-is. skaut.cz/JunakWebservice/. The web services are categorized in agendas and together form the back-end services for the entire in- formation system. One of the more notable categories, which most users interact with, are OrganizationUnit, UserManagement, Message, Events and Telephony. The web services implement WSDL (Web Service Description Lan- guage), which acts as an interface and descriptive language of the offered services. The communication messages use SOAP (Simple Object Access Protocol), which is strictly defined, more robust and has good support for other standards (such as WSDL) [3]. The SOAP is a type of XML (Extensible Markup Language). The messages are sent over HTTPS (HyperText Transfer Protocol Secure). The HTTPS POST requests encapsulate critical information such as a token or user id and query. The server responds to these requests with a SOAP response with a predefined response structure (or an error message) based on such given parameters. The SOAP objects and their properties are encapsulated into SOAP:Body.

1 2 3 guid 4 int 5 6

Figure 2.2: Example of a SOAP:Body request for user detail.

In order for the server to respond, we must send a request first, which contains userDetailInput object structure with properties such as ID_Login and ID (see Figure 2.2). An example response for such a request is shown in Figure 2.3. We can see that the response contains an object UserDetailResult with properties such as ID, UserName, ID_Person and others. After such response, we typically parse this data into an object later used for application behaviour determination or data presentation.

5 2. SkautIS – Information System of Junák

1 2 3 int 4 . 5 . 6 . 7 string 8 int 9 10

Figure 2.3: Example of a SOAP:Body response to user detail request.

2.3 Testing Environment

Since the production instance of skautIS contains sensitive user data, there is a clone instance, which offers equal capabilities in terms of API but provides dummy data instead. The Test skautIS environment is used mainly for user training and development purposes, which is also the case for this thesis. To log in to this test environment, we can either create an account or use one of the existing accounts available at https://napoveda.skaut. cz/skautis/testovaci. As the same server logic also applies to this testing server, if we create an account we also have to be assigned a role in order to see the data. Because of this, it is recommended to use the already mentioned testing accounts. When it comes to application development, one of the most help- ful tools is testing the interface, available at https://ws.skautis.cz/ testovani. With this form, one can quickly identify the right mes- sage parameters and reduce the time needed for message debugging. The main problem with the skautIS API calls is the lack of message documentation.

6 3 Mobile Application Development

There are many ways to develop a mobile application. We can divide the development approaches into three main categories: native, hy- brid and cross-platform. In our work, we focus on cross-platform and native development approach. The platform developers prefer native development as it has access to all of the available features provided by the given platform as well as an efficient app lifecycle. The main advantage of cross-platform development is its single code base, that can be used for to generate an mobile application on supported platforms by the framework. It also outperforms the hybrid approach as it uses native platform rendering capabilities instead of rendering capabilities of a web browser provided by the platform, in case of hybrid ones. As such, cross-platform applications provide comparable efficiency (at least in theory) to native ones written in Objective-C/Swift (iOS) or /Kotlin (Android OS). There are also PWA (Progressive Web Applications) which are considered only a browser wrapper and not a standalone application. Because of this, it suffers from the browser rendering deficiency. There are also some limitations regarding accessing various mobile sensors, which may not be available on some devices. Another downside is that it does not have good compatibility with iOS devices as it lacks the proper platform support, like native or cross-platform approaches have. In the reminder, we focus on the native and the cross-platform ap- proaches in more details, presenting their core features, development and technology stacks.

3.1 Native Approach

The native approach means developing with tools and programs de- signed (or endorsed) by the platform developers. For example, Ap- ple’s preferred programming languages are Objective-C and Swift. The company not only provides the compilers but the whole ecosystem for developers including the Xcode1 IDE (Integrated Development

1. https://developer.apple.com/xcode/

7 3. Mobile Application Development

Environment) and the whole pipeline for testing (TestFlight) and publishing (Apple Developer Console) the applications. Similarly, the native approach for Android application develop- ment includes Android Studio2 and supports Java and Kotlin pro- gramming languages. There are ways to get around using the endorsed programs. For example, Apple allows us to download Xcode command-line tools that let us bypass the native IDE (integrated developing environment) and enable programming primarily through the command line. An- droid suggests using JDK (Java Development Kit), Android SDK and Android SDK Platform for command line usage.

3.1.1 Native iOS Application Development

Objective-C is a programming language adopted by Apple in the year 1996. This was because Apple acquired NeXT for the purpose of using its operating system on their computers. Apple slowly but surely pushes Objective-C out of the picture nowadays. The programming language is still supported, but there is more emphasis on native development using Swift3, which was introduced in 2014. Objective-C and Swift can co-exist in the same project, but Swift has many syntax friendly features and improvements over Objective-C.

Swift Swift is an open-source programming language developed by Apple, known primarily as a language used for creating applications and software for their products. It was developed as a replacement for Objective-C due to its lack of modern language features. Some of Swift’s features were naturally influenced by Objective-C, such as dynamic dispatch or late binding [4]. Although Swift was designed to be comparable in performance to C-based languages, it also has a big emphasis on the safety part of the language. For example, variables are always initialized before use, arrays are checked for overflow and memory is managed automati- cally [5].

2. https://developer.android.com/studio 3. https://swift.org/

8 3. Mobile Application Development

One of the safety features of Swift is its use of nil notation. Objects with a value of nil cannot access its properties and methods. This will result in a compile-time error. However, Swift has a feature known as optionals. If we use a nil object, it forces us to indicate the compiler (with symbols ? and !) that we are confident and understand the behaviour of such action.

Xcode As mentioned, Xcode is the primary IDE for developing software for all Apple devices and operating systems (macOS, tvOS, watchOS, iPadOS). Xcode supports many popular programming languages such as C++, Java, Python but mainly Objective-C and Swift. It also has an integrated source code management (version control) based on Git4, profiling and debugging features, which allows the developer to control his source version from user interface and see the changes right in the code files. Xcode offers many features for its native development projects that may not be provided in other popular IDEs. For example, a crash or- ganiser enables the inspection of individual crashes of the applications available in the App Store. The provided information includes the thread stack, including the underlying errors and additional statistics, such as crash rates on different iOS versions and devices. These crash reports are also traversable as if the error occurred while developing the application. It also offers an interface building tool called Interface Builder5, which provides an easy, user-friendly way of designing the applica- tion user interface, enhanced with features such as basic interaction among the interface components (e.g., pushing specific view onto the navigation stack when a button is pressed). Furthermore, Xcode ver- sion 11 introduced SwiftUI6, which takes the interface building even further and provides a live preview of the application (see Figure 3.1). This is especially useful because we no longer need to compile the application in order to interact with the user interface.

4. https://git-scm.com/ 5. https://developer.apple.com/xcode/interface-builder/ 6. https://developer.apple.com/xcode/swiftui/

9 3. Mobile Application Development

Figure 3.1: Example of a simple SwiftUI project in Xcode.

iOS Architecture Structure

Apple divides its structure into four main layers (see Figure 3.2): Core OS, Core Services, Media and Cocoa Touch. Each layer has a specific purpose and hosts several frameworks in order to interact with them. Core OS layer is responsible for communicating with the hardware of the underlying device such as gyroscope, Bluetooth and external accessories. This layer also handles power management, security and many of the lower-level programming features. Core Services is responsible for providing network operations, auto- matic reference counting (also known in other languages as a garbage collector), string operations and other data formatting functionality. It also provides file access and threading features to programmers. Media Layer handles media playback as well as recording and edit- ing of audiovisual media. It is also responsible for rendering 2D and 3D graphics as well as animation. Cocoa Touch is a layer in which most of the user interaction hap- pens, handles gestures, touch events triggered by the user, overall visualisation aspect of the application and its behaviour.

10 3. Mobile Application Development

Cocoa Touch UIKit Media

Core Services Foundation Core OS

Hardware

Figure 3.2: Layer of iOS architecture.

Foundation Foundation is an Objective-C framework used extensively in many Swift projects mainly for its implementation of essential functions and data types [6]. This framework includes classes like:

• Object, • Array,

• String, • Dictionary,

• Number, • and many more.

Foundation’s framework essential functions include:

• date and time calculations, • text processing,

• sorting and filtering, • networking,

• data storage, • and many more.

UIKit Arguably the most important thing about a mobile application or any application aimed to satisfy the user in that sense is the user interface.

11 3. Mobile Application Development

In the iOS environment, this function is derived mostly from UIKit framework [7]. This framework provides the necessary infrastructure in iOS ap- plications. It supplies the event handling for Multi-Touch inputs in apps, most notably view and window architecture for implementing the user interface. UIKit’s framework most essential classes include: • View, • Label,

• ViewController, • Image,

• NavigationController, • and many more.

3.1.2 Native Android Application Development

Android7 is a free, open-source operating system intended for mobile devices. It was introduced in 2007 by Open Handset Alliance which was commercially supported by Google. Android is built upon Linux kernel with many libraries and APIs written in C and many application frameworks which include Java-compatible libraries. Android still natively supports programming in Java API, but lately, there have been many steps to encourage developers to switch to Kotlin. Contrary to popular belief, Android does not use JVM (Java Virtual Machine). Instead, it uses ART (Android Runtime) which transforms the application’s bytecode into native instructions. After this, the instructions can be executed by the Runtime Android Environ- ment. Java and Kotlin can co-exist in the same project, but Kotlin has many user-friendly features and syntax improvements that Java does not have.

Kotlin Kotlin is an open-source programming language developed by Jet- Brains8 (Czech software development company), known as a lan- guage for programming applications for Android devices. Although Google initially supported only Java for Android applications, they

7. https://developer.android.com/ 8. https://www.jetbrains.com/

12 3. Mobile Application Development

have shifted towards Kotlin in late 2017 and have been pushing and endorsing its use in Android Studio ever since [8]. Despite this, Kotlin is mostly known as a programming language for Android development. It can also be used for web development, data science and server-side development [9]. Kotlin also supports many similar developer-friendly features like Swift does. For example, run-time type inference that does not force the developer to specify the expression type at compile-time, or the null pointer exceptions and emphasis on the overall code safety. Even though the idea behind it is fundamentally shared between these two languages, the code execution differs. Thanks to Kotlin Mobile SDK, Kotlin can also be used to build an iOS application and can even use its native API, and thus can be considered for a cross-platform development [10].

Android Studio Android Studio is a native IDE made by JetBrains specifically for Android development. It is available on macOS, Linux and Windows operating systems. Its indirect predecessor was a plugin for Eclipse IDE called Eclipse Android Development Tools (E-ADT) which came to a halt in 2015. Android Studio offers many features popular in other IDEs such as syntax highlighting for many programming languages, code com- pletion or a code version control through Git. It also has an excellent Android Virtual Device (emulator) integration with a built-in user interface, where the developer can choose from many Google devices and its versions to run and debug the application. The emulator sup- ports mocking many features that are accessible only on physical devices, such as simulating location points as if the device was used in a car, simulating special predefined sequences of tilting the device, slow network simulation or even accessing the camera (in this case a webcam if one is accessible to the computer). Android Studio also supports many popular programming languages (e.g., Java, C++, Kotlin and Go). Like Xcode, Android Studio also has its tool for a visual representa- tion of elements and their relation to other elements. It is called visual layout editor, and it offers the developer to see (before compiling) how

13 3. Mobile Application Development

the given screen would look on a particular device. It also offers to set constraints for each element (e.g., its width, height or constraints related to other elements such as margin).

Figure 3.3: Example of layout editor in Android Studio.

A great feature included in the Android Studio is the APK9 Ana- lyzer. The analyzer helps to determine what components of the final projects take up the most amount of space. This is especially useful when trying to optimise and cut down on the final application size. The APK analyzer allows comparing two different versions of the same application even if they were not created using Android Studio.

Android Architecture Structure Android divides its platform into four main layers: Linux kernel, Hard- ware abstraction layer, Libraries, Application Framework and System Applications. These components are visually represented in Fig. 3.4. Linux kernel is the foundation for Android platform. It provides many functionalities on which the higher level relies on (e.g., ART).

9. APK (Android Package Kit) is a file format for applications that are meant tobe installed on Android devices

14 3. Mobile Application Development

System Applications Application Framework

Libraries ART Hardware Abstraction Layer Linux kernel

Figure 3.4: Layers of Android architecture.

Android takes advantage of many key security features and allows device manufacturers to develop drivers for known the kernel. Hardware Abstraction Layer provides an interface for hardware capa- bilities to the upper layer (Libraries). It is also responsible for commu- nicating with hardware such as camera, Bluetooth, audio and many device sensors. Libraries layer contains native C/C++ libraries including OpenGL, Webkit. One of the main library is ART responsible for running each application in its own virtual instance specialised for low memory consumption. Application Framework offers an entire feature set of Android oper- ating system, most notable parts of this components are View System, Activity Manager, Resource Manager and Content Provider. System Applications layer include preinstalled applications for mail, SMS, calendar, dialer and more. These applications function both as applications for users to provide such capabilities, but also for the de- veloper (e.g., invoke mail application with the predefined recipient).

Android Layouts

The building blocks for developing applications and their design for Android devices are its layouts. They define a user interface structure and its elements. All the layout elements are build upon the View and ViewGroup objects. The View typically defines something that the user

15 3. Mobile Application Development

can see, ViewGroup is a container that can define a layout structure of other Views or ViewGroups. Two of the most used layouts are Linear layout and Relative layout. The former organises its children into horizontal (or vertical) rows, depending on a given attribute. If the content is larger than the length of the screen, it creates a scrollable view. The latter enables the devel- oper to specify a relative location, relative to each child or other layout objects (with given constraints).

3.2 Cross-platform Application Development

The cross-platform approach to mobile application development fo- cuses on the idea that we use the same codebase to build applications on different platforms. In general, cross-platform application develop- ment widely depends on the chosen framework or toolset, since there is no clear path to the result like in the native approach. In this section, we present two popular JavaScript frameworks for mobile cross-platform development. Although they share a common language, there are fundamental differences in their development paradigm and usage.

3.2.1 NativeScript

NativeScript is an open-source framework developed by Progress that allows the developer to translate his JavaScript (or TypeScript) code into the native code for Android, iOS and web platforms [11]. Its main strength is that it allows for many plugins and customisa- tion for the developer right out of the box. It even lets the developer choose a back-end framework that he wants to use for his application development. Suppose he wants to build robust, well optimised appli- cation with full access to platform-specific API’s. For this he can choose . On the other hand, if he likes the app to be lightweight, he can use Vue.js. This framework is built upon five major parts: Runtimes, Core Modules, CLI and Plugins [12]. Runtimes enable using JavaScript code for native API calls in the Android and iOS frameworks. For them to work this way, they use JavaScript Virtual Machines, Google’s V8 implementation for Android

16 3. Mobile Application Development

Figure 3.5: NativeScript framework – high-level overview.

and WebKit’s JavaScriptCore implementation for iOS (available only for iOS 7.0 or greater). Core Modules are responsible for the most important thing for the whole operation. They transform the underlying JavaScript code to the respected native code for the given platform. The second important feature is that they provide an XML-like way for defining UI elements in the code.

1 2 3 4

Figure 3.6: Example of XML-like definition of Native Script elements.

Figure 3.6 shows how one could make a simple label and a button in Native Script using an XML-like syntax. The label will show a string stored in the message property of the component. The specified button will show a string tap me and will trigger a function onTap() of the given component when a tap event on the button is triggered.

17 3. Mobile Application Development

Data Binding Data binding is a core concept of Native Script [13]. It allows the developer to specify a connection between the data model (i.e., prop- erties and values) and UI (i.e., View). Data binding can occur in three different manners: One-way, One-way to source and Two-way. One-way data binding is the most common method when we need to pass some visual information (stored in the model) to the UI for presenting. The data binding is placed inside the square brackets []. In Figure 3.7 the label text property is data-bound to the given component’s message property. Meaning that every time a message property changes, the label’s text property is also updated with the appropriate value.

1

Figure 3.7: Example of One-way data binding.

One-way to source data binding is best explained on an event like a button click. This type of binding updates the model as a response caused by some action in the user interface (like a button click). The binding is marked within round brackets (). In Figure 3.8, we can see a button which has a binding for tap action that triggers a onTap() function on the appropriate component.

1

Figure 3.8: Example of One-way to source data binding.

Two-way data binding combines two previously mentioned data bindings. A good example of this binding is using it on a text field, because we would want to bind our property to the text in the text field and for example, in the same time be notified when the user ended editing the text field. This binding is visualised inside the appropriate element with square brackets [] and round brackets () inside. In Figure 3.9, we can see a two-way data binding to the property text inside a text field component to be bound to the component’s message property.

18 3. Mobile Application Development

1

Figure 3.9: Example of Two-way data binding.

Native Script needs more than just a XML-like syntax, that is just for a specification on how the View should look like. Generally these View specifications (like in Figure 3.6) are stored ina .html file, the logic is in Typescript (.ts) or Javascript (.js) file named accordingly.

3.2.2 React Native

React Native is a JavaScript framework that runs on ReactJS. Both of them are open-source projects developed by Facebook Inc. ReactJS is a popular JavaScript library for building user interfaces without the typical extensive boilerplate [14]. Its power lies in the fact that the developer only needs to write the code once and easily build it for all platforms. React Native enables us to access native platform-specific APIs using JavaScript code. It also lets us specify the appearance and be- haviour of our UI seamlessly for every platform with one code. Be- cause of this, there may be times where the native components work differently on each platform [15]. For example (as this was the case with this project) alerts and alert styling. iOS natively allows an unlimited number of buttons inside its alerts, but Android only allows no more than three. The solution we used was platform-specific custom alerts. For iOS we used the native solution, and for Android, we used DialogAndroid from library react-native-dialogs [16]. This solution allowed us to have an unlimited number of buttons inside alerts for both platforms and thus make a similar user experience for every user despite their choice of platform.

JSX The most crucial component in React used heavily in React Native is probably JSX (JavaScript XML). The compiler transforms this XML- like structure into pure React code [17].

19 3. Mobile Application Development

Cat Cafe Menu ViewGroup Cat Cafe Menu

ImageView TextView Maru Maru Spot Spot Pouncival Pouncival Pouncival Rum Tum Tugger Rum Tum Tugger Tabby Tabby Tuna Tuna UIImageView UITextView Mrs. Norris Mrs. Norris UIView Choupette Choupette

Figure 3.10: Representation of native layout components for each plat- form.

1 2 Click Me 3

Figure 3.11: JSX example of custom Button object.

1 React.createElement( 2 MyButton, 3 {color: 'blue', shadowSize: 2}, 4 'Click Me' 5 )

Figure 3.12: JSX code from Figure 3.11 transformed to JavaScript by compiler.

20 3. Mobile Application Development

We can use variables inside JSX just like we would in a standard JavaScript code. Anything between curly braces in JSX will transform into JavaScript expression, including event function calls. JSX is a part of a React library, so in order to use it in our project we have to import it like so: import {React} from ’react’;.

Properties By defining the object using JSX, we can then create the object with . This is especially useful, because we can complex objects or define other object behaviour based on those given proper- ties in the object definition part (see Figure 3.13 for an object definition).

1 const Car = (props) => { 2 return( 3 This car goes{props.speed} km/h. 4 ); 5 }

Figure 3.13: JSX code example that uses properties.

State We can also use properties inside to object that changes over time. For example, if we have one Car object that displays the car speed, but after a button is pressed, we would like to present speed property changes. To achieve such run-time changes and see the rerendered object, we need to use UseState, which is also a part of the React library. UseState offers two accessible properties, one for accessing the value and one for changing the value. In order to declare such proper- ties use syntax like this: const [speed, setSpeed] = useState(100). In this case we have also provided a initial value of speed = 100 by stating it in the parameters of useState(). With this in mind, we can present the car speed such as in Figure 3.14. Writing the code in this way lets can change the value of speed, for example by taping on a button, such as in Figure 3.15.

21 3. Mobile Application Development

1 This car goes{speed} km/h.

Figure 3.14: JSX code example that uses useState().

1