From 11567e67133ba4d27a4337e09d6dd1bf5f459c7a Mon Sep 17 00:00:00 2001 From: Rui Marinho Date: Fri, 6 Jan 2017 01:35:58 +0000 Subject: [PATCH] [Xamarin] Add Yoga/YogaKit identical to native objc version --- .../AppDelegate.cs | 59 +++++++ .../AppIcon.appiconset/Contents.json | 157 ++++++++++++++++++ .../Assets.xcassets/Contents.json | 6 + .../Entitlements.plist | 6 + .../Facebook.YogaKit.iOS.Sample.csproj | 128 ++++++++++++++ .../Facebook.YogaKit.iOS.Sample/Info.plist | 39 +++++ .../LaunchScreen.storyboard | 27 +++ .../Facebook.YogaKit.iOS.Sample/Main.cs | 15 ++ .../Main.storyboard | 25 +++ .../ViewController.cs | 60 +++++++ .../ViewController.designer.cs | 17 ++ 11 files changed, 539 insertions(+) create mode 100644 csharp/Xamarin.iOS/Facebook.YogaKit.iOS.Sample/AppDelegate.cs create mode 100644 csharp/Xamarin.iOS/Facebook.YogaKit.iOS.Sample/Assets.xcassets/AppIcon.appiconset/Contents.json create mode 100644 csharp/Xamarin.iOS/Facebook.YogaKit.iOS.Sample/Assets.xcassets/Contents.json create mode 100644 csharp/Xamarin.iOS/Facebook.YogaKit.iOS.Sample/Entitlements.plist create mode 100644 csharp/Xamarin.iOS/Facebook.YogaKit.iOS.Sample/Facebook.YogaKit.iOS.Sample.csproj create mode 100644 csharp/Xamarin.iOS/Facebook.YogaKit.iOS.Sample/Info.plist create mode 100644 csharp/Xamarin.iOS/Facebook.YogaKit.iOS.Sample/LaunchScreen.storyboard create mode 100644 csharp/Xamarin.iOS/Facebook.YogaKit.iOS.Sample/Main.cs create mode 100644 csharp/Xamarin.iOS/Facebook.YogaKit.iOS.Sample/Main.storyboard create mode 100644 csharp/Xamarin.iOS/Facebook.YogaKit.iOS.Sample/ViewController.cs create mode 100644 csharp/Xamarin.iOS/Facebook.YogaKit.iOS.Sample/ViewController.designer.cs diff --git a/csharp/Xamarin.iOS/Facebook.YogaKit.iOS.Sample/AppDelegate.cs b/csharp/Xamarin.iOS/Facebook.YogaKit.iOS.Sample/AppDelegate.cs new file mode 100644 index 00000000..b59ca105 --- /dev/null +++ b/csharp/Xamarin.iOS/Facebook.YogaKit.iOS.Sample/AppDelegate.cs @@ -0,0 +1,59 @@ +using Foundation; +using UIKit; + +namespace Facebook.YogaKit.iOS.Sample +{ + // The UIApplicationDelegate for the application. This class is responsible for launching the + // User Interface of the application, as well as listening (and optionally responding) to application events from iOS. + [Register("AppDelegate")] + public class AppDelegate : UIApplicationDelegate + { + // class-level declarations + + public override UIWindow Window + { + get; + set; + } + + public override bool FinishedLaunching(UIApplication application, NSDictionary launchOptions) + { + // Override point for customization after application launch. + // If not required for your application you can safely delete this method + + return true; + } + + public override void OnResignActivation(UIApplication application) + { + // Invoked when the application is about to move from active to inactive state. + // This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) + // or when the user quits the application and it begins the transition to the background state. + // Games should use this method to pause the game. + } + + public override void DidEnterBackground(UIApplication application) + { + // Use this method to release shared resources, save user data, invalidate timers and store the application state. + // If your application supports background exection this method is called instead of WillTerminate when the user quits. + } + + public override void WillEnterForeground(UIApplication application) + { + // Called as part of the transiton from background to active state. + // Here you can undo many of the changes made on entering the background. + } + + public override void OnActivated(UIApplication application) + { + // Restart any tasks that were paused (or not yet started) while the application was inactive. + // If the application was previously in the background, optionally refresh the user interface. + } + + public override void WillTerminate(UIApplication application) + { + // Called when the application is about to terminate. Save data, if needed. See also DidEnterBackground. + } + } +} + diff --git a/csharp/Xamarin.iOS/Facebook.YogaKit.iOS.Sample/Assets.xcassets/AppIcon.appiconset/Contents.json b/csharp/Xamarin.iOS/Facebook.YogaKit.iOS.Sample/Assets.xcassets/AppIcon.appiconset/Contents.json new file mode 100644 index 00000000..4e646784 --- /dev/null +++ b/csharp/Xamarin.iOS/Facebook.YogaKit.iOS.Sample/Assets.xcassets/AppIcon.appiconset/Contents.json @@ -0,0 +1,157 @@ +{ + "images": [ + { + "idiom": "iphone", + "size": "29x29", + "scale": "1x" + }, + { + "idiom": "iphone", + "size": "29x29", + "scale": "2x" + }, + { + "idiom": "iphone", + "size": "29x29", + "scale": "3x" + }, + { + "idiom": "iphone", + "size": "40x40", + "scale": "2x" + }, + { + "idiom": "iphone", + "size": "40x40", + "scale": "3x" + }, + { + "idiom": "iphone", + "size": "57x57", + "scale": "1x" + }, + { + "idiom": "iphone", + "size": "57x57", + "scale": "2x" + }, + { + "idiom": "iphone", + "size": "60x60", + "scale": "2x" + }, + { + "idiom": "iphone", + "size": "60x60", + "scale": "3x" + }, + { + "idiom": "ipad", + "size": "29x29", + "scale": "1x" + }, + { + "idiom": "ipad", + "size": "29x29", + "scale": "2x" + }, + { + "idiom": "ipad", + "size": "40x40", + "scale": "1x" + }, + { + "idiom": "ipad", + "size": "40x40", + "scale": "2x" + }, + { + "idiom": "ipad", + "size": "50x50", + "scale": "1x" + }, + { + "idiom": "ipad", + "size": "50x50", + "scale": "2x" + }, + { + "idiom": "ipad", + "size": "72x72", + "scale": "1x" + }, + { + "idiom": "ipad", + "size": "72x72", + "scale": "2x" + }, + { + "idiom": "ipad", + "size": "76x76", + "scale": "1x" + }, + { + "idiom": "ipad", + "size": "76x76", + "scale": "2x" + }, + { + "size": "24x24", + "idiom": "watch", + "scale": "2x", + "role": "notificationCenter", + "subtype": "38mm" + }, + { + "size": "27.5x27.5", + "idiom": "watch", + "scale": "2x", + "role": "notificationCenter", + "subtype": "42mm" + }, + { + "size": "29x29", + "idiom": "watch", + "role": "companionSettings", + "scale": "2x" + }, + { + "size": "29x29", + "idiom": "watch", + "role": "companionSettings", + "scale": "3x" + }, + { + "size": "40x40", + "idiom": "watch", + "scale": "2x", + "role": "appLauncher", + "subtype": "38mm" + }, + { + "size": "44x44", + "idiom": "watch", + "scale": "2x", + "role": "longLook", + "subtype": "42mm" + }, + { + "size": "86x86", + "idiom": "watch", + "scale": "2x", + "role": "quickLook", + "subtype": "38mm" + }, + { + "size": "98x98", + "idiom": "watch", + "scale": "2x", + "role": "quickLook", + "subtype": "42mm" + } + ], + "info": { + "version": 1, + "author": "xcode" + } +} \ No newline at end of file diff --git a/csharp/Xamarin.iOS/Facebook.YogaKit.iOS.Sample/Assets.xcassets/Contents.json b/csharp/Xamarin.iOS/Facebook.YogaKit.iOS.Sample/Assets.xcassets/Contents.json new file mode 100644 index 00000000..4caf392f --- /dev/null +++ b/csharp/Xamarin.iOS/Facebook.YogaKit.iOS.Sample/Assets.xcassets/Contents.json @@ -0,0 +1,6 @@ +{ + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/csharp/Xamarin.iOS/Facebook.YogaKit.iOS.Sample/Entitlements.plist b/csharp/Xamarin.iOS/Facebook.YogaKit.iOS.Sample/Entitlements.plist new file mode 100644 index 00000000..9ae59937 --- /dev/null +++ b/csharp/Xamarin.iOS/Facebook.YogaKit.iOS.Sample/Entitlements.plist @@ -0,0 +1,6 @@ + + + + + + diff --git a/csharp/Xamarin.iOS/Facebook.YogaKit.iOS.Sample/Facebook.YogaKit.iOS.Sample.csproj b/csharp/Xamarin.iOS/Facebook.YogaKit.iOS.Sample/Facebook.YogaKit.iOS.Sample.csproj new file mode 100644 index 00000000..d94eb930 --- /dev/null +++ b/csharp/Xamarin.iOS/Facebook.YogaKit.iOS.Sample/Facebook.YogaKit.iOS.Sample.csproj @@ -0,0 +1,128 @@ + + + + Debug + iPhoneSimulator + {6A094B74-FA9A-4E49-A8E1-F450A04E3E5B} + {FEACFBD2-3405-455C-9665-78FE426C6842};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + Exe + Facebook.YogaKit.iOS.Sample + Facebook.YogaKit.iOS.Sample + Resources + + + true + full + false + bin\iPhoneSimulator\Debug + DEBUG;ENABLE_TEST_CLOUD;__IOS__ + prompt + 4 + iPhone Developer + true + true + true + true + true + 56768 + None + x86_64 + HttpClientHandler + Default + false + + + pdbonly + true + bin\iPhone\Release + + prompt + 4 + iPhone Developer + true + true + true + Entitlements.plist + SdkOnly + ARMv7, ARM64 + HttpClientHandler + Default + + + + true + bin\iPhoneSimulator\Release + + prompt + 4 + iPhone Developer + true + true + None + x86_64 + HttpClientHandler + Default + + + true + full + false + bin\iPhone\Debug + DEBUG;ENABLE_TEST_CLOUD; + prompt + 4 + iPhone Developer + true + true + true + true + true + true + true + Entitlements.plist + SdkOnly + ARMv7, ARM64 + HttpClientHandler + Default + + + + + + + + + + + + + + + + + + + + + + + + + + + + ViewController.cs + + + + + {0C38AA9D-3178-4B43-9C3B-3C97A90FB1B0} + Facebook.YogaKit.iOS + + + {128FB32A-C4A1-4363-BF06-0A36E700B7FA} + Facebook.Yoga.iOS + + + + \ No newline at end of file diff --git a/csharp/Xamarin.iOS/Facebook.YogaKit.iOS.Sample/Info.plist b/csharp/Xamarin.iOS/Facebook.YogaKit.iOS.Sample/Info.plist new file mode 100644 index 00000000..0c6a791e --- /dev/null +++ b/csharp/Xamarin.iOS/Facebook.YogaKit.iOS.Sample/Info.plist @@ -0,0 +1,39 @@ + + + + + CFBundleName + Facebook.YogaKit.iOS.Sample + CFBundleIdentifier + com.xamarin.facebook-yogakit-ios-sample + CFBundleShortVersionString + 1.0 + CFBundleVersion + 1.0 + LSRequiresIPhoneOS + + MinimumOSVersion + 10.2 + UIDeviceFamily + + 1 + 2 + + UILaunchStoryboardName + LaunchScreen + UIMainStoryboardFile + Main + UIRequiredDeviceCapabilities + + armv7 + + UISupportedInterfaceOrientations + + UIInterfaceOrientationPortrait + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + XSAppIconAssets + Assets.xcassets/AppIcon.appiconset + + diff --git a/csharp/Xamarin.iOS/Facebook.YogaKit.iOS.Sample/LaunchScreen.storyboard b/csharp/Xamarin.iOS/Facebook.YogaKit.iOS.Sample/LaunchScreen.storyboard new file mode 100644 index 00000000..5d2e905a --- /dev/null +++ b/csharp/Xamarin.iOS/Facebook.YogaKit.iOS.Sample/LaunchScreen.storyboard @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/csharp/Xamarin.iOS/Facebook.YogaKit.iOS.Sample/Main.cs b/csharp/Xamarin.iOS/Facebook.YogaKit.iOS.Sample/Main.cs new file mode 100644 index 00000000..f87df673 --- /dev/null +++ b/csharp/Xamarin.iOS/Facebook.YogaKit.iOS.Sample/Main.cs @@ -0,0 +1,15 @@ +using UIKit; + +namespace Facebook.YogaKit.iOS.Sample +{ + public class Application + { + // This is the main entry point of the application. + static void Main(string[] args) + { + // if you want to use a different Application Delegate class from "AppDelegate" + // you can specify it here. + UIApplication.Main(args, null, "AppDelegate"); + } + } +} diff --git a/csharp/Xamarin.iOS/Facebook.YogaKit.iOS.Sample/Main.storyboard b/csharp/Xamarin.iOS/Facebook.YogaKit.iOS.Sample/Main.storyboard new file mode 100644 index 00000000..a43ad72c --- /dev/null +++ b/csharp/Xamarin.iOS/Facebook.YogaKit.iOS.Sample/Main.storyboard @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/csharp/Xamarin.iOS/Facebook.YogaKit.iOS.Sample/ViewController.cs b/csharp/Xamarin.iOS/Facebook.YogaKit.iOS.Sample/ViewController.cs new file mode 100644 index 00000000..072c8851 --- /dev/null +++ b/csharp/Xamarin.iOS/Facebook.YogaKit.iOS.Sample/ViewController.cs @@ -0,0 +1,60 @@ +using System; +using CoreGraphics; +using Facebook.Yoga; +using UIKit; + +namespace Facebook.YogaKit.iOS.Sample +{ + public partial class ViewController : UIViewController + { + protected ViewController(IntPtr handle) : base(handle) + { + // Note: this .ctor should not contain any initialization logic. + } + + public override void ViewDidLoad() + { + base.ViewDidLoad(); + CreateViewHierarchy(View, View.Bounds.Size.Width, View.Bounds.Size.Height); + } + + static void CreateViewHierarchy(UIView root, nfloat width, nfloat height) + { + root.BackgroundColor = UIColor.Red; + + root.UsesYoga(true); + root.YogaWidth(width); + root.YogaWidth(height); + root.YogaAlignItems(YogaAlign.Center); + root.YogaJustify(YogaJustify.Center); + + var child1 = new UIView { BackgroundColor = UIColor.Blue }; + child1.YogaWidth(100); + child1.YogaHeight(100); + child1.UsesYoga(true); + + var child2 = new UIView + { + BackgroundColor = UIColor.Green, + Frame = new CGRect { Size = new CGSize(200, 100) } + }; + + var child3 = new UIView + { + BackgroundColor = UIColor.Yellow, + Frame = new CGRect { Size = new CGSize(100, 100) } + }; + + child2.AddSubview(child3); + root.AddSubview(child1); + root.AddSubview(child2); + root.YogaApplyLayout(); + } + + public override void DidReceiveMemoryWarning() + { + base.DidReceiveMemoryWarning(); + // Release any cached data, images, etc that aren't in use. + } + } +} diff --git a/csharp/Xamarin.iOS/Facebook.YogaKit.iOS.Sample/ViewController.designer.cs b/csharp/Xamarin.iOS/Facebook.YogaKit.iOS.Sample/ViewController.designer.cs new file mode 100644 index 00000000..810950d0 --- /dev/null +++ b/csharp/Xamarin.iOS/Facebook.YogaKit.iOS.Sample/ViewController.designer.cs @@ -0,0 +1,17 @@ +// +// This file has been generated automatically by MonoDevelop to store outlets and +// actions made in the Xcode designer. If it is removed, they will be lost. +// Manual changes to this file may not be handled correctly. +// +using Foundation; + +namespace Facebook.YogaKit.iOS.Sample +{ + [Register("ViewController")] + partial class ViewController + { + void ReleaseDesignerOutlets() + { + } + } +}