With the recent conversation around Flutter, I decided to test out how things would work, if Xamarin.Forms ran on SkiaSharp, rather than using the platform APIs. I managed to create a proof of concept, of a Xamarin.Forms ContentPage, with one Label, showing on SkiaSharp. At the time of this post, this is all it can do.
GitHub Repo: Skixam.
As you will see in the Sample app, it is very easy to get started. All you need to do is replace what you inherit from, in your MainActivity or AppDelegate. Everything else in your Xamarin.Forms app remains the same.
public partial class AppDelegate : SkixamApplicationDelegate
public class MainActivity : SkixamAppCompatActivity
In each of these activities or delegates, we create a View or UIView, and place an SKSurface and Canvas down on it. We then search for the elements, and use the renderer to draw on the canvas.
With the Skia approach, there is only one renderer needed, as Skia is taking care of the API calls to each platform. This means whatever platform SkiaSharp supports, this would be able to run on. It could result with quicker support for new platforms, and worrying less about native platform changes made, with each release, along with a more consistent UI. As one thing I am now starting to notice in commercial Xamarin.Forms projects, is they are not really sticking to the native look and feel anymore, and want it almost identical across platforms.
- Only 1 default renderer. No need for platform specific renderers.
- You can still override a renderer, for platform specific changes if needed.
- Potentially faster viewing and scrolling.
- Quicker support for new platforms.
This was only a proof of concept, and it worked rather well. I would need to spend more time to add in Touch, and Layout. I believe once those are added, making renderers for other elements would come quite quickly and easily. It’s kind of cool that there is the potential to run an existing Xamarin.Forms application on SkiaSharp instead of the platform, with a single line change in your platform specific Xamarin project. I might advance further on this soon.