From a3d7d72421d4b50688707bae342af41e1b46875b Mon Sep 17 00:00:00 2001 From: Rui Marinho Date: Wed, 11 Jan 2017 07:42:41 -0800 Subject: [PATCH] Xamarin iOS Support Summary: Since there's a couple of changes after last month pr of #280 , here's a new pr for Xamarin support #276 , the idea is to add Xamarin iOS, Mac and Android support. - Add Xamarin iOS support for Yoga, by providing a wrapper for the native lib. - Add Xamarin iOS Unit testing project ~~- Adds a YogaKit shared implementation in c#.~~ ~~- Adds a YogaKIt iOS implementation.~~ ~~- Adds Yoga/YogaKit iOS sample application~~ Facebook.Yoga.iOS.Tests.exe : 169 ms Tests run: 114 Passed: 114 Inconclusive: 0 Failed: 0 Ignored: 0 ![simulator screen shot 6 jan 2017 02 05 15](https://cloud.githubusercontent.com/assets/1235097/21705017/f851e9d8-d3b4-11e6-9c44-646dab559643.png) Closes https://github.com/facebook/yoga/pull/324 Reviewed By: emilsjolander Differential Revision: D4401408 Pulled By: splhack fbshipit-source-id: ecdae7967060361bef2bc25a5ef759cb9a957322 --- csharp/Facebook.Yoga/Native.cs | 4 - csharp/iOS/.gitignore | 2 + .../Entitlements.plist | 6 + .../Facebook.Yoga.iOS.Tests.csproj | 114 ++++++++++++++++++ csharp/iOS/Facebook.Yoga.iOS.Tests/Info.plist | 36 ++++++ .../LaunchScreen.storyboard | 27 +++++ csharp/iOS/Facebook.Yoga.iOS.Tests/Main.cs | 28 +++++ .../UnitTestAppDelegate.cs | 53 ++++++++ csharp/iOS/Facebook.Yoga.iOS.sln | 81 +++++++++++++ csharp/iOS/Facebook.Yoga.iOS/ApiDefinition.cs | 20 +++ .../CustomBuildAction.targets | 10 ++ .../Facebook.Yoga.iOS.csproj | 50 ++++++++ .../Facebook.Yoga.Shared.Tests.projitems | 4 +- 13 files changed, 429 insertions(+), 6 deletions(-) create mode 100644 csharp/iOS/.gitignore create mode 100644 csharp/iOS/Facebook.Yoga.iOS.Tests/Entitlements.plist create mode 100644 csharp/iOS/Facebook.Yoga.iOS.Tests/Facebook.Yoga.iOS.Tests.csproj create mode 100644 csharp/iOS/Facebook.Yoga.iOS.Tests/Info.plist create mode 100644 csharp/iOS/Facebook.Yoga.iOS.Tests/LaunchScreen.storyboard create mode 100644 csharp/iOS/Facebook.Yoga.iOS.Tests/Main.cs create mode 100644 csharp/iOS/Facebook.Yoga.iOS.Tests/UnitTestAppDelegate.cs create mode 100644 csharp/iOS/Facebook.Yoga.iOS.sln create mode 100644 csharp/iOS/Facebook.Yoga.iOS/ApiDefinition.cs create mode 100644 csharp/iOS/Facebook.Yoga.iOS/CustomBuildAction.targets create mode 100644 csharp/iOS/Facebook.Yoga.iOS/Facebook.Yoga.iOS.csproj diff --git a/csharp/Facebook.Yoga/Native.cs b/csharp/Facebook.Yoga/Native.cs index 248fc17f..9a233a3c 100644 --- a/csharp/Facebook.Yoga/Native.cs +++ b/csharp/Facebook.Yoga/Native.cs @@ -89,10 +89,6 @@ namespace Facebook.Yoga [DllImport(DllName, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)] public static extern void YGNodePrint(YGNodeHandle node, YogaPrintOptions options); - [DllImport(DllName, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)] - [return: MarshalAs(UnmanagedType.I1)] - public static extern bool YGValueIsUndefined(float value); - [DllImport(DllName, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)] public static extern void YGNodeCopyStyle(YGNodeHandle dstNode, YGNodeHandle srcNode); diff --git a/csharp/iOS/.gitignore b/csharp/iOS/.gitignore new file mode 100644 index 00000000..a5b96ed6 --- /dev/null +++ b/csharp/iOS/.gitignore @@ -0,0 +1,2 @@ +libyoga.a +*.userprefs diff --git a/csharp/iOS/Facebook.Yoga.iOS.Tests/Entitlements.plist b/csharp/iOS/Facebook.Yoga.iOS.Tests/Entitlements.plist new file mode 100644 index 00000000..9ae59937 --- /dev/null +++ b/csharp/iOS/Facebook.Yoga.iOS.Tests/Entitlements.plist @@ -0,0 +1,6 @@ + + + + + + diff --git a/csharp/iOS/Facebook.Yoga.iOS.Tests/Facebook.Yoga.iOS.Tests.csproj b/csharp/iOS/Facebook.Yoga.iOS.Tests/Facebook.Yoga.iOS.Tests.csproj new file mode 100644 index 00000000..697a7be8 --- /dev/null +++ b/csharp/iOS/Facebook.Yoga.iOS.Tests/Facebook.Yoga.iOS.Tests.csproj @@ -0,0 +1,114 @@ + + + + Debug + iPhoneSimulator + {FCF0BE59-AE56-4D4F-8524-94532B2DFC71} + {FEACFBD2-3405-455C-9665-78FE426C6842};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + Exe + Facebook.Yoga.iOS.Tests + Facebook.Yoga.iOS.Tests + Resources + + + true + full + false + bin\iPhoneSimulator\Debug + DEBUG; + prompt + 4 + iPhone Developer + true + true + true + true + true + 28871 + 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 + + + pdbonly + true + bin\iPhoneSimulator\Release + + prompt + 4 + iPhone Developer + true + true + None + x86_64 + HttpClientHandler + Default + + + true + full + false + bin\iPhone\Debug + DEBUG; + prompt + 4 + iPhone Developer + true + true + true + true + true + true + true + Entitlements.plist + SdkOnly + ARMv7, ARM64 + HttpClientHandler + Default + + + + + + + + + + + + + + + + + + + + + + {128FB32A-C4A1-4363-BF06-0A36E700B7FA} + Facebook.Yoga.iOS + + + + + \ No newline at end of file diff --git a/csharp/iOS/Facebook.Yoga.iOS.Tests/Info.plist b/csharp/iOS/Facebook.Yoga.iOS.Tests/Info.plist new file mode 100644 index 00000000..18ec8367 --- /dev/null +++ b/csharp/iOS/Facebook.Yoga.iOS.Tests/Info.plist @@ -0,0 +1,36 @@ + + + + + CFBundleName + Facebook.Yoga.iOS.Tests + CFBundleIdentifier + com.xamarin.facebook-yoga-ios-tests + CFBundleShortVersionString + 1.0 + CFBundleVersion + 1.0 + LSRequiresIPhoneOS + + MinimumOSVersion + 9.0 + UIDeviceFamily + + 1 + 2 + + UISupportedInterfaceOrientations + + UIInterfaceOrientationPortrait + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + UILaunchStoryboardName + LaunchScreen + NSAppTransportSecurity + + NSAllowsArbitraryLoads + + + + diff --git a/csharp/iOS/Facebook.Yoga.iOS.Tests/LaunchScreen.storyboard b/csharp/iOS/Facebook.Yoga.iOS.Tests/LaunchScreen.storyboard new file mode 100644 index 00000000..5d2e905a --- /dev/null +++ b/csharp/iOS/Facebook.Yoga.iOS.Tests/LaunchScreen.storyboard @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/csharp/iOS/Facebook.Yoga.iOS.Tests/Main.cs b/csharp/iOS/Facebook.Yoga.iOS.Tests/Main.cs new file mode 100644 index 00000000..4dfd9416 --- /dev/null +++ b/csharp/iOS/Facebook.Yoga.iOS.Tests/Main.cs @@ -0,0 +1,28 @@ +/** + * Copyright 2014-present, Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the license found in the + * LICENSE-examples file in the root directory of this source tree. + */ + +using System; +using System.Linq; +using System.Collections.Generic; + +using Foundation; +using UIKit; + +namespace Facebook.Yoga.iOS.Tests +{ + 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 "UnitTestAppDelegate" + // you can specify it here. + UIApplication.Main(args, null, "UnitTestAppDelegate"); + } + } +} diff --git a/csharp/iOS/Facebook.Yoga.iOS.Tests/UnitTestAppDelegate.cs b/csharp/iOS/Facebook.Yoga.iOS.Tests/UnitTestAppDelegate.cs new file mode 100644 index 00000000..683901cf --- /dev/null +++ b/csharp/iOS/Facebook.Yoga.iOS.Tests/UnitTestAppDelegate.cs @@ -0,0 +1,53 @@ +/** + * Copyright 2014-present, Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the license found in the + * LICENSE-examples file in the root directory of this source tree. + */ + +using System; +using System.Linq; +using System.Collections.Generic; + +using Foundation; +using UIKit; +using MonoTouch.NUnit.UI; + +namespace Facebook.Yoga.iOS.Tests +{ + // 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("UnitTestAppDelegate")] + public partial class UnitTestAppDelegate : UIApplicationDelegate + { + // class-level declarations + UIWindow window; + TouchRunner runner; + + // + // This method is invoked when the application has loaded and is ready to run. In this + // method you should instantiate the window, load the UI into it and then make the window + // visible. + // + // You have 17 seconds to return from this method, or iOS will terminate your application. + // + public override bool FinishedLaunching(UIApplication app, NSDictionary options) + { + // create a new window instance based on the screen size + window = new UIWindow(UIScreen.MainScreen.Bounds); + runner = new TouchRunner(window); + + // register every tests included in the main application/assembly + runner.Add(System.Reflection.Assembly.GetExecutingAssembly()); + + window.RootViewController = new UINavigationController(runner.GetViewController()); + + // make the window visible + window.MakeKeyAndVisible(); + + return true; + } + } +} diff --git a/csharp/iOS/Facebook.Yoga.iOS.sln b/csharp/iOS/Facebook.Yoga.iOS.sln new file mode 100644 index 00000000..a58ae0b4 --- /dev/null +++ b/csharp/iOS/Facebook.Yoga.iOS.sln @@ -0,0 +1,81 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 2012 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Facebook.Yoga.iOS", "Facebook.Yoga.iOS\Facebook.Yoga.iOS.csproj", "{128FB32A-C4A1-4363-BF06-0A36E700B7FA}" +EndProject +Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "Facebook.Yoga.Shared", "..\Facebook.Yoga\Facebook.Yoga.Shared.shproj", "{91C42D32-291D-4B72-90B4-551663D60B8B}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Shared", "Shared", "{89A39C6B-6A7B-4458-872B-A0456550CAA6}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Facebook.Yoga.iOS.Tests", "Facebook.Yoga.iOS.Tests\Facebook.Yoga.iOS.Tests.csproj", "{FCF0BE59-AE56-4D4F-8524-94532B2DFC71}" +EndProject +Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "Facebook.Yoga.Shared.Tests", "..\tests\Facebook.Yoga\Facebook.Yoga.Shared.Tests.shproj", "{4EDC82D9-A201-4831-8FE0-98F468F8E4AE}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + Debug|iPhoneSimulator = Debug|iPhoneSimulator + Release|iPhone = Release|iPhone + Release|iPhoneSimulator = Release|iPhoneSimulator + Debug|iPhone = Debug|iPhone + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {128FB32A-C4A1-4363-BF06-0A36E700B7FA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {128FB32A-C4A1-4363-BF06-0A36E700B7FA}.Debug|Any CPU.Build.0 = Debug|Any CPU + {128FB32A-C4A1-4363-BF06-0A36E700B7FA}.Release|Any CPU.ActiveCfg = Release|Any CPU + {128FB32A-C4A1-4363-BF06-0A36E700B7FA}.Release|Any CPU.Build.0 = Release|Any CPU + {128FB32A-C4A1-4363-BF06-0A36E700B7FA}.Debug|iPhoneSimulator.ActiveCfg = Debug|Any CPU + {128FB32A-C4A1-4363-BF06-0A36E700B7FA}.Debug|iPhoneSimulator.Build.0 = Debug|Any CPU + {128FB32A-C4A1-4363-BF06-0A36E700B7FA}.Release|iPhone.ActiveCfg = Release|Any CPU + {128FB32A-C4A1-4363-BF06-0A36E700B7FA}.Release|iPhone.Build.0 = Release|Any CPU + {128FB32A-C4A1-4363-BF06-0A36E700B7FA}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU + {128FB32A-C4A1-4363-BF06-0A36E700B7FA}.Release|iPhoneSimulator.Build.0 = Release|Any CPU + {128FB32A-C4A1-4363-BF06-0A36E700B7FA}.Debug|iPhone.ActiveCfg = Debug|Any CPU + {128FB32A-C4A1-4363-BF06-0A36E700B7FA}.Debug|iPhone.Build.0 = Debug|Any CPU + {FCF0BE59-AE56-4D4F-8524-94532B2DFC71}.Debug|Any CPU.ActiveCfg = Debug|iPhoneSimulator + {FCF0BE59-AE56-4D4F-8524-94532B2DFC71}.Debug|Any CPU.Build.0 = Debug|iPhoneSimulator + {FCF0BE59-AE56-4D4F-8524-94532B2DFC71}.Release|Any CPU.ActiveCfg = Release|iPhone + {FCF0BE59-AE56-4D4F-8524-94532B2DFC71}.Release|Any CPU.Build.0 = Release|iPhone + {FCF0BE59-AE56-4D4F-8524-94532B2DFC71}.Debug|iPhoneSimulator.ActiveCfg = Debug|iPhoneSimulator + {FCF0BE59-AE56-4D4F-8524-94532B2DFC71}.Debug|iPhoneSimulator.Build.0 = Debug|iPhoneSimulator + {FCF0BE59-AE56-4D4F-8524-94532B2DFC71}.Release|iPhone.ActiveCfg = Release|iPhone + {FCF0BE59-AE56-4D4F-8524-94532B2DFC71}.Release|iPhone.Build.0 = Release|iPhone + {FCF0BE59-AE56-4D4F-8524-94532B2DFC71}.Release|iPhoneSimulator.ActiveCfg = Release|iPhoneSimulator + {FCF0BE59-AE56-4D4F-8524-94532B2DFC71}.Release|iPhoneSimulator.Build.0 = Release|iPhoneSimulator + {FCF0BE59-AE56-4D4F-8524-94532B2DFC71}.Debug|iPhone.ActiveCfg = Debug|iPhone + {FCF0BE59-AE56-4D4F-8524-94532B2DFC71}.Debug|iPhone.Build.0 = Debug|iPhone + EndGlobalSection + GlobalSection(NestedProjects) = preSolution + {91C42D32-291D-4B72-90B4-551663D60B8B} = {89A39C6B-6A7B-4458-872B-A0456550CAA6} + {4EDC82D9-A201-4831-8FE0-98F468F8E4AE} = {89A39C6B-6A7B-4458-872B-A0456550CAA6} + EndGlobalSection + GlobalSection(MonoDevelopProperties) = preSolution + Policies = $0 + $0.TextStylePolicy = $1 + $1.inheritsSet = VisualStudio + $1.inheritsScope = text/plain + $1.scope = text/x-csharp + $0.CSharpFormattingPolicy = $2 + $2.IndentSwitchSection = True + $2.NewLinesForBracesInProperties = True + $2.NewLinesForBracesInAccessors = True + $2.NewLinesForBracesInAnonymousMethods = True + $2.NewLinesForBracesInControlBlocks = True + $2.NewLinesForBracesInAnonymousTypes = True + $2.NewLinesForBracesInObjectCollectionArrayInitializers = True + $2.NewLinesForBracesInLambdaExpressionBody = True + $2.NewLineForElse = True + $2.NewLineForCatch = True + $2.NewLineForFinally = True + $2.NewLineForMembersInObjectInit = True + $2.NewLineForMembersInAnonymousTypes = True + $2.NewLineForClausesInQuery = True + $2.SpacingAfterMethodDeclarationName = False + $2.SpaceAfterMethodCallName = False + $2.SpaceBeforeOpenSquareBracket = False + $2.inheritsSet = Mono + $2.inheritsScope = text/x-csharp + $2.scope = text/x-csharp + EndGlobalSection +EndGlobal diff --git a/csharp/iOS/Facebook.Yoga.iOS/ApiDefinition.cs b/csharp/iOS/Facebook.Yoga.iOS/ApiDefinition.cs new file mode 100644 index 00000000..9a160ca2 --- /dev/null +++ b/csharp/iOS/Facebook.Yoga.iOS/ApiDefinition.cs @@ -0,0 +1,20 @@ +/** + * Copyright (c) 2014-present, Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + */ + +using System; + +using UIKit; +using Foundation; +using ObjCRuntime; +using CoreGraphics; + +namespace Facebook.Yoga.iOS +{ + //this is needed +} diff --git a/csharp/iOS/Facebook.Yoga.iOS/CustomBuildAction.targets b/csharp/iOS/Facebook.Yoga.iOS/CustomBuildAction.targets new file mode 100644 index 00000000..2d5538bd --- /dev/null +++ b/csharp/iOS/Facebook.Yoga.iOS/CustomBuildAction.targets @@ -0,0 +1,10 @@ + + + + CopyInNativeLib;$(CompileDependsOn) + + + + + + diff --git a/csharp/iOS/Facebook.Yoga.iOS/Facebook.Yoga.iOS.csproj b/csharp/iOS/Facebook.Yoga.iOS/Facebook.Yoga.iOS.csproj new file mode 100644 index 00000000..479efbff --- /dev/null +++ b/csharp/iOS/Facebook.Yoga.iOS/Facebook.Yoga.iOS.csproj @@ -0,0 +1,50 @@ + + + + Debug + AnyCPU + {128FB32A-C4A1-4363-BF06-0A36E700B7FA} + {8FFB629D-F513-41CE-95D2-7ECE97B6EEEC};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + Library + Facebook.Yoga.iOS + Facebook.Yoga.iOS + Resources + + + true + full + false + bin\Debug + DEBUG; + prompt + 4 + true + + + true + bin\Release + prompt + 4 + true + + + + + + + + + + + + + + + Static + False + + + + + + diff --git a/csharp/tests/Facebook.Yoga/Facebook.Yoga.Shared.Tests.projitems b/csharp/tests/Facebook.Yoga/Facebook.Yoga.Shared.Tests.projitems index e593c942..0afe5e63 100644 --- a/csharp/tests/Facebook.Yoga/Facebook.Yoga.Shared.Tests.projitems +++ b/csharp/tests/Facebook.Yoga/Facebook.Yoga.Shared.Tests.projitems @@ -22,7 +22,7 @@ - + - \ No newline at end of file +