cross-platform mobile platforms and xamarinfiles.meetup.com/12584322/xamarin and...
Post on 22-May-2020
6 Views
Preview:
TRANSCRIPT
Presented by Mir Majeed
Cross-Platform Mobile Platforms and Xamarin
Agenda1. Sharing Code Among Different Platforms
• File-Linking into each App Project• Portable Class Libraries
2. Solution Population Strategies
3. Cross-Platform Mobile Development Frameworks1. MvvmCross2. MonoCross
The Silo’d Approach: Build Apps Multiple Times
File-Linking into each App ProjectThe simplest approach to sharing code files is to place them in a separate directory (ie. outside of your various mobile application projects) and use file-linking to include them.
File-Linking into each App Project
File-Linking into each App Project
Benefits•Allows you to share code across multiple projects.•Shared code can be branched based on the platform using compiler directives (eg. using #if __ANDROID__, as discussed in the Building Cross Platform Applications document).•Application projects can include platform-specific references that the shared code can utilize (such as using Community.CsharpSqlite.WP7 in the Tasky and MWC samples).
Disadvantages•In Visual Studio there is no simple way to add an entire filesystem ‘tree’ to a project, so files must be individually added. The directory hierarchy must also be manually created.•If you add, delete or move a file in one project you must remember to perform the same action in all the other project files.
File-Linking into each App Project
•Refactoring will only work within one platform type.•Empty subdirectories must also exist before you can ‘link’ files contained within a subdirectory.•If you forget to choose Add As Link (in Visual Studio), it will copy the file into your target project instead of linking. If you don’t notice this has occurred you could accidentally edit both the original file and the copy, getting them out-of-sync.
Portable Class Libraries (PCL)
•A Portable Class Library (PCL) is a special type of project that can be used across Different CLI platforms such as Xamarin.iOS and Xamarin.Android, as well as Silverlight, WPF, Windows Phone and Xbox. The library can only utilize a subset of the complete .NET framework, limited by the platforms being targeted.
Portable Class Libraries (PCL)
The Xamarin column reflects the fact that Xamarin.iOS and Xamarin.Android supports all the profiles shipped with Visual Studio 2013, and the availability of features in any libraries you create will only be limited by the other platforms you choose to support (such as Windows Phone or Windows Store).
This includes profiles that are combinations of:• .NET 4 or .NET 4.5• Silverlight 5• Windows Phone 8• Windows Store Apps
Portable Class Libraries (PCL)
Portable Class Libraries (PCL)
Benefits•Centralized code sharing – write and test code in a single project that can be consumed by other libraries or applications.•Refactoring operations will affect all code loaded in the solution (the Portable Class Library and the platform-specific projects).•The PCL Project itself, or the output assembly can be shared.
Disadvantages•Because the same Portable Class Library is shared between multiple applications, platform-specific libraries cannot be referenced (eg. Community.CsharpSqlite.WP7).•The Portable Class Library subset may not include classes that would otherwise be available in both MonoTouch and Mono for Android (such as DllImport or System.IO.File).
Solution Population Strategies
Two Project Types:•Core project – Write re-usable code in one place, to be shared across different platforms. Use the principles of encapsulation to hide implementation details wherever possible.
•Platform-specific application projects – Consume the re-usable code with as little coupling as possible. Platform-specific features are added at this level, built on components exposed in the Core project.
Solution Population Strategies
Structure of Core Project•Shared projects should implement as much non-UI functionality as is possible, which generally includes the following layers:•Data Layer – Code that takes care of physical data or even XML files. The data layer classes are normally only used by the data access layer.•Data Access Layer – Defines an API that supports the required data operations for the application’s functionality, such as methods to access lists of data, individual data items and also•Service Access Layer – An optional layer to provide cloud services to the application. Contains code that accesses remote network resources (web services, image downloads, etc) and possibly caching of the results.•Business Layer – Definition of the Model classes and the Façade or Manager classes that expose functionality to the platform-specific applications.
Solution Population Strategies
Structure of Platform-Specific Application Projects•Platform-specific projects must reference the assemblies required to bind to each platform’s SDK (Xamarin.iOS, Xamarin.Android or Windows Phone) as well as the Core shared code project.•Application Layer – Platform specific functionality and binding/conversion between the Business Layer objects and the user interface.•User Interface Layer – Screens, custom user-interface controls, presentation of validation logic.
Solution Population Strategies
MvvmCross
About MvvmCross
• Fork of the MonoCross project• Started by Stuart Lodge• Moved from MVC and towards MVVM• It is an extension project from http://www.cirrious.com
MvvmCross Manifesto
Portability – Use Portable Class Libraries for as much of your code as you possibly can -
viewmodel, model, service and even view.
Interface Driven Development – Use Dependency Injection, Inversion of Control and Plugins to
get your applications richly and robustly to market on all of your target platforms.
Code for Test – Use interfaces; develop small, cohesive, loosely coupled components.
Mvvm – Use architectural patterns - especially Model-View-ViewModel with Data-Binding.
Native UIs – users love Native, and you should give them Native UIs that delight, that provide rich
functionality and that are styled to fit naturally in the context of your users’ devices.
Supported Platforms
• Windows Phone 7 and Windows Phone 8
• Windows Presentation Foundation
• Windows Store
• Xamarin.Android
• Xamarin.iOS
• Xamarin.Mac
Parts of MvvmCross Application
Core Project – containing all the ViewModels, Services, Models and 'business' code.
UI Project(s) – per platform containing the Views and platform specific code for
interacting with the Core Project.
Key MvvmCross Objects
Core Project
• an App object - responsible for starting your ViewModels and your business logic
• a Start object - responsible for deciding the first ViewModel or ViewModels which
should be presented
• one or more ViewModels - each one responsible for a piece of user interaction
• Services and Models
Key MvvmCross Objects
UI Project
• The native Application object - responsible for native lifecycle events - on each
platform this object is a platform-specific class
• MvvmCross Setup class - responsible for 'bootstrapping' MvvmCross, Core and UI
Projects
• One or more Views - each one responsible for presenting one of your ViewModels
• Custom UI code - for controls, gestures, events, etc.
MonoCross
About MonoCross
• MonoCross is an open source cross-platform mobile
framework using C# .NET and the Mono framework.
• It is based on Model-View-Controller (MVC) Pattern
enables cross-platform portability of business logic
and data access code, (Model + Controller), while
supporting full, native and/or platform-specific
presentation (Views).
MonoCross Solution Structure
• It consists of the MonoCross framework , a shared application, and one or more
container projects.
• The core application logic is contained in shared application which is referenced by
multiple class library assembly projects. This project structure enables code files to be
compiled to the appropriate platform.
top related