Skip to content

Instantly share code, notes, and snippets.

@taimila
taimila / Feature.swift
Last active Jun 25, 2019
Feature Toggle implementation in Swift
View Feature.swift
import Foundation
enum Feature: String, CaseIterable {
case newThing
case otherThing
var isEnabled: Bool {
return UserDefaults.standard.bool(forKey: "feature-\(self.rawValue)")
}
@taimila
taimila / Screen.cs
Last active Sep 16, 2021
Detect iOS device and split screen situation on Xamarin.Forms
View Screen.cs
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 / BaseContentPage.cs
Last active Feb 18, 2019
This is a experimental way of implementing MVVM in Xamarin Forms.
View BaseContentPage.cs
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 / ExtraAnimations.cs
Created Feb 12, 2019
Xamarin.Forms view's width and height animation
View ExtraAnimations.cs
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 / CardView.cs
Created Feb 5, 2019
Xamarin.Forms CardView for iOS (Supports rounded corners, drop shadow and border)
View CardView.cs
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 / SvgIcon.cs
Last active Jan 11, 2020
Simple Xamarin.Forms view that allows showing SVG icons with specific color.
View SvgIcon.cs
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 / StateMachine.fsx
Created May 11, 2016
Dynamic recursive API in F#
View StateMachine.fsx
[<AutoOpen>]
module StateMachine =
type State =
| StateA
| StateB
| StateC
| StateD
| End
@taimila
taimila / gist:4989046
Created Feb 19, 2013
Converts .NET color objects into Cocoa color objects and vice versa. Useful when coding with MonoMac.
View gist:4989046
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);
}