Consuming a web service with Xamarin forms - xamarin

I am learning Xamarin Forms, and I have a few questions.
What's the Portable project that appears in demos and tutorials? My project from scratch is not called Portable.
Must I make my own service interface? After I add the Web reference, References.cs has generated classes and methods. Why not just use those methods directly?

When creating the app, make sure you select Xamarin.Forms, as well as Portable Class Library.
The Portable project (aka Portable Class Library, or PCL) is where the shared code goes for your Xamarin.Forms app. For example, your UI, Models, and View Models will go into that project. You mainly need to worry about the iOS and Android projects for Custom Renderers and Dependency Services, to create custom UI or platform-specific functionality that Xamarin.Forms can't do.
As for consuming the service, its not necessary to create a service interface (I assume its a RESTful service), but it will help you in being able to use the service more easily.

Related

Xamarin Forms Customer Control Library

I need to create a reusable Xamarin Forms control that will be used in two separate projects. It does require custom renderers for IOS and Android. The problem is I cannot figure our what kind of project to use to create a reusable custom control library for Xamarin forms.
Every site seems to talk about creating customer controls that can be reusing in the same project. But I need it in a separate project for reuse.
Can someone please point me in the right direction.
Depending what are your needs regarding multi-targeting, using a solution with a shared project of type MSBuild.Sdk.Extras could be very helpful. You can then packed your shared project into a package that you can reference from your apps project and use locally.
Examples that might guide you and shows you the path are known nuget packages that are being used by app developers cross-platforms, just an example Xamarin.Forms.PancakeView.
Related to MSBuild.Sdk.Extras: How to use different base class in custom control depending on platform target?

Cannot add Judopay to Xamarin forms project

I am trying to include Judopay in my project, and I was able to add it to Android and iOS, but not to the Xamarin forms project. There is no NuGet to be included and I can't seem to add the component reference. Any idea on how can I add it? I cannot use any of these:
using JudoDotNetXamarin;
using JudoPayDotNet.Enums;
using JudoPayDotNet.Models;
Again, they only work on iOS or Android, but not Xam forms.
That is because they only provide platform implementations. You will need to tell your Forms app which implementation to use at what time.
The correct way to go about this is with some form of IoC, using dependency injection or service location. Luckily Xamarin Forms has this integrated:
https://developer.xamarin.com/guides/xamarin-forms/application-fundamentals/dependency-service/introduction/
Using the references from the Android or iOS projects in your shared code will likely not work completely or break things. Maybe not immediately but surely later on. (Except when there really is no platform-specific functionality, then you might get away with this.)

Import ReactNative libraries into a NativeScript application

I have some Android development experience along with React.js. I'm working on a new mobile project and I haven't been sold entirely on either framework yet.
I'm thinking about using the NativeScript framework for its maturity and because it has more libraries with the functionality that I need but I'd like to design my views in a manner similar to ReactJS. I know I could write my own modules for ReactNative but that would require then I'd have to write modules for both Android and iOS. I'd like to avoid that if I could.
I was thinking about importing the necessary ReactNative libraries into a NativeScript project and then being able to write views in a way similar to ReactNative but still using NativeScript.
Is this doable?
Not sure about your exact question. I did just see an integration between Preact and NativeScript you may be interested in. Take a look here: https://github.com/staydecent/nativescript-preact
I believe that repo is in the early stages, but if enough people want something similar, it'll get worked on faster.
Using React Native in NativeScript is not the right approach, either of it are not built to work together and wouldn't work due to architectural reasons. Here is an NativeScript official comparison of these two.
Both are built for solving same problem (building native apps using JS, without webview hybrid app approach) by trans-compiling XML based view layer(which both these framework has its own syntax and so cant be shared) to build Native UI.
Said that view layer has its own syntax for both and cant be shared, model and controller layer cant be shared as well, due to the fact that NativeScript has few things packed as part of the application package, like JavaScript runtime, c++ and Java API layer which helps in exposing all the Native API without the need for any explicit native API wrapper we have in ReactNative.
React Native have platform specific UI components as well as hardware capabilities, which is not the case with NativeScript. Offcouse, that comes with the cost of a fatter app package size(50+MB) compared to <10MB for ReactNative. More on ReactNative vs NativeScript comparison here.

How to create complex UI component (ex- seatmap) using NativeScript

I am working with Nativescript and while it's great to create interfaces with the provided UI components, I haven't found a way to implement custom components that can be used across platforms.
What is the proper way of implementing a complex UI element(directive?) in NativeScript? I am trying to implement a seat map for Android and iOS.
Should the native ui components created and wrapped for NativeScript, or is it possible to create the directive using the web technologies(HTML/CSS/JS)?
You can create custom components that can be reused in your application. Nice how-to blog on that matter can be found here.
The articles above are describing the mechanism to reuse a portion of your UI and creating a separation to ease the developing process.
However, if that is not what you ar looking for you can create your own custom UI element using the native one. TO do that you will need to do marshalling. For example take a look at this documentation section (for Android) and this section (for iOS)
With data conversion you can either use native components directly inside your nativeScript app or you can even extend further and create your own UI plugin.

What does MvvmCross do that Xamarin doesn't already?

Hi so I'm a newb at cross platform stuff and I'm trying to figure out what MvvmCross brings to the table.
From my poor understanding, Xamarin already allows for everything except UI stuff to be written in csharp. Where does MvvmCross come in?
MvvmCross brings the MVVM pattern to platforms where it was previously unavailable, like iOS and Android.
It also supports data binding in Views. This is a powerful feature that provides great separation of concerns. The View will use the ViewModels to offer proper behaviors in the application. MvvmCross even locates the ViewModels in a dedicated project so you can easily reference and reuse them in others.
This is the most important point when talking about MvvmCross. By locating the ViewModels in a Portable Class Library (PCL), you can add them as a reference to any other projects. Of course, that’s not the only interesting point of MvvmCross. There’s also a plug-in architecture, dependency injection (DI) and more.
Source: https://msdn.microsoft.com/en-us/magazine/dn759442.aspx
Xamarin already allows for everything except UI stuff to be written in
csharp.
Xamarin allows you to write UI stuff in C#.
MVVMCross (Mvx) allows you to use the MVVM pattern in cross platform development, so that you can have a shared business logic layer, ViewModel. So you are creating different Views based on the platform but binding to the same ViewModel.

Resources