├── Assets.xcassets ├── Contents.json ├── AppIcon.appiconset │ ├── icon.png │ ├── icon120.png │ ├── icon152.png │ ├── icon167.png │ ├── icon180.png │ ├── icon120-1.png │ ├── AppIcon.appiconset │ │ ├── icon.png │ │ ├── icon120.png │ │ ├── icon152.png │ │ ├── icon167.png │ │ ├── icon180.png │ │ └── Contents.json │ └── Contents.json ├── LaunchImage.launchimage │ └── Contents.json ├── chevron.imageset │ ├── chevron.pdf │ └── Contents.json ├── icon_pip.imageset │ ├── icon_pip.png │ └── Contents.json ├── icon_calc.imageset │ ├── icon_calc.png │ └── Contents.json ├── icon_flash.imageset │ ├── icon_flash.png │ └── Contents.json ├── icon_rubber.imageset │ ├── icon_rubber.png │ └── Contents.json ├── icon_spring.imageset │ ├── icon_spring.png │ └── Contents.json ├── flashlight_on.imageset │ ├── flashlight_on.pdf │ └── Contents.json ├── icon_momentum.imageset │ ├── icon_momentum.png │ └── Contents.json ├── icon_rotation.imageset │ ├── icon_rotation.png │ └── Contents.json ├── flashlight_off.imageset │ ├── flashlight_off.pdf │ └── Contents.json └── icon_acceleration.imageset │ ├── icon_acceleration.png │ └── Contents.json ├── AppIcon.appiconset ├── icon.png ├── icon120.png ├── icon152.png ├── icon167.png ├── icon180.png └── Contents.json ├── Interfaces ├── Acceleration.xcassets │ └── Contents.json ├── InterfaceViewController.cs ├── Rubberbanding.cs ├── CalculatorButton.cs ├── Spring.cs ├── Acceleration.cs ├── FlashlightButton.cs └── RewardingMomentum.cs ├── packages.config ├── Entitlements.plist ├── InterfaceCell.cs ├── Utilities ├── CGPointExtensions.cs ├── UIColorExtensions.cs ├── UISpringTimingParameters.cs ├── UIViewExtensions.cs ├── GradientView.cs └── SliderView.cs ├── InterfaceCell.designer.cs ├── .gitignore ├── README.md ├── MenuViewController.cs ├── FluidInterfaces.sln ├── Info.plist ├── LaunchScreen.storyboard ├── AppDelegate.cs ├── Main.storyboard ├── FluidInterfaces.csproj └── LICENSE /Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | } 6 | } -------------------------------------------------------------------------------- /AppIcon.appiconset/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/migueldeicaza/FluidInterfaces/HEAD/AppIcon.appiconset/icon.png -------------------------------------------------------------------------------- /AppIcon.appiconset/icon120.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/migueldeicaza/FluidInterfaces/HEAD/AppIcon.appiconset/icon120.png -------------------------------------------------------------------------------- /AppIcon.appiconset/icon152.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/migueldeicaza/FluidInterfaces/HEAD/AppIcon.appiconset/icon152.png -------------------------------------------------------------------------------- /AppIcon.appiconset/icon167.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/migueldeicaza/FluidInterfaces/HEAD/AppIcon.appiconset/icon167.png -------------------------------------------------------------------------------- /AppIcon.appiconset/icon180.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/migueldeicaza/FluidInterfaces/HEAD/AppIcon.appiconset/icon180.png -------------------------------------------------------------------------------- /Interfaces/Acceleration.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | } 6 | } -------------------------------------------------------------------------------- /Assets.xcassets/AppIcon.appiconset/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/migueldeicaza/FluidInterfaces/HEAD/Assets.xcassets/AppIcon.appiconset/icon.png -------------------------------------------------------------------------------- /Assets.xcassets/LaunchImage.launchimage/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images": [], 3 | "info": { 4 | "version": 1, 5 | "author": "xcode" 6 | } 7 | } -------------------------------------------------------------------------------- /Assets.xcassets/chevron.imageset/chevron.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/migueldeicaza/FluidInterfaces/HEAD/Assets.xcassets/chevron.imageset/chevron.pdf -------------------------------------------------------------------------------- /Assets.xcassets/AppIcon.appiconset/icon120.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/migueldeicaza/FluidInterfaces/HEAD/Assets.xcassets/AppIcon.appiconset/icon120.png -------------------------------------------------------------------------------- /Assets.xcassets/AppIcon.appiconset/icon152.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/migueldeicaza/FluidInterfaces/HEAD/Assets.xcassets/AppIcon.appiconset/icon152.png -------------------------------------------------------------------------------- /Assets.xcassets/AppIcon.appiconset/icon167.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/migueldeicaza/FluidInterfaces/HEAD/Assets.xcassets/AppIcon.appiconset/icon167.png -------------------------------------------------------------------------------- /Assets.xcassets/AppIcon.appiconset/icon180.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/migueldeicaza/FluidInterfaces/HEAD/Assets.xcassets/AppIcon.appiconset/icon180.png -------------------------------------------------------------------------------- /Assets.xcassets/icon_pip.imageset/icon_pip.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/migueldeicaza/FluidInterfaces/HEAD/Assets.xcassets/icon_pip.imageset/icon_pip.png -------------------------------------------------------------------------------- /Assets.xcassets/AppIcon.appiconset/icon120-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/migueldeicaza/FluidInterfaces/HEAD/Assets.xcassets/AppIcon.appiconset/icon120-1.png -------------------------------------------------------------------------------- /Assets.xcassets/icon_calc.imageset/icon_calc.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/migueldeicaza/FluidInterfaces/HEAD/Assets.xcassets/icon_calc.imageset/icon_calc.png -------------------------------------------------------------------------------- /Assets.xcassets/icon_flash.imageset/icon_flash.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/migueldeicaza/FluidInterfaces/HEAD/Assets.xcassets/icon_flash.imageset/icon_flash.png -------------------------------------------------------------------------------- /Assets.xcassets/icon_rubber.imageset/icon_rubber.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/migueldeicaza/FluidInterfaces/HEAD/Assets.xcassets/icon_rubber.imageset/icon_rubber.png -------------------------------------------------------------------------------- /Assets.xcassets/icon_spring.imageset/icon_spring.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/migueldeicaza/FluidInterfaces/HEAD/Assets.xcassets/icon_spring.imageset/icon_spring.png -------------------------------------------------------------------------------- /Assets.xcassets/flashlight_on.imageset/flashlight_on.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/migueldeicaza/FluidInterfaces/HEAD/Assets.xcassets/flashlight_on.imageset/flashlight_on.pdf -------------------------------------------------------------------------------- /Assets.xcassets/icon_momentum.imageset/icon_momentum.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/migueldeicaza/FluidInterfaces/HEAD/Assets.xcassets/icon_momentum.imageset/icon_momentum.png -------------------------------------------------------------------------------- /Assets.xcassets/icon_rotation.imageset/icon_rotation.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/migueldeicaza/FluidInterfaces/HEAD/Assets.xcassets/icon_rotation.imageset/icon_rotation.png -------------------------------------------------------------------------------- /packages.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /Assets.xcassets/flashlight_off.imageset/flashlight_off.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/migueldeicaza/FluidInterfaces/HEAD/Assets.xcassets/flashlight_off.imageset/flashlight_off.pdf -------------------------------------------------------------------------------- /Assets.xcassets/AppIcon.appiconset/AppIcon.appiconset/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/migueldeicaza/FluidInterfaces/HEAD/Assets.xcassets/AppIcon.appiconset/AppIcon.appiconset/icon.png -------------------------------------------------------------------------------- /Assets.xcassets/icon_acceleration.imageset/icon_acceleration.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/migueldeicaza/FluidInterfaces/HEAD/Assets.xcassets/icon_acceleration.imageset/icon_acceleration.png -------------------------------------------------------------------------------- /Assets.xcassets/AppIcon.appiconset/AppIcon.appiconset/icon120.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/migueldeicaza/FluidInterfaces/HEAD/Assets.xcassets/AppIcon.appiconset/AppIcon.appiconset/icon120.png -------------------------------------------------------------------------------- /Assets.xcassets/AppIcon.appiconset/AppIcon.appiconset/icon152.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/migueldeicaza/FluidInterfaces/HEAD/Assets.xcassets/AppIcon.appiconset/AppIcon.appiconset/icon152.png -------------------------------------------------------------------------------- /Assets.xcassets/AppIcon.appiconset/AppIcon.appiconset/icon167.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/migueldeicaza/FluidInterfaces/HEAD/Assets.xcassets/AppIcon.appiconset/AppIcon.appiconset/icon167.png -------------------------------------------------------------------------------- /Assets.xcassets/AppIcon.appiconset/AppIcon.appiconset/icon180.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/migueldeicaza/FluidInterfaces/HEAD/Assets.xcassets/AppIcon.appiconset/AppIcon.appiconset/icon180.png -------------------------------------------------------------------------------- /Entitlements.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /InterfaceCell.cs: -------------------------------------------------------------------------------- 1 | using Foundation; 2 | using System; 3 | using UIKit; 4 | 5 | namespace FluidInterfaces 6 | { 7 | public partial class InterfaceCell : UICollectionViewCell 8 | { 9 | public InterfaceCell (IntPtr handle) : base (handle) 10 | { 11 | } 12 | } 13 | } -------------------------------------------------------------------------------- /Utilities/CGPointExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using CoreGraphics; 3 | 4 | 5 | public static class CGPointExtensions { 6 | public static nfloat Distance (this CGPoint self, CGPoint to) 7 | { 8 | return NMath.Sqrt (NMath.Pow (to.X - self.X, 2) + NMath.Pow (to.Y - self.Y, 2)); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /Assets.xcassets/chevron.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "chevron.pdf" 6 | } 7 | ], 8 | "info" : { 9 | "version" : 1, 10 | "author" : "xcode" 11 | }, 12 | "properties" : { 13 | "template-rendering-intent" : "template" 14 | } 15 | } -------------------------------------------------------------------------------- /Assets.xcassets/flashlight_off.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "flashlight_off.pdf" 6 | } 7 | ], 8 | "info" : { 9 | "version" : 1, 10 | "author" : "xcode" 11 | }, 12 | "properties" : { 13 | "template-rendering-intent" : "template" 14 | } 15 | } -------------------------------------------------------------------------------- /Assets.xcassets/flashlight_on.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "flashlight_on.pdf" 6 | } 7 | ], 8 | "info" : { 9 | "version" : 1, 10 | "author" : "xcode" 11 | }, 12 | "properties" : { 13 | "template-rendering-intent" : "template" 14 | } 15 | } -------------------------------------------------------------------------------- /Utilities/UIColorExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using UIKit; 3 | 4 | public class Color { 5 | public static UIColor FromHex (int hex, float alpha = 1) 6 | { 7 | var r = ((hex & 0xff0000) >> 16) / 255f; 8 | var g = ((hex & 0xff00) >> 8) / 255f; 9 | var b = ((hex & 0xff)) / 255f; 10 | return new UIColor ((nfloat)r, (nfloat)g, (nfloat)b, alpha); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Assets.xcassets/icon_pip.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "scale" : "1x" 6 | }, 7 | { 8 | "idiom" : "universal", 9 | "scale" : "2x" 10 | }, 11 | { 12 | "idiom" : "universal", 13 | "filename" : "icon_pip.png", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /Assets.xcassets/icon_calc.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "scale" : "1x" 6 | }, 7 | { 8 | "idiom" : "universal", 9 | "scale" : "2x" 10 | }, 11 | { 12 | "idiom" : "universal", 13 | "filename" : "icon_calc.png", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /Assets.xcassets/icon_flash.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "scale" : "1x" 6 | }, 7 | { 8 | "idiom" : "universal", 9 | "scale" : "2x" 10 | }, 11 | { 12 | "idiom" : "universal", 13 | "filename" : "icon_flash.png", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /Assets.xcassets/icon_momentum.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "scale" : "1x" 6 | }, 7 | { 8 | "idiom" : "universal", 9 | "scale" : "2x" 10 | }, 11 | { 12 | "idiom" : "universal", 13 | "filename" : "icon_momentum.png", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /Assets.xcassets/icon_rotation.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "scale" : "1x" 6 | }, 7 | { 8 | "idiom" : "universal", 9 | "scale" : "2x" 10 | }, 11 | { 12 | "idiom" : "universal", 13 | "filename" : "icon_rotation.png", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /Assets.xcassets/icon_rubber.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "scale" : "1x" 6 | }, 7 | { 8 | "idiom" : "universal", 9 | "scale" : "2x" 10 | }, 11 | { 12 | "idiom" : "universal", 13 | "filename" : "icon_rubber.png", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /Assets.xcassets/icon_spring.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "scale" : "1x" 6 | }, 7 | { 8 | "idiom" : "universal", 9 | "scale" : "2x" 10 | }, 11 | { 12 | "idiom" : "universal", 13 | "filename" : "icon_spring.png", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /Assets.xcassets/icon_acceleration.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "scale" : "1x" 6 | }, 7 | { 8 | "idiom" : "universal", 9 | "scale" : "2x" 10 | }, 11 | { 12 | "idiom" : "universal", 13 | "filename" : "icon_acceleration.png", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /Interfaces/InterfaceViewController.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using UIKit; 3 | 4 | public class InterfaceViewController : UIViewController { 5 | public InterfaceViewController () 6 | { 7 | } 8 | 9 | public override void ViewDidLoad () 10 | { 11 | base.ViewDidLoad (); 12 | 13 | // reduces screen tearing on iPhone X 14 | View.BackgroundColor = UIColor.FromWhiteAlpha (0.05f, 1); 15 | 16 | NavigationItem.LargeTitleDisplayMode = UINavigationItemLargeTitleDisplayMode.Never; 17 | } 18 | } 19 | 20 | -------------------------------------------------------------------------------- /InterfaceCell.designer.cs: -------------------------------------------------------------------------------- 1 | // WARNING 2 | // 3 | // This file has been generated automatically by Visual Studio from the outlets and 4 | // actions declared in your storyboard file. 5 | // Manual changes to this file will not be maintained. 6 | // 7 | using Foundation; 8 | using System; 9 | using System.CodeDom.Compiler; 10 | using UIKit; 11 | 12 | namespace FluidInterfaces 13 | { 14 | [Register ("InterfaceCell")] 15 | partial class InterfaceCell 16 | { 17 | void ReleaseDesignerOutlets () 18 | { 19 | } 20 | } 21 | } -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Autosave files 2 | *~ 3 | 4 | # build 5 | [Oo]bj/ 6 | [Bb]in/ 7 | packages/ 8 | TestResults/ 9 | 10 | # globs 11 | Makefile.in 12 | *.DS_Store 13 | *.sln.cache 14 | *.suo 15 | *.cache 16 | *.pidb 17 | *.userprefs 18 | *.usertasks 19 | config.log 20 | config.make 21 | config.status 22 | aclocal.m4 23 | install-sh 24 | autom4te.cache/ 25 | *.user 26 | *.tar.gz 27 | tarballs/ 28 | test-results/ 29 | Thumbs.db 30 | .vs/ 31 | 32 | # Mac bundle stuff 33 | *.dmg 34 | *.app 35 | 36 | # resharper 37 | *_Resharper.* 38 | *.Resharper 39 | 40 | # dotCover 41 | *.dotCover 42 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | This is a line-by-line port of Nathan Gitter's Fluent Interfaces 2 | project that shows how to implement the various idioms that Apple 3 | showed on their "Fluid Interfaces" talk at WWDC 2018. 4 | 5 | This is still missing a couple of ports, but figured I could open it up 6 | now for people to try out. And I messed up the layout for some controls 7 | in one of the samples, need to fix that. 8 | 9 | Nathan [wrote a blog 10 | post](https://medium.com/@nathangitter/building-fluid-interfaces-ios-swift-9732bb934bf5) 11 | with all the juicy details. He tweets as [https://twitter.com/nathangitter](@nathangitter). 12 | 13 | The LICENSE reflects the same license that Nathan used 14 | -------------------------------------------------------------------------------- /Utilities/UISpringTimingParameters.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using UIKit; 3 | using CoreGraphics; 4 | 5 | public static class UISpringTiming { 6 | /// A design-friendly way to create a spring timing curve. 7 | /// damping: The 'bounciness' of the animation. Value must be between 0 and 1. 8 | /// response: The 'speed' of the animation. 9 | /// initialVelocity: The vector describing the starting motion of the property. Use CGVector.Zero if not desired 10 | public static UISpringTimingParameters MakeTimingParameters (nfloat damping, nfloat response, CGVector initialVelocity) 11 | { 12 | var stiffness = NMath.Pow (2 * NMath.PI / response, 2); 13 | var damp = 4 * NMath.PI * damping / response; 14 | 15 | return new UISpringTimingParameters (mass: 1, stiffness: stiffness, damping: damp, velocity: initialVelocity); 16 | } 17 | 18 | public static UISpringTimingParameters MakeTimingParameters (nfloat damping, nfloat response) => MakeTimingParameters (damping, response, new CGVector (0, 0)); 19 | } -------------------------------------------------------------------------------- /MenuViewController.cs: -------------------------------------------------------------------------------- 1 | using Foundation; 2 | using System; 3 | using UIKit; 4 | 5 | namespace FluidInterfaces { 6 | // 7 | // This class is references from the Main.storyboard 8 | // 9 | public partial class MenuViewController : UIViewController { 10 | public MenuViewController (IntPtr handle) : base (handle) 11 | { 12 | } 13 | 14 | public MenuViewController () 15 | { 16 | Delegate = this; 17 | } 18 | 19 | public override void ViewDidLoad () 20 | { 21 | base.ViewDidLoad (); 22 | 23 | // reduces screen tearing on iPhone X 24 | View.BackgroundColor = UIColor.FromWhiteAlpha (0.05f, 1); 25 | } 26 | 27 | public override void ViewWillAppear (bool animated) 28 | { 29 | base.ViewWillAppear (animated); 30 | foreach (var cell in collectionView.VisibleCells) 31 | cell.Highlighted = true; 32 | 33 | } 34 | 35 | class CollectionViewDelegate : UICollectionViewDelegate { 36 | [Weak] MenuViewController parent; 37 | public CollectionViewDelegate (MenuViewController parent) => this.parent = parent; 38 | 39 | public override void ItemSelected (UICollectionView collectionView, NSIndexPath indexPath) 40 | { 41 | parent.collectionView.CellForItem (indexPath).Highlighted = true; 42 | 43 | } 44 | } 45 | } 46 | } -------------------------------------------------------------------------------- /Utilities/UIViewExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using UIKit; 3 | using CoreGraphics; 4 | 5 | public static class UIViewExtensions { 6 | 7 | public static void Center (this UIView view, UIView inView) => view.Center (inView, UIOffset.Zero); 8 | 9 | public static void Center (this UIView view, UIView inView, UIOffset offset) 10 | { 11 | view.TranslatesAutoresizingMaskIntoConstraints = false; 12 | NSLayoutConstraint.ActivateConstraints (new [] { 13 | view.CenterXAnchor.ConstraintEqualTo (inView.CenterXAnchor, offset.Horizontal), 14 | view.CenterYAnchor.ConstraintEqualTo (inView.CenterYAnchor, offset.Vertical)}); 15 | 16 | } 17 | 18 | public static void Pin (this UIView view, UIView inView) => view.Pin (inView, UIEdgeInsets.Zero); 19 | 20 | public static void Pin (this UIView view, UIView inView, UIEdgeInsets insets) 21 | { 22 | view.TranslatesAutoresizingMaskIntoConstraints = false; 23 | NSLayoutConstraint.ActivateConstraints (new [] { 24 | view.TopAnchor.ConstraintEqualTo (inView.TopAnchor, insets.Top), 25 | view.LeftAnchor.ConstraintEqualTo (inView.LeftAnchor, insets.Left), 26 | view.BottomAnchor.ConstraintEqualTo (inView.BottomAnchor, -insets.Bottom), 27 | view.RightAnchor.ConstraintEqualTo (inView.RightAnchor, -insets.Right) 28 | }); 29 | } 30 | 31 | 32 | } 33 | -------------------------------------------------------------------------------- /FluidInterfaces.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FluidInterfaces", "FluidInterfaces.csproj", "{C1F13BE3-B6F3-4A78-BC58-B3A789D00D64}" 5 | EndProject 6 | Global 7 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 8 | Debug|iPhoneSimulator = Debug|iPhoneSimulator 9 | Release|iPhone = Release|iPhone 10 | Release|iPhoneSimulator = Release|iPhoneSimulator 11 | Debug|iPhone = Debug|iPhone 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {C1F13BE3-B6F3-4A78-BC58-B3A789D00D64}.Debug|iPhoneSimulator.ActiveCfg = Debug|iPhoneSimulator 15 | {C1F13BE3-B6F3-4A78-BC58-B3A789D00D64}.Debug|iPhoneSimulator.Build.0 = Debug|iPhoneSimulator 16 | {C1F13BE3-B6F3-4A78-BC58-B3A789D00D64}.Release|iPhone.ActiveCfg = Release|iPhone 17 | {C1F13BE3-B6F3-4A78-BC58-B3A789D00D64}.Release|iPhone.Build.0 = Release|iPhone 18 | {C1F13BE3-B6F3-4A78-BC58-B3A789D00D64}.Release|iPhoneSimulator.ActiveCfg = Release|iPhoneSimulator 19 | {C1F13BE3-B6F3-4A78-BC58-B3A789D00D64}.Release|iPhoneSimulator.Build.0 = Release|iPhoneSimulator 20 | {C1F13BE3-B6F3-4A78-BC58-B3A789D00D64}.Debug|iPhone.ActiveCfg = Debug|iPhone 21 | {C1F13BE3-B6F3-4A78-BC58-B3A789D00D64}.Debug|iPhone.Build.0 = Debug|iPhone 22 | EndGlobalSection 23 | EndGlobal 24 | -------------------------------------------------------------------------------- /Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleName 6 | FluidInterfaces 7 | CFBundleIdentifier 8 | org.tirania.FluidInterfaces 9 | CFBundleShortVersionString 10 | 1.0 11 | CFBundleVersion 12 | 1.0 13 | LSRequiresIPhoneOS 14 | 15 | MinimumOSVersion 16 | 11.4 17 | UIDeviceFamily 18 | 19 | 1 20 | 2 21 | 22 | UILaunchStoryboardName 23 | LaunchScreen 24 | UIRequiredDeviceCapabilities 25 | 26 | armv7 27 | 28 | UISupportedInterfaceOrientations 29 | 30 | UIInterfaceOrientationPortrait 31 | UIInterfaceOrientationPortraitUpsideDown 32 | UIInterfaceOrientationLandscapeLeft 33 | UIInterfaceOrientationLandscapeRight 34 | 35 | XSLaunchImageAssets 36 | Assets.xcassets/LaunchImage.launchimage 37 | XSAppIconAssets 38 | Assets.xcassets/AppIcon.appiconset 39 | 40 | 41 | -------------------------------------------------------------------------------- /Utilities/GradientView.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using CoreGraphics; 3 | using UIKit; 4 | using Foundation; 5 | using System.Linq; 6 | using CoreAnimation; 7 | 8 | public class GradientView : UIView { 9 | UIColor topColor = UIColor.White, bottomColor = UIColor.Black; 10 | nfloat? cornerRadius; 11 | CAGradientLayer gradientLayer; 12 | 13 | public UIColor TopColor { 14 | get => topColor; 15 | set { 16 | topColor = value; 17 | UpdateGradientColors (); 18 | } 19 | } 20 | 21 | public UIColor BottomColor { 22 | get => bottomColor; 23 | set { 24 | bottomColor = value; 25 | UpdateGradientColors (); 26 | } 27 | } 28 | 29 | /// The corner radius of the view. 30 | /// If no value is provided, the default is 20% of the view's width. 31 | public nfloat? CornerRadius { 32 | get => cornerRadius; 33 | set { 34 | cornerRadius = value; 35 | LayoutSubviews (); 36 | } 37 | } 38 | 39 | public GradientView (CGRect rect) : base (rect) => Init (); 40 | public GradientView (NSCoder aCoder) : base (aCoder) => Init (); 41 | 42 | void Init () 43 | { 44 | gradientLayer = new CAGradientLayer () { 45 | Colors = new [] { topColor.CGColor, bottomColor.CGColor }, 46 | StartPoint = new CGPoint (0, 0), 47 | EndPoint = new CGPoint (0, 1) 48 | }; 49 | Layer.AddSublayer (gradientLayer); 50 | } 51 | 52 | public override void LayoutSubviews () 53 | { 54 | base.LayoutSubviews (); 55 | 56 | gradientLayer.Frame = Bounds; 57 | 58 | var maskLayer = new CAShapeLayer () { 59 | Path = UIBezierPath.FromRoundedRect (Bounds, cornerRadius ?? Bounds.Width * 0.2f).CGPath 60 | }; 61 | Layer.Mask = maskLayer; 62 | } 63 | 64 | void UpdateGradientColors () 65 | { 66 | gradientLayer.Colors = new [] { topColor.CGColor, bottomColor.CGColor }; 67 | } 68 | } -------------------------------------------------------------------------------- /LaunchScreen.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /AppDelegate.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Foundation; 3 | using MonoTouch.Dialog; 4 | using UIKit; 5 | 6 | 7 | [Register ("AppDelegate")] 8 | public class AppDelegate : UIApplicationDelegate { 9 | public override UIWindow Window { 10 | get; 11 | set; 12 | } 13 | UINavigationController navigation; 14 | 15 | void Push (string title, UIViewController uivc) 16 | { 17 | navigation.PushViewController(uivc, true); 18 | uivc.Title = title; 19 | } 20 | 21 | Element MakeButton (string title, UIViewController uvc) 22 | { 23 | return new StringElement (title, () => Push (title, uvc)); 24 | } 25 | 26 | public override bool FinishedLaunching (UIApplication application, NSDictionary launchOptions) 27 | { 28 | Window = new UIWindow (UIScreen.MainScreen.Bounds); 29 | Window.MakeKeyAndVisible (); 30 | navigation = new UINavigationController (); 31 | 32 | var menu = new RootElement ("Fluid Interfaces") { 33 | new Section ("Fluid Interfaces"){ 34 | MakeButton ("Calculator Button", new CalculatorButtonInterfaceViewController ()), 35 | MakeButton ("Spring animations", new SpringInterfaceViewController ()), 36 | MakeButton ("Flashlight button", new FlashlightButtonInterfaceViewController ()), 37 | MakeButton ("Rubberbanding", new RubberbandingViewController ()), 38 | MakeButton ("Acceleration pausing", new AccelerationViewController ()), 39 | MakeButton ("Rewarding momentum", new MomentumInterfaceViewController ()), 40 | // new StringElement ("Facetime PiP", () => Push (new ())), 41 | // new StringElement ("Rotation", () => Push (new ())), 42 | } 43 | }; 44 | var dv = new DialogViewController (menu); 45 | navigation.PushViewController (dv, true); 46 | Window.RootViewController = navigation; 47 | return true; 48 | } 49 | 50 | // This is the main entry point of the application. 51 | static void Main (string [] args) 52 | { 53 | UIApplication.Main (args, null, "AppDelegate"); 54 | } 55 | } -------------------------------------------------------------------------------- /Interfaces/Rubberbanding.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using UIKit; 3 | using CoreGraphics; 4 | using Foundation; 5 | using System.Collections.Generic; 6 | 7 | public class RubberbandingViewController : InterfaceViewController { 8 | GradientView rubberView = new GradientView (CGRect.Empty) { 9 | TopColor = Color.FromHex (0xff5b50), 10 | BottomColor = Color.FromHex (0xffc950) 11 | }; 12 | UIPanGestureRecognizer panRecognizer = new UIPanGestureRecognizer (); 13 | 14 | public override void ViewDidLoad () 15 | { 16 | base.ViewDidLoad (); 17 | 18 | View.AddSubview (rubberView); 19 | rubberView.Center (View); 20 | rubberView.WidthAnchor.ConstraintEqualTo (140).Active = true; 21 | rubberView.HeightAnchor.ConstraintEqualTo (160).Active = true; 22 | 23 | panRecognizer.AddTarget (Panned); 24 | rubberView.AddGestureRecognizer (panRecognizer); 25 | } 26 | 27 | CGPoint originalTouchPoint = CGPoint.Empty; 28 | 29 | void Panned (NSObject r) 30 | { 31 | var recognizer = r as UIPanGestureRecognizer; 32 | var touchPoint = recognizer.LocationInView (View); 33 | switch (recognizer.State) { 34 | case UIGestureRecognizerState.Began: 35 | originalTouchPoint = touchPoint; 36 | break; 37 | case UIGestureRecognizerState.Changed: 38 | var offset = touchPoint.Y - originalTouchPoint.Y; 39 | offset = offset > 0 ? NMath.Pow (offset, 0.7f) : -NMath.Pow (-offset, 0.7f); 40 | rubberView.Transform = CGAffineTransform.MakeTranslation (0, offset); 41 | break; 42 | case UIGestureRecognizerState.Ended: 43 | case UIGestureRecognizerState.Cancelled: 44 | var timingParameters = UISpringTiming.MakeTimingParameters (damping: 0.6f, response: .3f); 45 | var animator = new UIViewPropertyAnimator (duration: 0, parameters: timingParameters); 46 | animator.AddAnimations (() => rubberView.Transform = CGAffineTransform.MakeIdentity ()); 47 | animator.Interruptible = true; 48 | animator.StartAnimation (); 49 | break; 50 | default: 51 | break; 52 | } 53 | } 54 | } -------------------------------------------------------------------------------- /AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "20x20", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "20x20", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "29x29", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "29x29", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "40x40", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "40x40", 31 | "scale" : "3x" 32 | }, 33 | { 34 | "size" : "60x60", 35 | "idiom" : "iphone", 36 | "filename" : "icon120.png", 37 | "scale" : "2x" 38 | }, 39 | { 40 | "size" : "60x60", 41 | "idiom" : "iphone", 42 | "filename" : "icon180.png", 43 | "scale" : "3x" 44 | }, 45 | { 46 | "idiom" : "ipad", 47 | "size" : "20x20", 48 | "scale" : "1x" 49 | }, 50 | { 51 | "idiom" : "ipad", 52 | "size" : "20x20", 53 | "scale" : "2x" 54 | }, 55 | { 56 | "idiom" : "ipad", 57 | "size" : "29x29", 58 | "scale" : "1x" 59 | }, 60 | { 61 | "idiom" : "ipad", 62 | "size" : "29x29", 63 | "scale" : "2x" 64 | }, 65 | { 66 | "idiom" : "ipad", 67 | "size" : "40x40", 68 | "scale" : "1x" 69 | }, 70 | { 71 | "idiom" : "ipad", 72 | "size" : "40x40", 73 | "scale" : "2x" 74 | }, 75 | { 76 | "idiom" : "ipad", 77 | "size" : "76x76", 78 | "scale" : "1x" 79 | }, 80 | { 81 | "size" : "76x76", 82 | "idiom" : "ipad", 83 | "filename" : "icon152.png", 84 | "scale" : "2x" 85 | }, 86 | { 87 | "size" : "83.5x83.5", 88 | "idiom" : "ipad", 89 | "filename" : "icon167.png", 90 | "scale" : "2x" 91 | }, 92 | { 93 | "size" : "1024x1024", 94 | "idiom" : "ios-marketing", 95 | "filename" : "icon.png", 96 | "scale" : "1x" 97 | } 98 | ], 99 | "info" : { 100 | "version" : 1, 101 | "author" : "xcode" 102 | } 103 | } -------------------------------------------------------------------------------- /Interfaces/CalculatorButton.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using UIKit; 3 | using CoreGraphics; 4 | using Foundation; 5 | 6 | public class CalculatorButton : UIControl { 7 | UILabel label = new UILabel () { 8 | Font = UIFont.SystemFontOfSize (36, UIFontWeight.Regular), 9 | TextColor = UIColor.White, 10 | TextAlignment = UITextAlignment.Center 11 | }; 12 | 13 | UIViewPropertyAnimator animator = new UIViewPropertyAnimator (); 14 | UIColor normalColor = new UIColor (0.2f, 0.2f, 0.2f, 1); 15 | UIColor highlightedColor = new UIColor (0.45f, 0.45f, 0.45f, 1); 16 | 17 | int value; 18 | public int Value { 19 | get => value; 20 | set { 21 | this.value = value; 22 | label.Text = $"{value}"; 23 | } 24 | } 25 | 26 | void CalculatorButton_TouchDown (object sender, EventArgs e) 27 | { 28 | animator.StopAnimation (true); 29 | BackgroundColor = highlightedColor; 30 | } 31 | 32 | void CalculatorButton_TouchUp (object sender, EventArgs e) 33 | { 34 | animator = new UIViewPropertyAnimator ( 35 | duration: 0.5, 36 | curve: UIViewAnimationCurve.EaseOut, 37 | animations: () => { BackgroundColor = normalColor; }); 38 | animator.StartAnimation (); 39 | } 40 | 41 | void SharedInit () 42 | { 43 | BackgroundColor = normalColor; 44 | AddTarget (CalculatorButton_TouchDown, UIControlEvent.TouchDown | UIControlEvent.TouchDragEnter); 45 | AddTarget (CalculatorButton_TouchUp, UIControlEvent.TouchUpInside | UIControlEvent.TouchDragExit | UIControlEvent.TouchCancel); 46 | AddSubview (label); 47 | label.Center (this); 48 | } 49 | 50 | public CalculatorButton (CGRect frame) : base (frame) => SharedInit (); 51 | public CalculatorButton (NSCoder aCoder) : base (aCoder) => SharedInit (); 52 | 53 | public override CGSize IntrinsicContentSize => new CGSize (75, 75); 54 | 55 | public override void LayoutSubviews () 56 | { 57 | base.LayoutSubviews (); 58 | Layer.CornerRadius = Bounds.Width / 2; 59 | } 60 | } 61 | 62 | public class CalculatorButtonInterfaceViewController : InterfaceViewController { 63 | public CalculatorButtonInterfaceViewController () { } 64 | 65 | public override void ViewDidLoad () 66 | { 67 | base.ViewDidLoad (); 68 | var calculatorButton = new CalculatorButton (CGRect.Empty) { 69 | Value = 9 70 | }; 71 | View.AddSubview (calculatorButton); 72 | calculatorButton.Center (inView: View); 73 | } 74 | } 75 | 76 | -------------------------------------------------------------------------------- /Assets.xcassets/AppIcon.appiconset/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "20x20", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "20x20", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "29x29", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "29x29", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "40x40", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "40x40", 31 | "scale" : "3x" 32 | }, 33 | { 34 | "size" : "60x60", 35 | "idiom" : "iphone", 36 | "filename" : "icon120.png", 37 | "scale" : "2x" 38 | }, 39 | { 40 | "size" : "60x60", 41 | "idiom" : "iphone", 42 | "filename" : "icon180.png", 43 | "scale" : "3x" 44 | }, 45 | { 46 | "idiom" : "ipad", 47 | "size" : "20x20", 48 | "scale" : "1x" 49 | }, 50 | { 51 | "idiom" : "ipad", 52 | "size" : "20x20", 53 | "scale" : "2x" 54 | }, 55 | { 56 | "idiom" : "ipad", 57 | "size" : "29x29", 58 | "scale" : "1x" 59 | }, 60 | { 61 | "idiom" : "ipad", 62 | "size" : "29x29", 63 | "scale" : "2x" 64 | }, 65 | { 66 | "idiom" : "ipad", 67 | "size" : "40x40", 68 | "scale" : "1x" 69 | }, 70 | { 71 | "idiom" : "ipad", 72 | "size" : "40x40", 73 | "scale" : "2x" 74 | }, 75 | { 76 | "idiom" : "ipad", 77 | "size" : "76x76", 78 | "scale" : "1x" 79 | }, 80 | { 81 | "size" : "76x76", 82 | "idiom" : "ipad", 83 | "filename" : "icon152.png", 84 | "scale" : "2x" 85 | }, 86 | { 87 | "size" : "83.5x83.5", 88 | "idiom" : "ipad", 89 | "filename" : "icon167.png", 90 | "scale" : "2x" 91 | }, 92 | { 93 | "size" : "1024x1024", 94 | "idiom" : "ios-marketing", 95 | "filename" : "icon.png", 96 | "scale" : "1x" 97 | } 98 | ], 99 | "info" : { 100 | "version" : 1, 101 | "author" : "xcode" 102 | } 103 | } -------------------------------------------------------------------------------- /Utilities/SliderView.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using CoreGraphics; 3 | using UIKit; 4 | using Foundation; 5 | using System.Linq; 6 | 7 | public class SliderView : UIView { 8 | void HandleEventHandler (object sender, EventArgs e) 9 | { 10 | } 11 | 12 | 13 | UILabel titleLabel = new UILabel (CGRect.Empty) { 14 | TranslatesAutoresizingMaskIntoConstraints = false, 15 | TextColor = UIColor.White, 16 | Font = UIFont.SystemFontOfSize (16, UIFontWeight.Bold) 17 | }; 18 | UILabel valueLabel = new UILabel (CGRect.Empty) { 19 | TranslatesAutoresizingMaskIntoConstraints = false, 20 | Font = UIFont.SystemFontOfSize (16, UIFontWeight.Bold), 21 | TextColor = UIColor.White, 22 | Text = "0" 23 | }; 24 | UISlider slider; 25 | 26 | string title; 27 | public string Title { 28 | get => title; 29 | set { 30 | title = value; 31 | titleLabel.Text = title; 32 | } 33 | } 34 | 35 | nfloat value; 36 | public nfloat Value { 37 | get => value; 38 | set { 39 | this.value = value; 40 | slider.Value = (float)value; 41 | valueLabel.Text = $"{value:f2}"; 42 | } 43 | } 44 | 45 | float minValue = 0, maxValue = 1; 46 | public float MinValue { 47 | get => minValue; 48 | set { 49 | minValue = value; 50 | slider.MinValue = value; 51 | } 52 | } 53 | 54 | public float MaxValue { 55 | get => maxValue; 56 | set { 57 | maxValue = value; 58 | slider.MaxValue = value; 59 | } 60 | } 61 | 62 | public Action SliderMoved; 63 | public Action SliderFinishedMoving; 64 | 65 | void SharedInit () 66 | { 67 | slider = new UISlider () { 68 | TranslatesAutoresizingMaskIntoConstraints = true 69 | }; 70 | AddSubview (titleLabel); 71 | titleLabel.LeadingAnchor.ConstraintEqualTo (LeadingAnchor).Active = true; 72 | titleLabel.TopAnchor.ConstraintEqualTo (TopAnchor).Active = true; 73 | 74 | AddSubview (valueLabel); 75 | valueLabel.TrailingAnchor.ConstraintEqualTo (TrailingAnchor).Active = true; 76 | valueLabel.LastBaselineAnchor.ConstraintEqualTo (LastBaselineAnchor).Active = true; 77 | 78 | AddSubview (slider); 79 | slider.LeadingAnchor.ConstraintEqualTo (LeadingAnchor).Active = true; 80 | slider.TrailingAnchor.ConstraintEqualTo (TrailingAnchor).Active = true; 81 | slider.BottomAnchor.ConstraintEqualTo (BottomAnchor).Active = true; 82 | slider.TopAnchor.ConstraintEqualTo (TopAnchor, 20).Active = true; 83 | 84 | slider.AddTarget (this, new ObjCRuntime.Selector ("slider:event:"), UIControlEvent.ValueChanged); 85 | } 86 | 87 | public SliderView (CGRect rect) : base (rect) => SharedInit (); 88 | public SliderView (NSCoder aCoder) : base (aCoder) => SharedInit (); 89 | 90 | [Export ("slider:event:")] 91 | void SliderMovedEvent (UISlider senderSlider, UIEvent uievent) 92 | { 93 | valueLabel.Text = $"{senderSlider.Value:f2}"; 94 | if (SliderMoved != null) 95 | SliderMoved (senderSlider.Value); 96 | 97 | if ((uievent.AllTouches?.FirstOrDefault () as UITouch)?.Phase == UITouchPhase.Ended) 98 | if (SliderFinishedMoving != null) 99 | SliderFinishedMoving (); 100 | 101 | } 102 | } 103 | -------------------------------------------------------------------------------- /Interfaces/Spring.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using CoreGraphics; 3 | using UIKit; 4 | 5 | public class SpringInterfaceViewController : InterfaceViewController { 6 | nfloat dampingRatio = 0.5f, frequencyResponse = 1, margin = 30; 7 | GradientView springView; 8 | SliderView dampingSliderView, frequencySliderView; 9 | UIViewPropertyAnimator animator = new UIViewPropertyAnimator (); 10 | 11 | public SpringInterfaceViewController () 12 | { 13 | springView = new GradientView (CGRect.Empty) { 14 | TranslatesAutoresizingMaskIntoConstraints = false, 15 | TopColor = new UIColor (.39f, .8f, .96f, 1), 16 | BottomColor = new UIColor (.20f, .61f, .92f, 1) 17 | }; 18 | dampingSliderView = new SliderView (CGRect.Empty) { 19 | TranslatesAutoresizingMaskIntoConstraints = false, 20 | Title = "DAMPING (BOUNCINESS)", 21 | MinValue = 0.1f, 22 | MaxValue = 1, 23 | Value = dampingRatio, 24 | SliderMoved = (x) => dampingRatio = x, 25 | SliderFinishedMoving = () => ResetAnimation () 26 | }; 27 | 28 | frequencySliderView = new SliderView (CGRect.Empty) { 29 | TranslatesAutoresizingMaskIntoConstraints = false, 30 | Title = "RESPONSE (SPEED)", 31 | MinValue = 0.1f, 32 | MaxValue = 2f, 33 | Value = frequencyResponse, 34 | SliderMoved = (x) => frequencyResponse = x, 35 | SliderFinishedMoving = () => ResetAnimation () 36 | }; 37 | } 38 | 39 | void AnchorEqual (NSLayoutXAxisAnchor target, NSLayoutXAxisAnchor host, nfloat margin) => target.ConstraintEqualTo (host, margin).Active = true; 40 | void AnchorEqual (NSLayoutYAxisAnchor target, NSLayoutYAxisAnchor host, nfloat margin) => target.ConstraintEqualTo (host, margin).Active = true; 41 | 42 | public override void ViewDidLoad () 43 | { 44 | base.ViewDidLoad (); 45 | View.AddSubview (dampingSliderView); 46 | AnchorEqual (dampingSliderView.LeadingAnchor, View.LeadingAnchor, margin); 47 | AnchorEqual (dampingSliderView.TrailingAnchor, View.TrailingAnchor, -margin); 48 | AnchorEqual (dampingSliderView.CenterYAnchor, View.CenterYAnchor, 0); 49 | 50 | View.AddSubview (frequencySliderView); 51 | AnchorEqual (frequencySliderView.LeadingAnchor, View.LeadingAnchor, margin); 52 | AnchorEqual (frequencySliderView.TrailingAnchor, View.TrailingAnchor, -margin); 53 | AnchorEqual (frequencySliderView.CenterYAnchor, View.CenterYAnchor, 0); 54 | 55 | View.AddSubview (springView); 56 | springView.HeightAnchor.ConstraintEqualTo (80).Active = true; 57 | springView.WidthAnchor.ConstraintEqualTo (80).Active = true; 58 | AnchorEqual (springView.LeadingAnchor, View.LeadingAnchor, margin); 59 | AnchorEqual (springView.BottomAnchor, View.BottomAnchor, -80); 60 | } 61 | 62 | void AnimateView () 63 | { 64 | var timingParameters = UISpringTiming.MakeTimingParameters (damping: dampingRatio, response: frequencyResponse); 65 | animator = new UIViewPropertyAnimator (duration: 0, parameters: timingParameters); 66 | animator.AddAnimations (() => { 67 | var translation = View.Bounds.Width - 2 * margin - 80; 68 | 69 | springView.Transform = CGAffineTransform.MakeTranslation (translation, 0); 70 | }); 71 | animator.AddCompletion ((x) => { 72 | springView.Transform = CGAffineTransform.MakeIdentity (); 73 | AnimateView (); 74 | }); 75 | animator.StartAnimation (); 76 | } 77 | 78 | void ResetAnimation () 79 | { 80 | animator.StopAnimation (true); 81 | springView.Transform = CGAffineTransform.MakeIdentity (); 82 | AnimateView (); 83 | } 84 | } -------------------------------------------------------------------------------- /Interfaces/Acceleration.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using UIKit; 3 | using CoreGraphics; 4 | using Foundation; 5 | using System.Collections.Generic; 6 | 7 | public class AccelerationViewController : InterfaceViewController { 8 | UILabel pauseLabel; 9 | GradientView accelerationView; 10 | UIPanGestureRecognizer panRecognizer = new UIPanGestureRecognizer (); 11 | UIImpactFeedbackGenerator feedbackGenerator = new UIImpactFeedbackGenerator (UIImpactFeedbackStyle.Light); 12 | nfloat verticalOffset = 180; 13 | 14 | public override void ViewDidLoad () 15 | { 16 | base.ViewDidLoad (); 17 | 18 | pauseLabel = new UILabel (CGRect.Empty) { 19 | Text = "Paused", 20 | Font = UIFont.BoldSystemFontOfSize (16), 21 | TextColor = UIColor.White, 22 | TextAlignment = UITextAlignment.Center, 23 | TranslatesAutoresizingMaskIntoConstraints = true, 24 | Alpha = 0 25 | }; 26 | 27 | accelerationView = new GradientView (CGRect.Empty) { 28 | TopColor = Color.FromHex (0x64ff8f), 29 | BottomColor = Color.FromHex (0x51ffea) 30 | }; 31 | 32 | View.AddSubview (pauseLabel); 33 | pauseLabel.CenterXAnchor.ConstraintEqualTo (View.CenterXAnchor).Active = true; 34 | pauseLabel.TopAnchor.ConstraintEqualTo (View.SafeAreaLayoutGuide.TopAnchor, 40); 35 | 36 | View.AddSubview (accelerationView); 37 | accelerationView.Center (View, new UIOffset (0, verticalOffset)); 38 | accelerationView.WidthAnchor.ConstraintEqualTo (160).Active = true; 39 | accelerationView.HeightAnchor.ConstraintEqualTo (160).Active = true; 40 | 41 | panRecognizer.AddTarget (Panned); 42 | accelerationView.AddGestureRecognizer (panRecognizer); 43 | } 44 | 45 | CGPoint originalTouchPoint = CGPoint.Empty; 46 | 47 | void Panned (NSObject r) 48 | { 49 | var recognizer = r as UIPanGestureRecognizer; 50 | var touchPoint = recognizer.LocationInView (View); 51 | var velocity = recognizer.VelocityInView (View); 52 | switch (recognizer.State) { 53 | case UIGestureRecognizerState.Began: 54 | originalTouchPoint = touchPoint; 55 | break; 56 | case UIGestureRecognizerState.Changed: 57 | var offset = touchPoint.Y - originalTouchPoint.Y; 58 | if (offset > 0) 59 | offset = NMath.Pow (offset, 0.7f); 60 | else if (offset < -verticalOffset * 2) { 61 | offset = -verticalOffset * 2 - NMath.Pow (-(offset + verticalOffset * 2f), 0.7f); 62 | } 63 | accelerationView.Transform = CGAffineTransform.MakeTranslation (0, offset); 64 | TrackPause (velocity.Y, offset); 65 | break; 66 | case UIGestureRecognizerState.Ended: 67 | case UIGestureRecognizerState.Cancelled: 68 | var timingParameters = UISpringTiming.MakeTimingParameters (damping: 0.8f, response: 0.3f); 69 | var animator = new UIViewPropertyAnimator (0, timingParameters); 70 | animator.AddAnimations (() => { 71 | accelerationView.Transform = CGAffineTransform.MakeIdentity (); 72 | pauseLabel.Alpha = 0; 73 | }); 74 | animator.Interruptible = true; 75 | animator.StartAnimation (); 76 | hasPaused = false; 77 | break; 78 | default: 79 | break; 80 | } 81 | } 82 | 83 | /// The number of past velocities to track. 84 | int numberOfVelocities = 7; 85 | 86 | /// The array of past velocities. 87 | List velocities = new List (); 88 | 89 | /// Whether the view is considered paused 90 | bool hasPaused; 91 | void TrackPause (nfloat velocity, nfloat offset) 92 | { 93 | if (hasPaused) 94 | return; 95 | 96 | // update the array of most recent velocities 97 | 98 | if (velocities.Count >= numberOfVelocities) 99 | velocities.RemoveAt (0); 100 | velocities.Add (velocity); 101 | // enforce minimum velocity and offset 102 | if (NMath.Abs (velocity) > 100 || Math.Abs (offset) < 50) 103 | return; 104 | var firstRecorded = velocities [0]; 105 | // if the majority of the velocity has been lost recetly, we consider the motion to be paused 106 | 107 | if (NMath.Abs (firstRecorded - velocity) / NMath.Abs (firstRecorded) > 0.9) { 108 | pauseLabel.Alpha = 1; 109 | feedbackGenerator.ImpactOccurred (); 110 | hasPaused = true; 111 | velocities.Clear (); 112 | } 113 | } 114 | } -------------------------------------------------------------------------------- /Interfaces/FlashlightButton.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using CoreGraphics; 3 | using UIKit; 4 | using Foundation; 5 | using System.Linq; 6 | 7 | class FlashlightButtonInterfaceViewController : InterfaceViewController { 8 | public override void ViewDidLoad () 9 | { 10 | base.ViewDidLoad (); 11 | var flashlightButton = new FlashlightButton (); 12 | View.AddSubview (flashlightButton); 13 | flashlightButton.Center (View); 14 | } 15 | } 16 | 17 | class FlashlightButton : UIControl { 18 | enum ForceState { 19 | // The button is ready to be activiated. Default state. 20 | Reset, 21 | // The button has been pressed with enough force. 22 | Activated, 23 | // The button has recently switched on/off. 24 | Confirmed 25 | } 26 | 27 | UIImage onImage, offImage; 28 | UIImageView imageView; 29 | bool isOn = false; 30 | ForceState forceState = ForceState.Reset; 31 | bool touchExited = false; 32 | UIImpactFeedbackGenerator activationFeedbackGenerator, confirmationFeedbackGenerator; 33 | nfloat minWidth = 50; 34 | nfloat maxWidth = 92; 35 | nfloat activationForce = 0.5f; 36 | nfloat confirmationForce = 0.49f; 37 | nfloat resetForce = 0.4f; 38 | UIColor offColor = UIColor.FromWhiteAlpha (0.2f, 1); 39 | UIColor onColor = UIColor.FromWhiteAlpha (0.95f, 1); 40 | 41 | public FlashlightButton (CGRect frame) : base (frame) => Init (); 42 | public FlashlightButton () : base (CGRect.Empty) => Init (); 43 | public FlashlightButton (NSCoder aCoder) : base (aCoder) => Init (); 44 | 45 | void Init () 46 | { 47 | onImage = UIImage.FromBundle ("flaslight_on"); 48 | offImage = UIImage.FromBundle ("flaslight_off"); 49 | BackgroundColor = offColor; 50 | 51 | imageView = new UIImageView () { 52 | Image = offImage, 53 | TintColor = UIColor.White 54 | }; 55 | AddSubview (imageView); 56 | imageView.Pin (this); 57 | } 58 | 59 | public override CGSize IntrinsicContentSize => new CGSize (minWidth, minWidth); 60 | 61 | public override void LayoutSubviews () 62 | { 63 | base.LayoutSubviews (); 64 | Layer.CornerRadius = Bounds.Width / 2; 65 | } 66 | 67 | void TouchMoved (UITouch touch) 68 | { 69 | if (touch == null) 70 | return; 71 | if (touchExited) 72 | return; 73 | var cancelDistance = minWidth / 2 + 20; 74 | if (touch.LocationInView (this).Distance (new CGPoint (Bounds.GetMidX (), Bounds.GetMidY ())) < cancelDistance) { 75 | // the touch has moved outside of the bounds of the button 76 | touchExited = true; 77 | forceState = ForceState.Reset; 78 | AnimateToRest (); 79 | return; 80 | } 81 | var force = touch.Force / touch.MaximumPossibleForce; 82 | var scale = 1 + (maxWidth / minWidth - 1) * force; 83 | 84 | // update the button's size and color 85 | Transform = CGAffineTransform.MakeScale (scale, scale); 86 | if (!isOn) { 87 | BackgroundColor = UIColor.FromWhiteAlpha (0.2f - force * 0.2f, 1); 88 | } 89 | switch (forceState) { 90 | case ForceState.Reset: 91 | if (force > activationForce) { 92 | forceState = ForceState.Activated; 93 | activationFeedbackGenerator.ImpactOccurred (); 94 | } 95 | break; 96 | case ForceState.Activated: 97 | if (force <= confirmationForce) { 98 | forceState = ForceState.Confirmed; 99 | Activate (); 100 | } 101 | break; 102 | case ForceState.Confirmed: 103 | if (force <= resetForce) 104 | forceState = ForceState.Reset; 105 | 106 | break; 107 | } 108 | } 109 | 110 | void TouchEnded (UITouch touch) 111 | { 112 | if (touch == null) 113 | return; 114 | if (touchExited) 115 | return; 116 | forceState = ForceState.Reset; 117 | AnimateToRest (); 118 | } 119 | 120 | void Activate () 121 | { 122 | isOn = !isOn; 123 | imageView.Image = isOn ? onImage : offImage; 124 | imageView.TintColor = isOn ? UIColor.Black : UIColor.White; 125 | BackgroundColor = isOn ? onColor : offColor; 126 | confirmationFeedbackGenerator.ImpactOccurred (); 127 | } 128 | 129 | void AnimateToRest () 130 | { 131 | var timingParameters = UISpringTiming.MakeTimingParameters (damping: 0.4f, response: 0.2f); 132 | var animator = new UIViewPropertyAnimator (duration: 0, parameters: timingParameters); 133 | animator.AddAnimations (() => { 134 | Transform = CGAffineTransform.MakeScale (1, 1); 135 | BackgroundColor = isOn ? onColor : offColor; 136 | }); 137 | animator.Interruptible = true; 138 | animator.StartAnimation (); 139 | } 140 | 141 | public override void TouchesBegan (NSSet touches, UIEvent evt) 142 | { 143 | base.TouchesBegan (touches, evt); 144 | touchExited = false; 145 | TouchMoved (touches.FirstOrDefault () as UITouch); 146 | } 147 | 148 | public override void TouchesMoved (NSSet touches, UIEvent evt) 149 | { 150 | base.TouchesMoved (touches, evt); 151 | TouchMoved (touches.FirstOrDefault () as UITouch); 152 | } 153 | 154 | public override void TouchesEnded (NSSet touches, UIEvent evt) 155 | { 156 | base.TouchesEnded (touches, evt); 157 | TouchEnded (touches.FirstOrDefault () as UITouch); 158 | } 159 | 160 | public override void TouchesCancelled (NSSet touches, UIEvent evt) 161 | { 162 | base.TouchesCancelled (touches, evt); 163 | TouchEnded (touches.FirstOrDefault () as UITouch); 164 | } 165 | } -------------------------------------------------------------------------------- /Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images": [ 3 | { 4 | "size": "20x20", 5 | "scale": "2x", 6 | "idiom": "iphone" 7 | }, 8 | { 9 | "size": "20x20", 10 | "scale": "3x", 11 | "idiom": "iphone" 12 | }, 13 | { 14 | "size": "29x29", 15 | "scale": "2x", 16 | "idiom": "iphone" 17 | }, 18 | { 19 | "size": "29x29", 20 | "scale": "3x", 21 | "idiom": "iphone" 22 | }, 23 | { 24 | "size": "40x40", 25 | "scale": "2x", 26 | "idiom": "iphone" 27 | }, 28 | { 29 | "filename": "icon120-1.png", 30 | "size": "40x40", 31 | "scale": "3x", 32 | "idiom": "iphone" 33 | }, 34 | { 35 | "filename": "icon120.png", 36 | "size": "60x60", 37 | "scale": "2x", 38 | "idiom": "iphone" 39 | }, 40 | { 41 | "filename": "icon180.png", 42 | "size": "60x60", 43 | "scale": "3x", 44 | "idiom": "iphone" 45 | }, 46 | { 47 | "size": "20x20", 48 | "scale": "1x", 49 | "idiom": "ipad" 50 | }, 51 | { 52 | "size": "20x20", 53 | "scale": "2x", 54 | "idiom": "ipad" 55 | }, 56 | { 57 | "size": "29x29", 58 | "scale": "1x", 59 | "idiom": "ipad" 60 | }, 61 | { 62 | "size": "29x29", 63 | "scale": "2x", 64 | "idiom": "ipad" 65 | }, 66 | { 67 | "size": "40x40", 68 | "scale": "1x", 69 | "idiom": "ipad" 70 | }, 71 | { 72 | "size": "40x40", 73 | "scale": "2x", 74 | "idiom": "ipad" 75 | }, 76 | { 77 | "filename": "icon167.png", 78 | "size": "83.5x83.5", 79 | "scale": "2x", 80 | "idiom": "ipad" 81 | }, 82 | { 83 | "size": "76x76", 84 | "scale": "1x", 85 | "idiom": "ipad" 86 | }, 87 | { 88 | "filename": "icon152.png", 89 | "size": "76x76", 90 | "scale": "2x", 91 | "idiom": "ipad" 92 | }, 93 | { 94 | "filename": "icon.png", 95 | "size": "1024x1024", 96 | "scale": "1x", 97 | "idiom": "ios-marketing" 98 | }, 99 | { 100 | "size": "60x60", 101 | "scale": "2x", 102 | "idiom": "car" 103 | }, 104 | { 105 | "size": "60x60", 106 | "scale": "3x", 107 | "idiom": "car" 108 | }, 109 | { 110 | "role": "notificationCenter", 111 | "size": "24x24", 112 | "subtype": "38mm", 113 | "scale": "2x", 114 | "idiom": "watch" 115 | }, 116 | { 117 | "role": "notificationCenter", 118 | "size": "27.5x27.5", 119 | "subtype": "42mm", 120 | "scale": "2x", 121 | "idiom": "watch" 122 | }, 123 | { 124 | "role": "companionSettings", 125 | "size": "29x29", 126 | "scale": "2x", 127 | "idiom": "watch" 128 | }, 129 | { 130 | "role": "companionSettings", 131 | "size": "29x29", 132 | "scale": "3x", 133 | "idiom": "watch" 134 | }, 135 | { 136 | "role": "appLauncher", 137 | "size": "40x40", 138 | "subtype": "38mm", 139 | "scale": "2x", 140 | "idiom": "watch" 141 | }, 142 | { 143 | "role": "appLauncher", 144 | "size": "44x44", 145 | "subtype": "40mm", 146 | "scale": "2x", 147 | "idiom": "watch" 148 | }, 149 | { 150 | "role": "appLauncher", 151 | "size": "50x50", 152 | "subtype": "44mm", 153 | "scale": "2x", 154 | "idiom": "watch" 155 | }, 156 | { 157 | "role": "quickLook", 158 | "size": "86x86", 159 | "subtype": "38mm", 160 | "scale": "2x", 161 | "idiom": "watch" 162 | }, 163 | { 164 | "role": "quickLook", 165 | "size": "98x98", 166 | "subtype": "42mm", 167 | "scale": "2x", 168 | "idiom": "watch" 169 | }, 170 | { 171 | "role": "quickLook", 172 | "size": "108x108", 173 | "subtype": "44mm", 174 | "scale": "2x", 175 | "idiom": "watch" 176 | }, 177 | { 178 | "size": "1024x1024", 179 | "scale": "1x", 180 | "idiom": "watch-marketing" 181 | }, 182 | { 183 | "size": "16x16", 184 | "scale": "1x", 185 | "idiom": "mac" 186 | }, 187 | { 188 | "size": "16x16", 189 | "scale": "2x", 190 | "idiom": "mac" 191 | }, 192 | { 193 | "size": "32x32", 194 | "scale": "1x", 195 | "idiom": "mac" 196 | }, 197 | { 198 | "size": "32x32", 199 | "scale": "2x", 200 | "idiom": "mac" 201 | }, 202 | { 203 | "size": "128x128", 204 | "scale": "1x", 205 | "idiom": "mac" 206 | }, 207 | { 208 | "size": "128x128", 209 | "scale": "2x", 210 | "idiom": "mac" 211 | }, 212 | { 213 | "size": "256x256", 214 | "scale": "1x", 215 | "idiom": "mac" 216 | }, 217 | { 218 | "size": "256x256", 219 | "scale": "2x", 220 | "idiom": "mac" 221 | }, 222 | { 223 | "size": "512x512", 224 | "scale": "1x", 225 | "idiom": "mac" 226 | }, 227 | { 228 | "size": "512x512", 229 | "scale": "2x", 230 | "idiom": "mac" 231 | } 232 | ], 233 | "info": { 234 | "version": 1, 235 | "author": "xcode" 236 | } 237 | } -------------------------------------------------------------------------------- /Interfaces/RewardingMomentum.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using UIKit; 3 | using CoreGraphics; 4 | using Foundation; 5 | 6 | public class MomentumInterfaceViewController : InterfaceViewController { 7 | GradientView momentumView; 8 | bool isOpen; 9 | nfloat animationProgress = 0; 10 | CGAffineTransform closedTransform = CGAffineTransform.MakeIdentity (); 11 | UIViewPropertyAnimator animator = new UIViewPropertyAnimator (); 12 | UIView handleView; 13 | 14 | public MomentumInterfaceViewController () 15 | { 16 | momentumView = new GradientView (CGRect.Empty) { 17 | TranslatesAutoresizingMaskIntoConstraints = false, 18 | BackgroundColor = UIColor.FromWhiteAlpha (white: 0.3f, alpha: 1), 19 | TopColor = Color.FromHex (0x61A8FF), 20 | BottomColor = Color.FromHex (hex: 0x243BD1), 21 | CornerRadius = 30f, 22 | }; 23 | handleView = new UIView () { 24 | TranslatesAutoresizingMaskIntoConstraints = false, 25 | BackgroundColor = UIColor.FromWhiteAlpha (white: 1, alpha: 0.5f), 26 | }; 27 | } 28 | 29 | public override void ViewDidLoad () 30 | { 31 | base.ViewDidLoad (); 32 | View.AddSubview (momentumView); 33 | 34 | handleView.Layer.CornerRadius = 3; 35 | 36 | momentumView.LeadingAnchor.ConstraintEqualTo (View.LeadingAnchor).Active = true; 37 | momentumView.TrailingAnchor.ConstraintEqualTo (View.TrailingAnchor, constant: -8).Active = true; 38 | momentumView.BottomAnchor.ConstraintEqualTo (View.BottomAnchor, constant: 80).Active = true; 39 | momentumView.TopAnchor.ConstraintEqualTo (View.SafeAreaLayoutGuide.TopAnchor, constant: 80).Active = true; 40 | 41 | 42 | momentumView.AddSubview (handleView); 43 | handleView.TopAnchor.ConstraintEqualTo (momentumView.TopAnchor, constant: 10).Active = true; 44 | handleView.WidthAnchor.ConstraintEqualTo (50).Active = true; 45 | handleView.HeightAnchor.ConstraintEqualTo (5).Active = true; 46 | handleView.CenterXAnchor.ConstraintEqualTo (momentumView.CenterXAnchor).Active = true; 47 | 48 | var panRecognizer = new InstantPanGestureRecognizer (); 49 | 50 | closedTransform = CGAffineTransform.MakeTranslation (0, View.Bounds.Height * 0.6f); 51 | momentumView.Transform = closedTransform; 52 | 53 | panRecognizer.AddTarget (Panned); 54 | momentumView.AddGestureRecognizer (panRecognizer); 55 | } 56 | 57 | void Panned (object r) 58 | { 59 | var recognizer = r as UIPanGestureRecognizer; 60 | switch (recognizer.State) { 61 | case UIGestureRecognizerState.Began: 62 | StartAnimationIfNeeded (); 63 | animator.PauseAnimation (); 64 | animationProgress = animator.FractionComplete; 65 | break; 66 | case UIGestureRecognizerState.Changed: 67 | var fraction = -recognizer.TranslationInView (momentumView).Y / closedTransform.y0; 68 | if (isOpen) 69 | fraction *= -1; 70 | 71 | if (animator.Reversed) 72 | fraction *= -1; 73 | 74 | animator.FractionComplete = fraction + animationProgress; 75 | break; 76 | case UIGestureRecognizerState.Ended: 77 | case UIGestureRecognizerState.Cancelled: 78 | var yVelocity = recognizer.VelocityInView (momentumView).Y; 79 | var shouldClose = yVelocity > 0; // todo: should use projection instead 80 | 81 | if (yVelocity == 0) { 82 | animator.ContinueAnimation (parameters: null, durationFactor: 0); 83 | break; 84 | } 85 | if (isOpen) { 86 | if (!shouldClose && !animator.Reversed) animator.Reversed = !animator.Reversed; 87 | if (shouldClose && animator.Reversed) animator.Reversed = !animator.Reversed; 88 | } else { 89 | if (shouldClose && !animator.Reversed) animator.Reversed = !animator.Reversed; 90 | if (!shouldClose && animator.Reversed) animator.Reversed = !animator.Reversed; 91 | } 92 | var fractionRemaining = 1 - animator.FractionComplete; 93 | 94 | var distanceRemaining = fractionRemaining * closedTransform.y0; 95 | 96 | if (distanceRemaining == 0) { 97 | animator.ContinueAnimation (null, 0); 98 | break; 99 | } 100 | 101 | var relativeVelocity = NMath.Min (NMath.Abs (yVelocity) / distanceRemaining, 30); 102 | var timingParameters = UISpringTiming.MakeTimingParameters (damping: 0.8f, response: 0.3f, initialVelocity: new CGVector (dx: relativeVelocity, dy: relativeVelocity)); 103 | var preferredDuration = new UIViewPropertyAnimator (duration: 0, parameters: timingParameters).Duration; 104 | var durationFactor = preferredDuration / animator.Duration; 105 | animator.ContinueAnimation (parameters: timingParameters, durationFactor: (nfloat) durationFactor); 106 | break; 107 | default: 108 | break; 109 | } 110 | } 111 | 112 | private void StartAnimationIfNeeded () 113 | { 114 | if (animator.Running) 115 | return; 116 | 117 | var timingParameters = UISpringTiming.MakeTimingParameters (damping: 1, response: 0.4f); 118 | animator = new UIViewPropertyAnimator (0, timingParameters); 119 | animator.AddAnimations (() => { 120 | momentumView.Transform = isOpen ? closedTransform : CGAffineTransform.MakeIdentity (); 121 | }); 122 | animator.AddCompletion ((position) => { 123 | if (position == UIViewAnimatingPosition.End) { 124 | isOpen = !isOpen; 125 | } 126 | }); 127 | 128 | animator.StartAnimation (); 129 | } 130 | } 131 | 132 | class InstantPanGestureRecognizer : UIPanGestureRecognizer { 133 | public override void TouchesBegan (NSSet touches, UIEvent evt) 134 | { 135 | base.TouchesBegan (touches, evt); 136 | State = UIGestureRecognizerState.Began; 137 | } 138 | } -------------------------------------------------------------------------------- /Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | -------------------------------------------------------------------------------- /FluidInterfaces.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | Debug 4 | iPhoneSimulator 5 | {C1F13BE3-B6F3-4A78-BC58-B3A789D00D64} 6 | {FEACFBD2-3405-455C-9665-78FE426C6842};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} 7 | Exe 8 | FluidInterfaces 9 | FluidInterfaces 10 | Resources 11 | 12 | 13 | true 14 | full 15 | false 16 | bin\iPhoneSimulator\Debug 17 | DEBUG;ENABLE_TEST_CLOUD; 18 | prompt 19 | 4 20 | iPhone Developer 21 | true 22 | true 23 | true 24 | true 25 | 24044 26 | None 27 | x86_64 28 | NSUrlSessionHandler 29 | x86 30 | 31 | 32 | pdbonly 33 | true 34 | bin\iPhone\Release 35 | prompt 36 | 4 37 | iPhone Developer 38 | true 39 | true 40 | Entitlements.plist 41 | SdkOnly 42 | ARM64 43 | NSUrlSessionHandler 44 | x86 45 | 46 | 47 | pdbonly 48 | true 49 | bin\iPhoneSimulator\Release 50 | prompt 51 | 4 52 | iPhone Developer 53 | true 54 | None 55 | x86_64 56 | NSUrlSessionHandler 57 | x86 58 | 59 | 60 | true 61 | full 62 | false 63 | bin\iPhone\Debug 64 | DEBUG;ENABLE_TEST_CLOUD; 65 | prompt 66 | 4 67 | iPhone Developer 68 | true 69 | true 70 | true 71 | true 72 | true 73 | true 74 | Entitlements.plist 75 | 54474 76 | SdkOnly 77 | ARM64 78 | NSUrlSessionHandler 79 | x86 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | packages\MonoTouch.Dialog.2.0.0-pre1\lib\XamariniOS10\MonoTouch.Dialog.dll 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | --------------------------------------------------------------------------------