Skip to content

Instantly share code, notes, and snippets.

@taimila
taimila / gist:4989046
Created February 19, 2013 19:31
Converts .NET color objects into Cocoa color objects and vice versa. Useful when coding with MonoMac.
public static class ColorConverter
{
public static NSColor FromColor(Color c)
{
float red = IntToFloat(c.R);
float green = IntToFloat(c.G);
float blue = IntToFloat(c.B);
return NSColor.FromDeviceRgba(red, green, blue, 1);
}
@taimila
taimila / StateMachine.fsx
Created May 11, 2016 12:28
Dynamic recursive API in F#
[<AutoOpen>]
module StateMachine =
type State =
| StateA
| StateB
| StateC
| StateD
| End
@taimila
taimila / SvgIcon.cs
Last active January 11, 2020 16:48
Simple Xamarin.Forms view that allows showing SVG icons with specific color.
using System;
using System.IO;
using System.Reflection;
using System.Collections.Generic;
using SkiaSharp;
using SkiaSharp.Views.Forms;
using Xamarin.Forms;
namespace Components
{
@taimila
taimila / CardView.cs
Created February 5, 2019 07:53
Xamarin.Forms CardView for iOS (Supports rounded corners, drop shadow and border)
using Xamarin.Forms;
namespace Taimila
{
public class CardView : ContentView
{
public static readonly BindableProperty CornerRadiusProperty = BindableProperty.Create(
propertyName: "CornerRadius",
returnType: typeof(int),
declaringType: typeof(CardView),
@taimila
taimila / ExtraAnimations.cs
Created February 12, 2019 07:15
Xamarin.Forms view's width and height animation
public static class ExtraAnimations
{
public static async Task<bool> HeightTo(this View view, double height, uint duration = 250, Easing easing = null)
{
var tcs = new TaskCompletionSource<bool>();
var heightAnimation = new Animation(x => view.HeightRequest = x, view.Height, height);
heightAnimation.Commit(view, "HeightAnimation", 10, duration, easing, (finalValue, finished) => { tcs.SetResult(finished); });
return await tcs.Task;
@taimila
taimila / BaseContentPage.cs
Last active February 18, 2019 06:25
This is a experimental way of implementing MVVM in Xamarin Forms.
using System;
using Xamarin.Forms;
using System.Linq;
using System.Threading.Tasks;
namespace ExampleApp
{
/// <summary>
/// Base content page that provides navigation mechanism that
/// allows view models to navigate from one view model to another
@taimila
taimila / Screen.cs
Last active September 16, 2021 05:44
Detect iOS device and split screen situation on Xamarin.Forms
using System;
using Xamarin.Essentials;
using Xamarin.Forms;
namespace NamespaceOfYourApp
{
/// <summary>
/// Utility to get more information on screen configuration, type and size on iOS devices.
/// </summary>
public class Screen
@taimila
taimila / Feature.swift
Last active June 25, 2019 19:45
Feature Toggle implementation in Swift
import Foundation
enum Feature: String, CaseIterable {
case newThing
case otherThing
var isEnabled: Bool {
return UserDefaults.standard.bool(forKey: "feature-\(self.rawValue)")
}