Add basic Xamarin.iOS support #280
@@ -119,6 +119,10 @@
|
|||||||
<Project>{BE4CBFDA-02E2-4DF0-A81A-CEFB7987A708}</Project>
|
<Project>{BE4CBFDA-02E2-4DF0-A81A-CEFB7987A708}</Project>
|
||||||
<Name>Facebook.Yoga.iOS</Name>
|
<Name>Facebook.Yoga.iOS</Name>
|
||||||
</ProjectReference>
|
</ProjectReference>
|
||||||
|
<ProjectReference Include="..\Facebook.YogaKit.iOS\Facebook.YogaKit.iOS.csproj">
|
||||||
|
<Project>{33B1B6BE-F415-4819-A5FB-CFFE2E40AD6E}</Project>
|
||||||
|
<Name>Facebook.YogaKit.iOS</Name>
|
||||||
|
</ProjectReference>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<Import Project="$(MSBuildExtensionsPath)\Xamarin\iOS\Xamarin.iOS.CSharp.targets" />
|
<Import Project="$(MSBuildExtensionsPath)\Xamarin\iOS\Xamarin.iOS.CSharp.targets" />
|
||||||
</Project>
|
</Project>
|
@@ -1,5 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using CoreGraphics;
|
using CoreGraphics;
|
||||||
|
using Facebook.YogaKit.iOS;
|
||||||
using Foundation;
|
using Foundation;
|
||||||
using UIKit;
|
using UIKit;
|
||||||
|
|
||||||
@@ -30,66 +31,41 @@ namespace Facebook.Yoga.iOS.Test
|
|||||||
public override void ViewDidLoad()
|
public override void ViewDidLoad()
|
||||||
{
|
{
|
||||||
base.ViewDidLoad();
|
base.ViewDidLoad();
|
||||||
UIImage image = FromUrl("https://placehold.it/50x50");
|
|
||||||
|
|
||||||
UIView root = CreateViewHierarchy(image);
|
CreateViewHierarchy(View, View.Bounds.Size.Width, View.Bounds.Size.Height);
|
||||||
|
|
||||||
var rootNode = CalculateLayout(image.Size);
|
|
||||||
|
|
||||||
root.ApplyYogaLayout(rootNode);
|
|
||||||
|
|
||||||
View.AddSubview(root);
|
|
||||||
|
|
||||||
}
|
|
||||||
static UIImage FromUrl(string uri)
|
|
||||||
{
|
|
||||||
using (var url = new NSUrl(uri))
|
|
||||||
using (var data = NSData.FromUrl(url))
|
|
||||||
return UIImage.LoadFromData(data);
|
|
||||||
}
|
|
||||||
static UIView CreateViewHierarchy(UIImage image)
|
|
||||||
{
|
|
||||||
var root = new UIView();
|
|
||||||
UIImageView imageView = new UIImageView()
|
|
||||||
{
|
|
||||||
Image = image
|
|
||||||
};
|
|
||||||
root.AddSubview(imageView);
|
|
||||||
|
|
||||||
UITextField text = new UITextField()
|
|
||||||
{
|
|
||||||
Text = "Hello World",
|
|
||||||
};
|
|
||||||
root.AddSubview(text);
|
|
||||||
return root;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static YogaNode CalculateLayout(CGSize imageSize)
|
static void CreateViewHierarchy(UIView root, nfloat width, nfloat height)
|
||||||
{
|
{
|
||||||
var rootNode = new YogaNode()
|
root.BackgroundColor = UIColor.Red;
|
||||||
{
|
|
||||||
Width = 400,
|
|
||||||
Height = 120,
|
|
||||||
FlexDirection = YogaFlexDirection.Row
|
|
||||||
};
|
|
||||||
rootNode.SetPadding(YogaEdge.All, 20);
|
|
||||||
|
|
||||||
var imageNode = new YogaNode()
|
root.UsesYoga(true);
|
||||||
{
|
root.YogaWidth(width);
|
||||||
Width = (float)imageSize.Width,
|
root.YogaWidth(height);
|
||||||
};
|
root.YogaAlignItems(YogaAlign.Center);
|
||||||
imageNode.SetMargin(YogaEdge.End, 20);
|
root.YogaJustify(YogaJustify.Center);
|
||||||
|
|
||||||
var textNode = new YogaNode()
|
var child1 = new UIView { BackgroundColor = UIColor.Blue };
|
||||||
{
|
child1.YogaWidth(100);
|
||||||
AlignSelf = YogaAlign.Center,
|
child1.YogaHeight(100);
|
||||||
FlexGrow = 1,
|
child1.UsesYoga(true);
|
||||||
};
|
|
||||||
rootNode.Insert(0, imageNode);
|
|
||||||
rootNode.Insert(1, textNode);
|
|
||||||
rootNode.CalculateLayout();
|
|
||||||
|
|
||||||
return rootNode;
|
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()
|
public override void DidReceiveMemoryWarning()
|
||||||
|
Reference in New Issue
Block a user