Going mobile with Umbraco and Xamarin Part 2
Learn more about mobile dev using Xamarin and how you can use Umbraco to improve your native apps.
... into our code behind for our page, and I want to change the button's animation so whenever I press the button it's going to scale out, it's going to rotate, it's going to look exactly like you would perform a normal high-five. So, if I run this on my local machine again, Windows from Project, I'm just going to wait a few seconds, then we can go up here, my name is Matthias, and then I push the button, wow, and then we wait, ah, and then you just let a bro hang, right? So that's not that good. So perhaps my good friend Thomas also has this app installed. He might, yeah, otherwise this is going to be a boring performance. Yeah, he just sat home Friday nights, Saturday nights. We can also just try to show it on the, are you ready? Are you ready for a high-five? Okay. So in one, two, three. Oh, that was quick. So you high-fived Thomas, thanks Matthias, and I hope Thomas' will say you high-fived Matthias. Thank you Thomas. And that's pretty much it, like that's the high-five app, like my finest piece. And what's really nice to look at is that we use Xamarin.Forms and the only actual UI code we made was up in our high-five page in the Portable Class Library, and then also we made the image button. where we then specify a specific render for Universal Windows Project, but that's actually more or less it for making this app, which is pretty nice, I think. It's pretty maintainable and it's pretty, it's not that much code. And it's all done in Visual Studio and C Sharp. Exactly. So can you do any gestures, stuff, for swiping and inline and stuff, or just button stuff, like for the laser, which actually makes the laser stuff, what I can see is that exactly this is what it looks like. Yeah. That just is easier to do it like that? Yeah, so you can do whatever you want, like for swiping, for animations, stuff like that, that you have for the platforms, you can do that. And if you have a specific thing that is for one of the platforms, you can do it by doing this custom renderer, as Matthias just showed with the image function. Yes. Just to be sure, I just want to show you the iOS project works as well with the animations and stuff like that. Of course, I doubt I'm going to get any high-fives. Maybe. Yeah. It looks the same. I just wanted to show the animations. Oh, thanks. So, yeah. Okay. That was really nice. Please don't steal the idea. No. I mean, perhaps when I get some lawyers like over it and stuff like that. Okay. So, Matthias, how was your reuse here? It was pretty high, right? The only thing you did on a specific platform was the Windows part where you did this image custom render, right? Yes, exactly. Okay. That's awesome. Maybe we should try to look at how we can use some of the resources from Umbraco in your project. Oh, that's a good idea. Isn't it? Yeah. Let's take a look. Yeah. You just came up with that. Yeah. So, I'll plug myself out. Okay. So, we've got this. This is a little bit of a mess. Yeah. Yeah. Yeah. So, what I have added to the project that Matthias have just shown you is like a simple Umbraco site. The Umbraco site here simply can consist of a host controller. So, it's a really small Umbraco site. And if we go into the local host here, you'll see that it's just one of the default templates. But what we want here is actually to be able to allow our customers that they can sit in Umbraco, do the resources that they have for the apps and edit them inside Umbraco. So, instead of us either adding them directly to the app or inventing a system where we can just do this, we'll use Umbraco. Umbraco is, as you most likely know, really used in many companies. So, they're familiar with Umbraco. So, let's take a look. Okay. So, in here in the languages, I've added that we can have this site in both English and Danish. And I've added a lot of strings that we're going to translate, both loading and welcome. Lots and lots. Yes. So, and my translation is maybe not that good. However, it should still work. So, in here, in my Umbraco project. Okay. So, I've added a host controller, a controller inheriting from Umbraco API controller. And the only thing it does is actually it goes into Umbraco, takes the dictionary value of a specific key using a specific culture and gives it back to me. And I can return that. Super simple. So, back to my Hi5 app or to my TSS. Awesome. Correct. Cool Hi5 app. So, I extended that a little bit. What I did was I added a method that says get localized strings. So, right now, I'm just calling my local installation here with my culture info and the key I want to see. And I call that when I need some local strings. This is not optimized. I call it for every string I need. Of course, in an enterprise model, we call it once, get all of the strings to the client and use it from there. But just to simplify things a little bit here. Yeah. So, you can see here I call welcome text using welcome and loading. And I'll run this in Danish so that when I run it now, you will be able to see that I get these all the strings. It says welcome. It means welcome, right? Yes. Oh, no. All right. Let me see if I can Hi5 somebody. Oh, crap. Maybe you can. Really? Yeah. So, mine says, boom, boom, boom. And that's a really easy way that we can reuse some of the stuff we have in Umbraco to our native apps. And it's really strong because, as I said before, the company knows it. The company loves Umbraco. So, being able to use that as part of their native application development is an extra plus for them. Okay. So, let's head back to this. So, what we have done now is we have shown you how you really easily can use Xamarin to make mobile applications for iOS, Android, and Windows. We have shown you how you can reuse your code in a really high degree. And finally, we have shown you how you can reuse some of the stuff you have in Umbraco down to your mobile native apps. Any questions? Yeah? I just want to ask the learning curve. I've never done these Android tools. Is it a difficult thing to get into? Well, in some aspects, it is. So, it's all .NET. And that's a really good starting point, right? If you do the Android part and you have done Windows development before, that's easy. The tough point comes to when you're going to do UI in iOS and you're using Xamarin Classic. Because the way they build their UIs in iOS is a little bit tricky. So, there you will see a learning curve. It's also a really good idea to have some understanding of each of the platforms because you are still developing for each of the platforms. So, having good understanding of what's possible in the different platforms. That's also a good thing and needed. But the form is also free, right? Is it better to use forms now? Yeah, well, so, that's a really good question. Because you can say Xamarin started with Xamarin Classic and Xamarin Forms appeared a little bit later. In the beginning, everybody could see the idea in Forms. You have one project where you can reuse a lot, including the UI. However, Xamarin had some issues with it in the first version. They had some performance issues when you're using a lot of data, when you're using lists. So, that's why a lot of people and developers... They stick with Xamarin Classic. Xamarin Forms have reached a point where Xamarin themselves says, Always go with Xamarin Forms if you can do that. Otherwise, use Xamarin Classic. So, yes. Is Forms the one that comes now free with Visual Studio? So, both Xamarin Forms and Xamarin Classic is free. So, Microsoft acquired Xamarin a few months back. And part of that was they open sourced. And made it free. So, all of this is free. Previously, it had a pretty high price tag. But not free. Could you define a borderline up to when I would use a simple HTML or CSS web application? Something like PhoneGap or something like that? Yes. Yes. So, when does it make sense to use Xamarin? Yes. So, it actually depends on the company. So, if you're a company with a lot of .NET developers used to build Windows applications, then using Xamarin is a really easy way to get into doing mobile apps on multiple platforms. If you're a company with a lot of JavaScript developers, doing PhoneGap, doing Cordova, that would be the way to go. So, Xamarin is not for all companies. Because you need to have the developers that match it. And then you also have the question. So, will the user actually care that your UI is identical and doesn't match what they normally see in other apps? Or what? And that's from case to case. There have been a lot of examples that huge companies tried to build a web-based application and just hosted it inside a shell as a native application. And most of those companies have gone back to building fully native applications. Simply because they began getting that poor ratings in the stores. But again, it depends. Some cases Cordova is best. Some cases Xamarin is best. Yeah? What about using platform-specific stuff like local resources like Android and web-based storage? Yes. Yes. Yes. So, once you've figured out how the architecture is, it's actually pretty easy. But you need to figure that out. The way we do it is that we, in our shared view models, we have interfaces for all of the different services. And then on each platform we implement those services. And using an IOC container we can easily resolve that. Yep. Are there any performance implications between using Xamarin versus building a separate native app? Yeah. Good question. And that's actually a question we get a lot. Because one of the concerns is the performance. If we use Xamarin Classic, we are on the bare bone, you can say. We are building a fully native app. Yeah. Using Xamarin Forms, we are also building native apps. However, we have this little layer in between that's called Forms that using generics to resolve. So, if we have this type, it's called this in each of the platforms. So, there you'll see a slight performance decrease over doing it in Xamarin Classic, for example. Yes. Yep. Does the Xamarin build the full run time for all of those ? A run time for each of the? A mono run time. A mono run time. Yes. So, yes, it does. And looking ahead, one of the things that Microsoft have announced is that, they're going to occasionally move it over to the new core. But not yet. Yes. Anything else? All right. That was it. Thank you so much.