Add YogaKit Shared and iOS version
Summary: Using shared code for reuse in other platforms based on iOS native implementation. Adds YogaKit sample. Adds YogaKit tests (same as objc). ``` YogaKitTest : 80 ms Facebook.YogaKit.iOS.Tests.exe : 81 ms Tests run: 11 Passed: 8 Inconclusive: 0 Failed: 3 Ignored: 1 ``` Since we don't have extension properties we need to go with a extension method to get access to the YogaLayout . I m also not sure this is leak free yet, would love some help with testing and feedback about view/node lifecycle Closes https://github.com/facebook/yoga/pull/336 Reviewed By: splhack Differential Revision: D4415027 Pulled By: emilsjolander fbshipit-source-id: c88328212426c3200e6f0c48cda594cd2c432065
This commit is contained in:
committed by
Facebook Github Bot
parent
8021c5d968
commit
498a5980e8
11
csharp/Facebook.YogaKit/Facebook.YogaKit.Shared.shproj
Normal file
11
csharp/Facebook.YogaKit/Facebook.YogaKit.Shared.shproj
Normal file
@@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<ProjectGuid>{A24B3BA6-3143-4FFF-B8B8-1EDF166F5F4A}</ProjectGuid>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.Common.Default.props" />
|
||||
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.Common.props" />
|
||||
<Import Project="Facebook.YogaKit.projitems" Label="Shared" />
|
||||
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.CSharp.targets" />
|
||||
</Project>
|
16
csharp/Facebook.YogaKit/Facebook.YogaKit.projitems
Normal file
16
csharp/Facebook.YogaKit/Facebook.YogaKit.projitems
Normal file
@@ -0,0 +1,16 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<MSBuildAllProjects>$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
|
||||
<HasSharedItems>true</HasSharedItems>
|
||||
<SharedGUID>{A24B3BA6-3143-4FFF-B8B8-1EDF166F5F4A}</SharedGUID>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Label="Configuration">
|
||||
<Import_RootNamespace>Facebook.YogaKit</Import_RootNamespace>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="$(MSBuildThisFileDirectory)YogaLayout.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)IYogaLayout.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)YogaKit.cs" />
|
||||
</ItemGroup>
|
||||
</Project>
|
85
csharp/Facebook.YogaKit/IYogaLayout.cs
Normal file
85
csharp/Facebook.YogaKit/IYogaLayout.cs
Normal file
@@ -0,0 +1,85 @@
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using Facebook.Yoga;
|
||||
|
||||
namespace Facebook.YogaKit
|
||||
{
|
||||
public interface IYogaLayout : IDisposable
|
||||
{
|
||||
bool IsEnabled { get; set; }
|
||||
bool IsIncludeInLayout { get; set; }
|
||||
|
||||
//YogaDirection Direction { get; set; }
|
||||
YogaFlexDirection FlexDirection { get; set; }
|
||||
YogaJustify JustifyContent { get; set; }
|
||||
YogaAlign AlignContent { get; set; }
|
||||
YogaAlign AlignSelf { get; set; }
|
||||
YogaAlign AlignItems { get; set; }
|
||||
YogaPositionType Position { get; set; }
|
||||
YogaWrap FlexWrap { get; set; }
|
||||
YogaOverflow Overflow { get; set; }
|
||||
|
||||
|
||||
float FlexGrow { get; set; }
|
||||
float FlexShrink { get; set; }
|
||||
float FlexBasis { get; set; }
|
||||
|
||||
float Left { get; set; }
|
||||
float Top { get; set; }
|
||||
float Right { get; set; }
|
||||
float Bottom { get; set; }
|
||||
float Start { get; set; }
|
||||
float End { get; set; }
|
||||
|
||||
float MarginLeft { get; set; }
|
||||
float MarginTop { get; set; }
|
||||
float MarginRight { get; set; }
|
||||
float MarginBottom { get; set; }
|
||||
float MarginStart { get; set; }
|
||||
float MarginEnd { get; set; }
|
||||
float MarginHorizontal { get; set; }
|
||||
float MarginVertical { get; set; }
|
||||
float Margin { get; set; }
|
||||
|
||||
float PaddingLeft { get; set; }
|
||||
float PaddingTop { get; set; }
|
||||
float PaddingRight { get; set; }
|
||||
float PaddingBottom { get; set; }
|
||||
float PaddingStart { get; set; }
|
||||
float PaddingEnd { get; set; }
|
||||
float PaddingHorizontal { get; set; }
|
||||
float PaddingVertical { get; set; }
|
||||
float Padding { get; set; }
|
||||
|
||||
float BorderLeftWidth { get; set; }
|
||||
float BorderTopWidth { get; set; }
|
||||
float BorderRightWidth { get; set; }
|
||||
float BorderBottomWidth { get; set; }
|
||||
float BorderStartWidth { get; set; }
|
||||
float BorderEndWidth { get; set; }
|
||||
float BorderWidth { get; set; }
|
||||
|
||||
float Width { get; set; }
|
||||
float Height { get; set; }
|
||||
float MinWidth { get; set; }
|
||||
float MinHeight { get; set; }
|
||||
float MaxWidth { get; set; }
|
||||
float MaxHeight { get; set; }
|
||||
|
||||
// Yoga specific properties, not compatible with flexbox specification
|
||||
|
||||
// Returns the size of the view if no constraints were given. This could equivalent to calling [self sizeThatFits:CGSizeMake(CGFLOAT_MAX, CGFLOAT_MAX)];
|
||||
SizeF IntrinsicSize { get; }
|
||||
float AspectRatio { get; set; }
|
||||
// Get the resolved direction of this node. This won't be YGDirectionInherit
|
||||
YogaDirection ResolvedDirection { get; }
|
||||
// Returns the number of children that are using Flexbox.
|
||||
int NumberOfChildren { get; }
|
||||
// Return a BOOL indiciating whether or not we this node contains any subviews that are included in Yoga's layout.
|
||||
bool IsLeaf { get; }
|
||||
// Perform a layout calculation and update the frames of the views in the hierarchy with the results
|
||||
void ApplyLayout();
|
||||
// Mark that a view's layout needs to be recalculated. Only works for leaf views.
|
||||
void MarkDirty();
|
||||
}
|
||||
}
|
10
csharp/Facebook.YogaKit/YogaKit.cs
Normal file
10
csharp/Facebook.YogaKit/YogaKit.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
using System.Collections.Generic;
|
||||
using Facebook.Yoga;
|
||||
|
||||
namespace Facebook.YogaKit
|
||||
{
|
||||
public static partial class YogaKit
|
||||
{
|
||||
internal static Dictionary<YogaNode, object> Bridges = new Dictionary<YogaNode, object>();
|
||||
}
|
||||
}
|
888
csharp/Facebook.YogaKit/YogaLayout.cs
Normal file
888
csharp/Facebook.YogaKit/YogaLayout.cs
Normal file
@@ -0,0 +1,888 @@
|
||||
using System;
|
||||
using Facebook.Yoga;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
#if __IOS__
|
||||
using NativeView = UIKit.UIView;
|
||||
#endif
|
||||
|
||||
namespace Facebook.YogaKit
|
||||
{
|
||||
public partial class YogaLayout : IYogaLayout
|
||||
{
|
||||
WeakReference<NativeView> _viewRef;
|
||||
YogaNode _node;
|
||||
|
||||
internal YogaLayout(NativeView view)
|
||||
{
|
||||
_viewRef = new WeakReference<NativeView>(view);
|
||||
_node = new YogaNode();
|
||||
YogaKit.Bridges.Add(_node, view);
|
||||
|
||||
IsEnabled = false;
|
||||
IsIncludeInLayout = true;
|
||||
}
|
||||
|
||||
public new void MarkDirty()
|
||||
{
|
||||
if (IsLeaf)
|
||||
_node.MarkDirty();
|
||||
}
|
||||
|
||||
public bool IsLeaf
|
||||
{
|
||||
get
|
||||
{
|
||||
if (IsEnabled)
|
||||
{
|
||||
NativeView view = null;
|
||||
if (_viewRef.TryGetTarget(out view))
|
||||
{
|
||||
foreach (NativeView subview in GetChildren(view))
|
||||
{
|
||||
var layout = subview.Yoga();
|
||||
if (layout.IsEnabled && layout.IsIncludeInLayout)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public bool IsEnabled
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
public bool IsIncludeInLayout
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
public int NumberOfChildren => _node.Count;
|
||||
|
||||
public YogaDirection ResolvedDirection => _node.LayoutDirection;
|
||||
|
||||
public YogaFlexDirection FlexDirection
|
||||
{
|
||||
get
|
||||
{
|
||||
return _node.FlexDirection;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
_node.FlexDirection = value;
|
||||
}
|
||||
}
|
||||
|
||||
public YogaAlign AlignItems
|
||||
{
|
||||
get
|
||||
{
|
||||
return _node.AlignItems;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
_node.AlignItems = value;
|
||||
}
|
||||
}
|
||||
|
||||
public YogaJustify JustifyContent
|
||||
{
|
||||
get
|
||||
{
|
||||
return _node.JustifyContent;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
_node.JustifyContent = value;
|
||||
}
|
||||
}
|
||||
|
||||
public YogaAlign AlignContent
|
||||
{
|
||||
get
|
||||
{
|
||||
return _node.AlignContent;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
_node.AlignContent = value;
|
||||
}
|
||||
}
|
||||
|
||||
public YogaAlign AlignSelf
|
||||
{
|
||||
get
|
||||
{
|
||||
return _node.AlignSelf;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
_node.AlignSelf = value;
|
||||
}
|
||||
}
|
||||
|
||||
public YogaPositionType Position
|
||||
{
|
||||
get
|
||||
{
|
||||
return _node.PositionType;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
_node.PositionType = value;
|
||||
}
|
||||
}
|
||||
|
||||
public YogaWrap FlexWrap
|
||||
{
|
||||
get
|
||||
{
|
||||
return _node.Wrap;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
_node.Wrap = value;
|
||||
}
|
||||
}
|
||||
|
||||
public YogaOverflow Overflow
|
||||
{
|
||||
get
|
||||
{
|
||||
return _node.Overflow;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
_node.Overflow = value;
|
||||
}
|
||||
}
|
||||
|
||||
public float FlexGrow
|
||||
{
|
||||
get
|
||||
{
|
||||
return _node.FlexGrow;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
_node.FlexGrow = value;
|
||||
}
|
||||
}
|
||||
|
||||
public float FlexShrink
|
||||
{
|
||||
get
|
||||
{
|
||||
return _node.FlexShrink;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
_node.FlexShrink = value;
|
||||
}
|
||||
}
|
||||
|
||||
public float FlexBasis
|
||||
{
|
||||
get
|
||||
{
|
||||
return (float)_node.FlexBasis.Value;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
_node.FlexBasis = value;
|
||||
}
|
||||
}
|
||||
|
||||
public float Left
|
||||
{
|
||||
get
|
||||
{
|
||||
return _node.Left.Value;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
_node.Left = value;
|
||||
}
|
||||
}
|
||||
|
||||
public float Top
|
||||
{
|
||||
get
|
||||
{
|
||||
return _node.Top.Value;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
_node.Top = value;
|
||||
}
|
||||
}
|
||||
|
||||
public float Right
|
||||
{
|
||||
get
|
||||
{
|
||||
return _node.Right.Value;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
_node.Right = value;
|
||||
}
|
||||
}
|
||||
|
||||
public float Bottom
|
||||
{
|
||||
get
|
||||
{
|
||||
return _node.Bottom.Value;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
_node.Bottom = value;
|
||||
}
|
||||
}
|
||||
|
||||
public float Start
|
||||
{
|
||||
get
|
||||
{
|
||||
return _node.Start.Value;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
_node.Start = value;
|
||||
}
|
||||
}
|
||||
|
||||
public float End
|
||||
{
|
||||
get
|
||||
{
|
||||
return _node.End.Value;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
_node.End = value;
|
||||
}
|
||||
}
|
||||
|
||||
public float MarginLeft
|
||||
{
|
||||
get
|
||||
{
|
||||
return _node.MarginLeft.Value;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
_node.MarginLeft = value;
|
||||
}
|
||||
}
|
||||
|
||||
public float MarginTop
|
||||
{
|
||||
get
|
||||
{
|
||||
return _node.MarginTop.Value;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
_node.MarginTop = value;
|
||||
}
|
||||
}
|
||||
|
||||
public float MarginRight
|
||||
{
|
||||
get
|
||||
{
|
||||
return _node.MarginRight.Value;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
_node.MarginRight = value;
|
||||
}
|
||||
}
|
||||
|
||||
public float MarginBottom
|
||||
{
|
||||
get
|
||||
{
|
||||
return _node.MarginBottom.Value;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
_node.MarginBottom = value;
|
||||
}
|
||||
}
|
||||
|
||||
public float MarginStart
|
||||
{
|
||||
get
|
||||
{
|
||||
return _node.MarginStart.Value;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
_node.MarginStart = value;
|
||||
}
|
||||
}
|
||||
|
||||
public float MarginEnd
|
||||
{
|
||||
get
|
||||
{
|
||||
return _node.MarginEnd.Value;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
_node.MarginEnd = value;
|
||||
}
|
||||
}
|
||||
|
||||
public float MarginHorizontal
|
||||
{
|
||||
get
|
||||
{
|
||||
return _node.MarginHorizontal.Value;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
_node.MarginHorizontal = value;
|
||||
}
|
||||
}
|
||||
|
||||
public float MarginVertical
|
||||
{
|
||||
get
|
||||
{
|
||||
return _node.MarginVertical.Value;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
_node.MarginVertical = value;
|
||||
}
|
||||
}
|
||||
|
||||
public float Margin
|
||||
{
|
||||
get
|
||||
{
|
||||
return _node.Margin.Value;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
_node.Margin = value;
|
||||
}
|
||||
}
|
||||
|
||||
public float PaddingLeft
|
||||
{
|
||||
get
|
||||
{
|
||||
return _node.PaddingLeft.Value;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
_node.PaddingLeft = value;
|
||||
}
|
||||
}
|
||||
|
||||
public float PaddingTop
|
||||
{
|
||||
get
|
||||
{
|
||||
return _node.PaddingTop.Value;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
_node.PaddingTop = value;
|
||||
}
|
||||
}
|
||||
|
||||
public float PaddingRight
|
||||
{
|
||||
get
|
||||
{
|
||||
return _node.PaddingRight.Value;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
_node.PaddingRight = value;
|
||||
}
|
||||
}
|
||||
|
||||
public float PaddingBottom
|
||||
{
|
||||
get
|
||||
{
|
||||
return _node.PaddingBottom.Value;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
_node.PaddingBottom = value;
|
||||
}
|
||||
}
|
||||
|
||||
public float PaddingStart
|
||||
{
|
||||
get
|
||||
{
|
||||
return _node.PaddingStart.Value;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
_node.PaddingStart = value;
|
||||
}
|
||||
}
|
||||
|
||||
public float PaddingEnd
|
||||
{
|
||||
get
|
||||
{
|
||||
return _node.PaddingEnd.Value;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
_node.PaddingEnd = value;
|
||||
}
|
||||
}
|
||||
|
||||
public float PaddingHorizontal
|
||||
{
|
||||
get
|
||||
{
|
||||
return _node.PaddingHorizontal.Value;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
_node.PaddingHorizontal = value;
|
||||
}
|
||||
}
|
||||
|
||||
public float PaddingVertical
|
||||
{
|
||||
get
|
||||
{
|
||||
return _node.PaddingVertical.Value;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
_node.PaddingHorizontal = value;
|
||||
}
|
||||
}
|
||||
|
||||
public float Padding
|
||||
{
|
||||
get
|
||||
{
|
||||
return _node.Padding.Value;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
_node.Padding = value;
|
||||
}
|
||||
}
|
||||
|
||||
public float BorderLeftWidth
|
||||
{
|
||||
get
|
||||
{
|
||||
return _node.BorderLeftWidth;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
_node.BorderLeftWidth = value;
|
||||
}
|
||||
}
|
||||
|
||||
public float BorderTopWidth
|
||||
{
|
||||
get
|
||||
{
|
||||
return _node.BorderTopWidth;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
_node.BorderTopWidth = value;
|
||||
}
|
||||
}
|
||||
|
||||
public float BorderRightWidth
|
||||
{
|
||||
get
|
||||
{
|
||||
return _node.BorderRightWidth;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
_node.BorderRightWidth = value;
|
||||
}
|
||||
}
|
||||
|
||||
public float BorderBottomWidth
|
||||
{
|
||||
get
|
||||
{
|
||||
return _node.BorderBottomWidth;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
_node.BorderBottomWidth = value;
|
||||
}
|
||||
}
|
||||
|
||||
public float BorderStartWidth
|
||||
{
|
||||
get
|
||||
{
|
||||
return _node.BorderStartWidth;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
_node.BorderStartWidth = value;
|
||||
}
|
||||
}
|
||||
|
||||
public float BorderEndWidth
|
||||
{
|
||||
get
|
||||
{
|
||||
return _node.BorderEndWidth;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
_node.BorderEndWidth = value;
|
||||
}
|
||||
}
|
||||
|
||||
public float BorderWidth
|
||||
{
|
||||
get
|
||||
{
|
||||
return _node.BorderWidth;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
_node.BorderWidth = value;
|
||||
}
|
||||
}
|
||||
|
||||
public float Height
|
||||
{
|
||||
get
|
||||
{
|
||||
return _node.Height.Value;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
_node.Height = value;
|
||||
}
|
||||
}
|
||||
|
||||
public float Width
|
||||
{
|
||||
get
|
||||
{
|
||||
return _node.Width.Value;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
_node.Width = value;
|
||||
}
|
||||
}
|
||||
|
||||
public float MinWidth
|
||||
{
|
||||
get
|
||||
{
|
||||
return _node.MinWidth.Value;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
_node.MinWidth = value;
|
||||
}
|
||||
}
|
||||
|
||||
public float MinHeight
|
||||
{
|
||||
get
|
||||
{
|
||||
return _node.MinHeight.Value;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
_node.MinHeight = value;
|
||||
}
|
||||
}
|
||||
|
||||
public float MaxWidth
|
||||
{
|
||||
get
|
||||
{
|
||||
return _node.MaxWidth.Value;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
_node.MaxWidth = value;
|
||||
}
|
||||
}
|
||||
|
||||
public float MaxHeight
|
||||
{
|
||||
get
|
||||
{
|
||||
return _node.MaxHeight.Value;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
_node.MaxHeight = value;
|
||||
}
|
||||
}
|
||||
|
||||
public float AspectRatio
|
||||
{
|
||||
get
|
||||
{
|
||||
return _node.StyleAspectRatio;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
_node.StyleAspectRatio = value;
|
||||
}
|
||||
}
|
||||
|
||||
public void ApplyLayout()
|
||||
{
|
||||
NativeView view = null;
|
||||
if (_viewRef.TryGetTarget(out view))
|
||||
{
|
||||
float width = 0;
|
||||
float height = 0;
|
||||
GetWidthHeightOfNativeView(view, out width, out height);
|
||||
CalculateLayoutWithSize(this, width, height);
|
||||
ApplyLayoutToViewHierarchy(view);
|
||||
}
|
||||
}
|
||||
public SizeF IntrinsicSize
|
||||
{
|
||||
get
|
||||
{
|
||||
return CalculateLayoutWithSize(this, float.NaN, float.NaN);
|
||||
}
|
||||
}
|
||||
|
||||
SizeF CalculateLayoutWithSize(YogaLayout layout, float width, float height)
|
||||
{
|
||||
//TODO : Check thread access
|
||||
if (!layout.IsEnabled)
|
||||
{
|
||||
System.Diagnostics.Debug.WriteLine("Doesn't use Yoga");
|
||||
}
|
||||
NativeView view = null;
|
||||
if (_viewRef.TryGetTarget(out view))
|
||||
{
|
||||
AttachNodesFromViewHierachy(view);
|
||||
}
|
||||
|
||||
var node = layout._node;
|
||||
|
||||
node.Width = width;
|
||||
node.Height = height;
|
||||
node.CalculateLayout();
|
||||
|
||||
return new SizeF { Width = node.LayoutWidth, Height = node.LayoutHeight };
|
||||
}
|
||||
|
||||
static YogaSize MeasureView(YogaNode node, float width, YogaMeasureMode widthMode, float height, YogaMeasureMode heightMode)
|
||||
{
|
||||
var constrainedWidth = (widthMode == YogaMeasureMode.Undefined) ? float.MaxValue : width;
|
||||
var constrainedHeight = (heightMode == YogaMeasureMode.Undefined) ? float.MaxValue : height;
|
||||
|
||||
NativeView view = null;
|
||||
if (YogaKit.Bridges.ContainsKey(node))
|
||||
view = YogaKit.Bridges[node] as NativeView;
|
||||
|
||||
float sizeThatFitsWidth = 0;
|
||||
float sizeThatFitsHeight = 0;
|
||||
|
||||
MeasureNativeView(view, constrainedWidth, constrainedHeight, out sizeThatFitsWidth, out sizeThatFitsHeight);
|
||||
|
||||
var finalWidth = SanitizeMeasurement(constrainedWidth, sizeThatFitsWidth, widthMode);
|
||||
var finalHeight = SanitizeMeasurement(constrainedHeight, sizeThatFitsHeight, heightMode);
|
||||
|
||||
return MeasureOutput.Make(finalWidth, finalHeight);
|
||||
}
|
||||
|
||||
static float SanitizeMeasurement(float constrainedSize, float measuredSize, YogaMeasureMode measureMode)
|
||||
{
|
||||
float result;
|
||||
if (measureMode == YogaMeasureMode.Exactly)
|
||||
{
|
||||
result = (float)constrainedSize;
|
||||
}
|
||||
else if (measureMode == YogaMeasureMode.AtMost)
|
||||
{
|
||||
result = (float)Math.Min(constrainedSize, measuredSize);
|
||||
}
|
||||
else {
|
||||
result = (float)measuredSize;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static bool NodeHasExactSameChildren(YogaNode node, NativeView[] subviews)
|
||||
{
|
||||
if (node.Count != subviews.Length)
|
||||
return false;
|
||||
for (int i = 0; i < subviews.Length; i++)
|
||||
{
|
||||
YogaLayout yoga = subviews[i].Yoga() as YogaLayout;
|
||||
if (node[i] != yoga._node)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static void AttachNodesFromViewHierachy(NativeView view)
|
||||
{
|
||||
YogaLayout yoga = view.Yoga() as YogaLayout;
|
||||
var node = yoga._node;
|
||||
// Only leaf nodes should have a measure function
|
||||
if (yoga.IsLeaf)
|
||||
{
|
||||
RemoveAllChildren(node);
|
||||
node.SetMeasureFunction(MeasureView);
|
||||
}
|
||||
else
|
||||
{
|
||||
node.SetMeasureFunction(null);
|
||||
// Create a list of all the subviews that we are going to use for layout.
|
||||
var subviewsToInclude = new List<NativeView>();
|
||||
foreach (var subview in view.Subviews)
|
||||
{
|
||||
if (subview.Yoga().IsIncludeInLayout)
|
||||
{
|
||||
subviewsToInclude.Add(subview);
|
||||
}
|
||||
}
|
||||
|
||||
if (!NodeHasExactSameChildren(node, subviewsToInclude.ToArray()))
|
||||
{
|
||||
RemoveAllChildren(node);
|
||||
for (int i = 0; i < subviewsToInclude.Count; i++)
|
||||
{
|
||||
YogaLayout yogaSubview = subviewsToInclude[i].Yoga() as YogaLayout;
|
||||
node.Insert(i, yogaSubview._node);
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var subView in subviewsToInclude)
|
||||
{
|
||||
AttachNodesFromViewHierachy(subView);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void RemoveAllChildren(YogaNode node)
|
||||
{
|
||||
if (node == null)
|
||||
return;
|
||||
|
||||
if (node.Count > 0)
|
||||
{
|
||||
node.Clear();
|
||||
}
|
||||
}
|
||||
|
||||
static double RoundPixelValue(float value)
|
||||
{
|
||||
float scale = NativePixelScale;
|
||||
|
||||
return Math.Round(value * scale) / scale;
|
||||
}
|
||||
|
||||
static void ApplyLayoutToViewHierarchy(NativeView view)
|
||||
{
|
||||
//TODO : "Framesetting should only be done on the main thread."
|
||||
YogaLayout yoga = view.Yoga() as YogaLayout;
|
||||
|
||||
if (!yoga.IsIncludeInLayout)
|
||||
return;
|
||||
|
||||
var node = yoga._node;
|
||||
|
||||
ApplyLayoutToNativeView(view, node);
|
||||
|
||||
if (!yoga.IsLeaf)
|
||||
{
|
||||
for (int i = 0; i < view.Subviews.Length; i++)
|
||||
{
|
||||
ApplyLayoutToViewHierarchy(view.Subviews[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
23
csharp/iOS/Facebook.YogaKit.iOS.Sample/AppDelegate.cs
Normal file
23
csharp/iOS/Facebook.YogaKit.iOS.Sample/AppDelegate.cs
Normal file
@@ -0,0 +1,23 @@
|
||||
using Foundation;
|
||||
using UIKit;
|
||||
|
||||
namespace Facebook.YogaKit.iOS.Sample
|
||||
{
|
||||
[Register("AppDelegate")]
|
||||
public class AppDelegate : UIApplicationDelegate
|
||||
{
|
||||
public override UIWindow Window
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
public override bool FinishedLaunching(UIApplication application, NSDictionary launchOptions)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
@@ -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"
|
||||
}
|
||||
}
|
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"info" : {
|
||||
"version" : 1,
|
||||
"author" : "xcode"
|
||||
}
|
||||
}
|
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
</dict>
|
||||
</plist>
|
@@ -0,0 +1,128 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">iPhoneSimulator</Platform>
|
||||
<ProjectGuid>{6A094B74-FA9A-4E49-A8E1-F450A04E3E5B}</ProjectGuid>
|
||||
<ProjectTypeGuids>{FEACFBD2-3405-455C-9665-78FE426C6842};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
|
||||
<OutputType>Exe</OutputType>
|
||||
<RootNamespace>Facebook.YogaKit.iOS.Sample</RootNamespace>
|
||||
<AssemblyName>Facebook.YogaKit.iOS.Sample</AssemblyName>
|
||||
<IPhoneResourcePrefix>Resources</IPhoneResourcePrefix>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|iPhoneSimulator' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\iPhoneSimulator\Debug</OutputPath>
|
||||
<DefineConstants>DEBUG;ENABLE_TEST_CLOUD;__IOS__</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<CodesignKey>iPhone Developer</CodesignKey>
|
||||
<MtouchDebug>true</MtouchDebug>
|
||||
<MtouchFastDev>true</MtouchFastDev>
|
||||
<MtouchProfiling>true</MtouchProfiling>
|
||||
<MtouchUseSGen>true</MtouchUseSGen>
|
||||
<MtouchUseRefCounting>true</MtouchUseRefCounting>
|
||||
<IOSDebuggerPort>56768</IOSDebuggerPort>
|
||||
<MtouchLink>None</MtouchLink>
|
||||
<MtouchArch>x86_64</MtouchArch>
|
||||
<MtouchHttpClientHandler>HttpClientHandler</MtouchHttpClientHandler>
|
||||
<MtouchTlsProvider>Default</MtouchTlsProvider>
|
||||
<DeviceSpecificBuild>false</DeviceSpecificBuild>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|iPhone' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\iPhone\Release</OutputPath>
|
||||
<DefineConstants></DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<CodesignKey>iPhone Developer</CodesignKey>
|
||||
<MtouchUseSGen>true</MtouchUseSGen>
|
||||
<MtouchUseRefCounting>true</MtouchUseRefCounting>
|
||||
<MtouchFloat32>true</MtouchFloat32>
|
||||
<CodesignEntitlements>Entitlements.plist</CodesignEntitlements>
|
||||
<MtouchLink>SdkOnly</MtouchLink>
|
||||
<MtouchArch>ARMv7, ARM64</MtouchArch>
|
||||
<MtouchHttpClientHandler>HttpClientHandler</MtouchHttpClientHandler>
|
||||
<MtouchTlsProvider>Default</MtouchTlsProvider>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|iPhoneSimulator' ">
|
||||
<DebugType></DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\iPhoneSimulator\Release</OutputPath>
|
||||
<DefineConstants></DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<CodesignKey>iPhone Developer</CodesignKey>
|
||||
<MtouchUseSGen>true</MtouchUseSGen>
|
||||
<MtouchUseRefCounting>true</MtouchUseRefCounting>
|
||||
<MtouchLink>None</MtouchLink>
|
||||
<MtouchArch>x86_64</MtouchArch>
|
||||
<MtouchHttpClientHandler>HttpClientHandler</MtouchHttpClientHandler>
|
||||
<MtouchTlsProvider>Default</MtouchTlsProvider>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|iPhone' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\iPhone\Debug</OutputPath>
|
||||
<DefineConstants>DEBUG;ENABLE_TEST_CLOUD;</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<CodesignKey>iPhone Developer</CodesignKey>
|
||||
<DeviceSpecificBuild>true</DeviceSpecificBuild>
|
||||
<MtouchDebug>true</MtouchDebug>
|
||||
<MtouchFastDev>true</MtouchFastDev>
|
||||
<MtouchProfiling>true</MtouchProfiling>
|
||||
<MtouchUseSGen>true</MtouchUseSGen>
|
||||
<MtouchUseRefCounting>true</MtouchUseRefCounting>
|
||||
<MtouchFloat32>true</MtouchFloat32>
|
||||
<CodesignEntitlements>Entitlements.plist</CodesignEntitlements>
|
||||
<MtouchLink>SdkOnly</MtouchLink>
|
||||
<MtouchArch>ARMv7, ARM64</MtouchArch>
|
||||
<MtouchHttpClientHandler>HttpClientHandler</MtouchHttpClientHandler>
|
||||
<MtouchTlsProvider>Default</MtouchTlsProvider>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Xml" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="Xamarin.iOS" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ImageAsset Include="Assets.xcassets\AppIcon.appiconset\Contents.json" />
|
||||
<ImageAsset Include="Assets.xcassets\Contents.json" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Folder Include="Resources\" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<InterfaceDefinition Include="LaunchScreen.storyboard" />
|
||||
<InterfaceDefinition Include="Main.storyboard" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="Info.plist" />
|
||||
<None Include="Entitlements.plist" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Main.cs" />
|
||||
<Compile Include="AppDelegate.cs" />
|
||||
<Compile Include="ViewController.cs" />
|
||||
<Compile Include="ViewController.designer.cs">
|
||||
<DependentUpon>ViewController.cs</DependentUpon>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Facebook.YogaKit.iOS\Facebook.YogaKit.iOS.csproj">
|
||||
<Project>{0C38AA9D-3178-4B43-9C3B-3C97A90FB1B0}</Project>
|
||||
<Name>Facebook.YogaKit.iOS</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\Facebook.Yoga.iOS\Facebook.Yoga.iOS.csproj">
|
||||
<Project>{128FB32A-C4A1-4363-BF06-0A36E700B7FA}</Project>
|
||||
<Name>Facebook.Yoga.iOS</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildExtensionsPath)\Xamarin\iOS\Xamarin.iOS.CSharp.targets" />
|
||||
</Project>
|
39
csharp/iOS/Facebook.YogaKit.iOS.Sample/Info.plist
Normal file
39
csharp/iOS/Facebook.YogaKit.iOS.Sample/Info.plist
Normal file
@@ -0,0 +1,39 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>CFBundleName</key>
|
||||
<string>Facebook.YogaKit.iOS.Sample</string>
|
||||
<key>CFBundleIdentifier</key>
|
||||
<string>com.xamarin.facebook-yogakit-ios-sample</string>
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>1.0</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>1.0</string>
|
||||
<key>LSRequiresIPhoneOS</key>
|
||||
<true/>
|
||||
<key>MinimumOSVersion</key>
|
||||
<string>10.2</string>
|
||||
<key>UIDeviceFamily</key>
|
||||
<array>
|
||||
<integer>1</integer>
|
||||
<integer>2</integer>
|
||||
</array>
|
||||
<key>UILaunchStoryboardName</key>
|
||||
<string>LaunchScreen</string>
|
||||
<key>UIMainStoryboardFile</key>
|
||||
<string>Main</string>
|
||||
<key>UIRequiredDeviceCapabilities</key>
|
||||
<array>
|
||||
<string>armv7</string>
|
||||
</array>
|
||||
<key>UISupportedInterfaceOrientations</key>
|
||||
<array>
|
||||
<string>UIInterfaceOrientationPortrait</string>
|
||||
<string>UIInterfaceOrientationLandscapeLeft</string>
|
||||
<string>UIInterfaceOrientationLandscapeRight</string>
|
||||
</array>
|
||||
<key>XSAppIconAssets</key>
|
||||
<string>Assets.xcassets/AppIcon.appiconset</string>
|
||||
</dict>
|
||||
</plist>
|
@@ -0,0 +1,27 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="9532" systemVersion="15D21" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES" initialViewController="01J-lp-oVM">
|
||||
<dependencies>
|
||||
<deployment identifier="iOS" />
|
||||
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="9530" />
|
||||
</dependencies>
|
||||
<scenes>
|
||||
<!--View Controller-->
|
||||
<scene sceneID="EHf-IW-A2E">
|
||||
<objects>
|
||||
<viewController id="01J-lp-oVM" sceneMemberID="viewController">
|
||||
<layoutGuides>
|
||||
<viewControllerLayoutGuide type="top" id="Llm-lL-Icb" />
|
||||
<viewControllerLayoutGuide type="bottom" id="xb3-aO-Qok" />
|
||||
</layoutGuides>
|
||||
<view key="view" contentMode="scaleToFill" id="Ze5-6b-2t3">
|
||||
<rect key="frame" x="0.0" y="0.0" width="600" height="600" />
|
||||
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES" />
|
||||
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite" />
|
||||
</view>
|
||||
</viewController>
|
||||
<placeholder placeholderIdentifier="IBFirstResponder" id="iYj-Kq-Ea1" userLabel="First Responder" sceneMemberID="firstResponder" />
|
||||
</objects>
|
||||
<point key="canvasLocation" x="53" y="375" />
|
||||
</scene>
|
||||
</scenes>
|
||||
</document>
|
12
csharp/iOS/Facebook.YogaKit.iOS.Sample/Main.cs
Normal file
12
csharp/iOS/Facebook.YogaKit.iOS.Sample/Main.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
using UIKit;
|
||||
|
||||
namespace Facebook.YogaKit.iOS.Sample
|
||||
{
|
||||
public class Application
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
UIApplication.Main(args, null, "AppDelegate");
|
||||
}
|
||||
}
|
||||
}
|
25
csharp/iOS/Facebook.YogaKit.iOS.Sample/Main.storyboard
Normal file
25
csharp/iOS/Facebook.YogaKit.iOS.Sample/Main.storyboard
Normal file
@@ -0,0 +1,25 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="6211" systemVersion="14A298i" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="BYZ-38-t0r">
|
||||
<dependencies>
|
||||
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="6204" />
|
||||
</dependencies>
|
||||
<scenes>
|
||||
<!--View Controller-->
|
||||
<scene sceneID="tne-QT-ifu">
|
||||
<objects>
|
||||
<viewController id="BYZ-38-t0r" customClass="ViewController" customModuleProvider="" sceneMemberID="viewController">
|
||||
<layoutGuides>
|
||||
<viewControllerLayoutGuide type="top" id="y3c-jy-aDJ" />
|
||||
<viewControllerLayoutGuide type="bottom" id="wfy-db-euE" />
|
||||
</layoutGuides>
|
||||
<view key="view" contentMode="scaleToFill" id="8bC-Xf-vdC">
|
||||
<rect key="frame" x="0.0" y="0.0" width="600" height="600" />
|
||||
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES" />
|
||||
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite" />
|
||||
</view>
|
||||
</viewController>
|
||||
<placeholder placeholderIdentifier="IBFirstResponder" id="dkx-z0-nzr" sceneMemberID="firstResponder" />
|
||||
</objects>
|
||||
</scene>
|
||||
</scenes>
|
||||
</document>
|
54
csharp/iOS/Facebook.YogaKit.iOS.Sample/ViewController.cs
Normal file
54
csharp/iOS/Facebook.YogaKit.iOS.Sample/ViewController.cs
Normal file
@@ -0,0 +1,54 @@
|
||||
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.Yoga().IsEnabled = true;
|
||||
|
||||
root.Yoga().Width = (float)width;
|
||||
root.Yoga().Height = (float)height;
|
||||
root.Yoga().AlignItems = YogaAlign.Center;
|
||||
root.Yoga().JustifyContent = YogaJustify.Center;
|
||||
|
||||
var child1 = new UIView { BackgroundColor = UIColor.Blue };
|
||||
child1.Yoga().IsEnabled = true;
|
||||
child1.Yoga().Width = 100;
|
||||
child1.Yoga().Height = 100;
|
||||
|
||||
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.Yoga().ApplyLayout();
|
||||
}
|
||||
}
|
||||
}
|
17
csharp/iOS/Facebook.YogaKit.iOS.Sample/ViewController.designer.cs
generated
Normal file
17
csharp/iOS/Facebook.YogaKit.iOS.Sample/ViewController.designer.cs
generated
Normal file
@@ -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()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
6
csharp/iOS/Facebook.YogaKit.iOS.Tests/Entitlements.plist
Normal file
6
csharp/iOS/Facebook.YogaKit.iOS.Tests/Entitlements.plist
Normal file
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
</dict>
|
||||
</plist>
|
@@ -0,0 +1,118 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">iPhoneSimulator</Platform>
|
||||
<ProjectGuid>{238DB3A2-1182-4775-92BC-F62C885725D8}</ProjectGuid>
|
||||
<ProjectTypeGuids>{FEACFBD2-3405-455C-9665-78FE426C6842};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
|
||||
<OutputType>Exe</OutputType>
|
||||
<RootNamespace>Facebook.YogaKit.iOS.Tests</RootNamespace>
|
||||
<AssemblyName>Facebook.YogaKit.iOS.Tests</AssemblyName>
|
||||
<IPhoneResourcePrefix>Resources</IPhoneResourcePrefix>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|iPhoneSimulator' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\iPhoneSimulator\Debug</OutputPath>
|
||||
<DefineConstants>DEBUG;</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<CodesignKey>iPhone Developer</CodesignKey>
|
||||
<MtouchDebug>true</MtouchDebug>
|
||||
<MtouchFastDev>true</MtouchFastDev>
|
||||
<MtouchProfiling>true</MtouchProfiling>
|
||||
<MtouchUseSGen>true</MtouchUseSGen>
|
||||
<MtouchUseRefCounting>true</MtouchUseRefCounting>
|
||||
<IOSDebuggerPort>17481</IOSDebuggerPort>
|
||||
<MtouchLink>None</MtouchLink>
|
||||
<MtouchArch>x86_64</MtouchArch>
|
||||
<MtouchHttpClientHandler>HttpClientHandler</MtouchHttpClientHandler>
|
||||
<MtouchTlsProvider>Default</MtouchTlsProvider>
|
||||
<DeviceSpecificBuild>false</DeviceSpecificBuild>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|iPhone' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\iPhone\Release</OutputPath>
|
||||
<DefineConstants></DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<CodesignKey>iPhone Developer</CodesignKey>
|
||||
<MtouchUseSGen>true</MtouchUseSGen>
|
||||
<MtouchUseRefCounting>true</MtouchUseRefCounting>
|
||||
<MtouchFloat32>true</MtouchFloat32>
|
||||
<CodesignEntitlements>Entitlements.plist</CodesignEntitlements>
|
||||
<MtouchLink>SdkOnly</MtouchLink>
|
||||
<MtouchArch>ARMv7, ARM64</MtouchArch>
|
||||
<MtouchHttpClientHandler>HttpClientHandler</MtouchHttpClientHandler>
|
||||
<MtouchTlsProvider>Default</MtouchTlsProvider>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|iPhoneSimulator' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\iPhoneSimulator\Release</OutputPath>
|
||||
<DefineConstants></DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<CodesignKey>iPhone Developer</CodesignKey>
|
||||
<MtouchUseSGen>true</MtouchUseSGen>
|
||||
<MtouchUseRefCounting>true</MtouchUseRefCounting>
|
||||
<MtouchLink>None</MtouchLink>
|
||||
<MtouchArch>x86_64</MtouchArch>
|
||||
<MtouchHttpClientHandler>HttpClientHandler</MtouchHttpClientHandler>
|
||||
<MtouchTlsProvider>Default</MtouchTlsProvider>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|iPhone' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\iPhone\Debug</OutputPath>
|
||||
<DefineConstants>DEBUG;</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<CodesignKey>iPhone Developer</CodesignKey>
|
||||
<DeviceSpecificBuild>true</DeviceSpecificBuild>
|
||||
<MtouchDebug>true</MtouchDebug>
|
||||
<MtouchFastDev>true</MtouchFastDev>
|
||||
<MtouchProfiling>true</MtouchProfiling>
|
||||
<MtouchUseSGen>true</MtouchUseSGen>
|
||||
<MtouchUseRefCounting>true</MtouchUseRefCounting>
|
||||
<MtouchFloat32>true</MtouchFloat32>
|
||||
<CodesignEntitlements>Entitlements.plist</CodesignEntitlements>
|
||||
<MtouchLink>SdkOnly</MtouchLink>
|
||||
<MtouchArch>ARMv7, ARM64</MtouchArch>
|
||||
<MtouchHttpClientHandler>HttpClientHandler</MtouchHttpClientHandler>
|
||||
<MtouchTlsProvider>Default</MtouchTlsProvider>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Xml" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="Xamarin.iOS" />
|
||||
<Reference Include="MonoTouch.NUnitLite" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<InterfaceDefinition Include="LaunchScreen.storyboard" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="Info.plist" />
|
||||
<None Include="Entitlements.plist" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Main.cs" />
|
||||
<Compile Include="UnitTestAppDelegate.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Facebook.YogaKit.iOS\Facebook.YogaKit.iOS.csproj">
|
||||
<Project>{0C38AA9D-3178-4B43-9C3B-3C97A90FB1B0}</Project>
|
||||
<Name>Facebook.YogaKit.iOS</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\Facebook.Yoga.iOS\Facebook.Yoga.iOS.csproj">
|
||||
<Project>{128FB32A-C4A1-4363-BF06-0A36E700B7FA}</Project>
|
||||
<Name>Facebook.Yoga.iOS</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<Import Project="..\..\tests\Facebook.YogaKit.Shared.Tests\Facebook.YogaKit.Shared.Tests.projitems" Label="Shared" Condition="Exists('..\..\tests\Facebook.YogaKit.Shared.Tests\Facebook.YogaKit.Shared.Tests.projitems')" />
|
||||
<Import Project="$(MSBuildExtensionsPath)\Xamarin\iOS\Xamarin.iOS.CSharp.targets" />
|
||||
</Project>
|
36
csharp/iOS/Facebook.YogaKit.iOS.Tests/Info.plist
Normal file
36
csharp/iOS/Facebook.YogaKit.iOS.Tests/Info.plist
Normal file
@@ -0,0 +1,36 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"[]>
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>CFBundleName</key>
|
||||
<string>Facebook.YogaKit.iOS.Tests</string>
|
||||
<key>CFBundleIdentifier</key>
|
||||
<string>com.xamarin.facebook-yogakit-ios-tests</string>
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>1.0</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>1.0</string>
|
||||
<key>LSRequiresIPhoneOS</key>
|
||||
<true />
|
||||
<key>MinimumOSVersion</key>
|
||||
<string>10.2</string>
|
||||
<key>UIDeviceFamily</key>
|
||||
<array>
|
||||
<integer>1</integer>
|
||||
<integer>2</integer>
|
||||
</array>
|
||||
<key>UISupportedInterfaceOrientations</key>
|
||||
<array>
|
||||
<string>UIInterfaceOrientationPortrait</string>
|
||||
<string>UIInterfaceOrientationLandscapeLeft</string>
|
||||
<string>UIInterfaceOrientationLandscapeRight</string>
|
||||
</array>
|
||||
<key>UILaunchStoryboardName</key>
|
||||
<string>LaunchScreen</string>
|
||||
<key>NSAppTransportSecurity</key>
|
||||
<dict>
|
||||
<key>NSAllowsArbitraryLoads</key>
|
||||
<true />
|
||||
</dict>
|
||||
</dict>
|
||||
</plist>
|
@@ -0,0 +1,27 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="9532" systemVersion="15D21" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES" initialViewController="01J-lp-oVM">
|
||||
<dependencies>
|
||||
<deployment identifier="iOS" />
|
||||
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="9530" />
|
||||
</dependencies>
|
||||
<scenes>
|
||||
<!--View Controller-->
|
||||
<scene sceneID="EHf-IW-A2E">
|
||||
<objects>
|
||||
<viewController id="01J-lp-oVM" sceneMemberID="viewController">
|
||||
<layoutGuides>
|
||||
<viewControllerLayoutGuide type="top" id="Llm-lL-Icb" />
|
||||
<viewControllerLayoutGuide type="bottom" id="xb3-aO-Qok" />
|
||||
</layoutGuides>
|
||||
<view key="view" contentMode="scaleToFill" id="Ze5-6b-2t3">
|
||||
<rect key="frame" x="0.0" y="0.0" width="600" height="600" />
|
||||
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES" />
|
||||
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite" />
|
||||
</view>
|
||||
</viewController>
|
||||
<placeholder placeholderIdentifier="IBFirstResponder" id="iYj-Kq-Ea1" userLabel="First Responder" sceneMemberID="firstResponder" />
|
||||
</objects>
|
||||
<point key="canvasLocation" x="53" y="375" />
|
||||
</scene>
|
||||
</scenes>
|
||||
</document>
|
20
csharp/iOS/Facebook.YogaKit.iOS.Tests/Main.cs
Normal file
20
csharp/iOS/Facebook.YogaKit.iOS.Tests/Main.cs
Normal file
@@ -0,0 +1,20 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using Foundation;
|
||||
using UIKit;
|
||||
|
||||
namespace Facebook.YogaKit.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");
|
||||
}
|
||||
}
|
||||
}
|
45
csharp/iOS/Facebook.YogaKit.iOS.Tests/UnitTestAppDelegate.cs
Normal file
45
csharp/iOS/Facebook.YogaKit.iOS.Tests/UnitTestAppDelegate.cs
Normal file
@@ -0,0 +1,45 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using Foundation;
|
||||
using UIKit;
|
||||
using MonoTouch.NUnit.UI;
|
||||
|
||||
namespace Facebook.YogaKit.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;
|
||||
}
|
||||
}
|
||||
}
|
84
csharp/iOS/Facebook.YogaKit.iOS.sln
Normal file
84
csharp/iOS/Facebook.YogaKit.iOS.sln
Normal file
@@ -0,0 +1,84 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 2012
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Shared", "Shared", "{9FB621AA-66DD-46F1-8B10-94F508272A8D}"
|
||||
EndProject
|
||||
Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "Facebook.YogaKit.Shared", "..\Facebook.YogaKit\Facebook.YogaKit.Shared.shproj", "{A24B3BA6-3143-4FFF-B8B8-1EDF166F5F4A}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Facebook.YogaKit.iOS", "Facebook.YogaKit.iOS\Facebook.YogaKit.iOS.csproj", "{0C38AA9D-3178-4B43-9C3B-3C97A90FB1B0}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Facebook.YogaKit.iOS.Sample", "Facebook.YogaKit.iOS.Sample\Facebook.YogaKit.iOS.Sample.csproj", "{6A094B74-FA9A-4E49-A8E1-F450A04E3E5B}"
|
||||
EndProject
|
||||
Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "Facebook.Yoga.Shared", "..\Facebook.Yoga\Facebook.Yoga.Shared.shproj", "{91C42D32-291D-4B72-90B4-551663D60B8B}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Facebook.Yoga.iOS", "Facebook.Yoga.iOS\Facebook.Yoga.iOS.csproj", "{128FB32A-C4A1-4363-BF06-0A36E700B7FA}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Facebook.YogaKit.iOS.Tests", "Facebook.YogaKit.iOS.Tests\Facebook.YogaKit.iOS.Tests.csproj", "{238DB3A2-1182-4775-92BC-F62C885725D8}"
|
||||
EndProject
|
||||
Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "Facebook.YogaKit.Shared.Tests", "..\tests\Facebook.YogaKit.Shared.Tests\Facebook.YogaKit.Shared.Tests.shproj", "{63AB08F4-4F7C-42B7-A20F-D84204D0D3CE}"
|
||||
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
|
||||
{0C38AA9D-3178-4B43-9C3B-3C97A90FB1B0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{0C38AA9D-3178-4B43-9C3B-3C97A90FB1B0}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{0C38AA9D-3178-4B43-9C3B-3C97A90FB1B0}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{0C38AA9D-3178-4B43-9C3B-3C97A90FB1B0}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{0C38AA9D-3178-4B43-9C3B-3C97A90FB1B0}.Debug|iPhoneSimulator.ActiveCfg = Debug|Any CPU
|
||||
{0C38AA9D-3178-4B43-9C3B-3C97A90FB1B0}.Debug|iPhoneSimulator.Build.0 = Debug|Any CPU
|
||||
{0C38AA9D-3178-4B43-9C3B-3C97A90FB1B0}.Release|iPhone.ActiveCfg = Release|Any CPU
|
||||
{0C38AA9D-3178-4B43-9C3B-3C97A90FB1B0}.Release|iPhone.Build.0 = Release|Any CPU
|
||||
{0C38AA9D-3178-4B43-9C3B-3C97A90FB1B0}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU
|
||||
{0C38AA9D-3178-4B43-9C3B-3C97A90FB1B0}.Release|iPhoneSimulator.Build.0 = Release|Any CPU
|
||||
{0C38AA9D-3178-4B43-9C3B-3C97A90FB1B0}.Debug|iPhone.ActiveCfg = Debug|Any CPU
|
||||
{0C38AA9D-3178-4B43-9C3B-3C97A90FB1B0}.Debug|iPhone.Build.0 = Debug|Any CPU
|
||||
{6A094B74-FA9A-4E49-A8E1-F450A04E3E5B}.Debug|Any CPU.ActiveCfg = Debug|iPhoneSimulator
|
||||
{6A094B74-FA9A-4E49-A8E1-F450A04E3E5B}.Debug|Any CPU.Build.0 = Debug|iPhoneSimulator
|
||||
{6A094B74-FA9A-4E49-A8E1-F450A04E3E5B}.Release|Any CPU.ActiveCfg = Release|iPhone
|
||||
{6A094B74-FA9A-4E49-A8E1-F450A04E3E5B}.Release|Any CPU.Build.0 = Release|iPhone
|
||||
{6A094B74-FA9A-4E49-A8E1-F450A04E3E5B}.Debug|iPhoneSimulator.ActiveCfg = Debug|iPhoneSimulator
|
||||
{6A094B74-FA9A-4E49-A8E1-F450A04E3E5B}.Debug|iPhoneSimulator.Build.0 = Debug|iPhoneSimulator
|
||||
{6A094B74-FA9A-4E49-A8E1-F450A04E3E5B}.Release|iPhone.ActiveCfg = Release|iPhone
|
||||
{6A094B74-FA9A-4E49-A8E1-F450A04E3E5B}.Release|iPhone.Build.0 = Release|iPhone
|
||||
{6A094B74-FA9A-4E49-A8E1-F450A04E3E5B}.Release|iPhoneSimulator.ActiveCfg = Release|iPhoneSimulator
|
||||
{6A094B74-FA9A-4E49-A8E1-F450A04E3E5B}.Release|iPhoneSimulator.Build.0 = Release|iPhoneSimulator
|
||||
{6A094B74-FA9A-4E49-A8E1-F450A04E3E5B}.Debug|iPhone.ActiveCfg = Debug|iPhone
|
||||
{6A094B74-FA9A-4E49-A8E1-F450A04E3E5B}.Debug|iPhone.Build.0 = Debug|iPhone
|
||||
{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
|
||||
{238DB3A2-1182-4775-92BC-F62C885725D8}.Debug|Any CPU.ActiveCfg = Debug|iPhoneSimulator
|
||||
{238DB3A2-1182-4775-92BC-F62C885725D8}.Debug|Any CPU.Build.0 = Debug|iPhoneSimulator
|
||||
{238DB3A2-1182-4775-92BC-F62C885725D8}.Release|Any CPU.ActiveCfg = Release|iPhone
|
||||
{238DB3A2-1182-4775-92BC-F62C885725D8}.Release|Any CPU.Build.0 = Release|iPhone
|
||||
{238DB3A2-1182-4775-92BC-F62C885725D8}.Debug|iPhoneSimulator.ActiveCfg = Debug|iPhoneSimulator
|
||||
{238DB3A2-1182-4775-92BC-F62C885725D8}.Debug|iPhoneSimulator.Build.0 = Debug|iPhoneSimulator
|
||||
{238DB3A2-1182-4775-92BC-F62C885725D8}.Release|iPhone.ActiveCfg = Release|iPhone
|
||||
{238DB3A2-1182-4775-92BC-F62C885725D8}.Release|iPhone.Build.0 = Release|iPhone
|
||||
{238DB3A2-1182-4775-92BC-F62C885725D8}.Release|iPhoneSimulator.ActiveCfg = Release|iPhoneSimulator
|
||||
{238DB3A2-1182-4775-92BC-F62C885725D8}.Release|iPhoneSimulator.Build.0 = Release|iPhoneSimulator
|
||||
{238DB3A2-1182-4775-92BC-F62C885725D8}.Debug|iPhone.ActiveCfg = Debug|iPhone
|
||||
{238DB3A2-1182-4775-92BC-F62C885725D8}.Debug|iPhone.Build.0 = Debug|iPhone
|
||||
EndGlobalSection
|
||||
GlobalSection(NestedProjects) = preSolution
|
||||
{A24B3BA6-3143-4FFF-B8B8-1EDF166F5F4A} = {9FB621AA-66DD-46F1-8B10-94F508272A8D}
|
||||
{91C42D32-291D-4B72-90B4-551663D60B8B} = {9FB621AA-66DD-46F1-8B10-94F508272A8D}
|
||||
{63AB08F4-4F7C-42B7-A20F-D84204D0D3CE} = {9FB621AA-66DD-46F1-8B10-94F508272A8D}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
69
csharp/iOS/Facebook.YogaKit.iOS/Facebook.YogaKit.iOS.csproj
Normal file
69
csharp/iOS/Facebook.YogaKit.iOS/Facebook.YogaKit.iOS.csproj
Normal file
@@ -0,0 +1,69 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{0C38AA9D-3178-4B43-9C3B-3C97A90FB1B0}</ProjectGuid>
|
||||
<ProjectTypeGuids>{FEACFBD2-3405-455C-9665-78FE426C6842};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
|
||||
<OutputType>Library</OutputType>
|
||||
<RootNamespace>Facebook.YogaKit.iOS</RootNamespace>
|
||||
<AssemblyName>Facebook.YogaKit.iOS</AssemblyName>
|
||||
<IPhoneResourcePrefix>Resources</IPhoneResourcePrefix>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug</OutputPath>
|
||||
<DefineConstants>DEBUG;__IOS__</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<CodesignKey>iPhone Developer</CodesignKey>
|
||||
<MtouchDebug>true</MtouchDebug>
|
||||
<MtouchFastDev>true</MtouchFastDev>
|
||||
<MtouchProfiling>true</MtouchProfiling>
|
||||
<MtouchUseSGen>true</MtouchUseSGen>
|
||||
<MtouchUseRefCounting>true</MtouchUseRefCounting>
|
||||
<IOSDebuggerPort>53781</IOSDebuggerPort>
|
||||
<DeviceSpecificBuild>false</DeviceSpecificBuild>
|
||||
<MtouchLink>SdkOnly</MtouchLink>
|
||||
<MtouchHttpClientHandler>HttpClientHandler</MtouchHttpClientHandler>
|
||||
<MtouchTlsProvider>Default</MtouchTlsProvider>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release</OutputPath>
|
||||
<DefineConstants></DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<CodesignKey>iPhone Developer</CodesignKey>
|
||||
<MtouchUseSGen>true</MtouchUseSGen>
|
||||
<MtouchUseRefCounting>true</MtouchUseRefCounting>
|
||||
<MtouchLink>SdkOnly</MtouchLink>
|
||||
<MtouchHttpClientHandler>HttpClientHandler</MtouchHttpClientHandler>
|
||||
<MtouchTlsProvider>Default</MtouchTlsProvider>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Xml" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="Xamarin.iOS" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Folder Include="Resources\" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="YogaLayout.cs" />
|
||||
<Compile Include="YogaKit.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Facebook.Yoga.iOS\Facebook.Yoga.iOS.csproj">
|
||||
<Project>{128FB32A-C4A1-4363-BF06-0A36E700B7FA}</Project>
|
||||
<Name>Facebook.Yoga.iOS</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<Import Project="..\..\Facebook.YogaKit\Facebook.YogaKit.projitems" Label="Shared" Condition="Exists('..\..\Facebook.YogaKit\Facebook.YogaKit.projitems')" />
|
||||
<Import Project="$(MSBuildExtensionsPath)\Xamarin\iOS\Xamarin.iOS.CSharp.targets" />
|
||||
</Project>
|
26
csharp/iOS/Facebook.YogaKit.iOS/Properties/AssemblyInfo.cs
Normal file
26
csharp/iOS/Facebook.YogaKit.iOS/Properties/AssemblyInfo.cs
Normal file
@@ -0,0 +1,26 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
// Information about this assembly is defined by the following attributes.
|
||||
// Change them to the values specific to your project.
|
||||
|
||||
[assembly: AssemblyTitle("Facebook.YogaKit.iOS")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("")]
|
||||
[assembly: AssemblyCopyright("rmarinho")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}".
|
||||
// The form "{Major}.{Minor}.*" will automatically update the build and revision,
|
||||
// and "{Major}.{Minor}.{Build}.*" will update just the revision.
|
||||
|
||||
[assembly: AssemblyVersion("1.0.*")]
|
||||
|
||||
// The following attributes are used to specify the signing key for the assembly,
|
||||
// if desired. See the Mono documentation for more information about signing.
|
||||
|
||||
//[assembly: AssemblyDelaySign(false)]
|
||||
//[assembly: AssemblyKeyFile("")]
|
43
csharp/iOS/Facebook.YogaKit.iOS/YogaKit.cs
Normal file
43
csharp/iOS/Facebook.YogaKit.iOS/YogaKit.cs
Normal file
@@ -0,0 +1,43 @@
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using Foundation;
|
||||
using UIKit;
|
||||
|
||||
namespace Facebook.YogaKit
|
||||
{
|
||||
public static partial class YogaKit
|
||||
{
|
||||
static NSString YogaNodeKey = new NSString("YogaNode");
|
||||
|
||||
public static IYogaLayout Yoga(this UIView view)
|
||||
{
|
||||
return YogaLayoutNative(view);
|
||||
}
|
||||
|
||||
static IYogaLayout YogaLayoutNative(UIView view)
|
||||
{
|
||||
var yoga = ObjCRuntime.Runtime.GetNSObject(objc_getAssociatedObject(view.Handle, YogaNodeKey.Handle)) as YogaLayout;
|
||||
if (yoga == null)
|
||||
{
|
||||
yoga = new YogaLayout(view);
|
||||
objc_setAssociatedObject(view.Handle, YogaNodeKey.Handle, yoga.Handle, AssociationPolicy.RETAIN_NONATOMIC);
|
||||
}
|
||||
return yoga;
|
||||
}
|
||||
|
||||
[DllImport("/usr/lib/libobjc.dylib")]
|
||||
static extern void objc_setAssociatedObject(IntPtr @object, IntPtr key, IntPtr value, AssociationPolicy policy);
|
||||
|
||||
[DllImport("/usr/lib/libobjc.dylib")]
|
||||
static extern IntPtr objc_getAssociatedObject(IntPtr @object, IntPtr key);
|
||||
|
||||
enum AssociationPolicy
|
||||
{
|
||||
ASSIGN = 0,
|
||||
RETAIN_NONATOMIC = 1,
|
||||
COPY_NONATOMIC = 3,
|
||||
RETAIN = 01401,
|
||||
COPY = 01403,
|
||||
}
|
||||
}
|
||||
}
|
52
csharp/iOS/Facebook.YogaKit.iOS/YogaLayout.cs
Normal file
52
csharp/iOS/Facebook.YogaKit.iOS/YogaLayout.cs
Normal file
@@ -0,0 +1,52 @@
|
||||
using System.Collections.Generic;
|
||||
using CoreGraphics;
|
||||
using Facebook.Yoga;
|
||||
using Foundation;
|
||||
using UIKit;
|
||||
|
||||
namespace Facebook.YogaKit
|
||||
{
|
||||
public partial class YogaLayout : NSObject
|
||||
{
|
||||
static IEnumerable<UIView> GetChildren(UIView view) => view.Subviews;
|
||||
|
||||
static void MeasureNativeView(UIView view, float constrainedWidth, float constrainedHeight, out float sizeThatFitsWidth, out float sizeThatFitsHeight)
|
||||
{
|
||||
var sizeThatFits = view.SizeThatFits(new CGSize(constrainedWidth, constrainedHeight));
|
||||
sizeThatFitsWidth = (float)sizeThatFits.Width;
|
||||
sizeThatFitsHeight = (float)sizeThatFits.Height;
|
||||
}
|
||||
|
||||
static void GetWidthHeightOfNativeView(UIView view, out float width, out float height)
|
||||
{
|
||||
width = (float)view.Bounds.Width;
|
||||
height = (float)view.Bounds.Height;
|
||||
}
|
||||
|
||||
static float NativePixelScale => (float)UIScreen.MainScreen.Scale;
|
||||
|
||||
|
||||
static void ApplyLayoutToNativeView(UIView view, YogaNode node)
|
||||
{
|
||||
var topLeft = new CGPoint(node.LayoutX, node.LayoutY);
|
||||
var bottomRight = new CGPoint(topLeft.X + node.LayoutWidth, topLeft.Y + node.LayoutHeight);
|
||||
view.Frame = new CGRect(RoundPixelValue((float)topLeft.X), RoundPixelValue((float)topLeft.Y), RoundPixelValue((float)bottomRight.X) - RoundPixelValue((float)topLeft.X), RoundPixelValue((float)bottomRight.Y) - RoundPixelValue((float)topLeft.Y));
|
||||
}
|
||||
|
||||
bool _disposed;
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && !_disposed)
|
||||
{
|
||||
_disposed = true;
|
||||
if (YogaKit.Bridges.ContainsKey(_node))
|
||||
{
|
||||
YogaKit.Bridges.Remove(_node);
|
||||
}
|
||||
_node = null;
|
||||
_viewRef = null;
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<MSBuildAllProjects>$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
|
||||
<HasSharedItems>true</HasSharedItems>
|
||||
<SharedGUID>{63AB08F4-4F7C-42B7-A20F-D84204D0D3CE}</SharedGUID>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Label="Configuration">
|
||||
<Import_RootNamespace>Facebook.YogaKit.Shared.Tests</Import_RootNamespace>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="$(MSBuildThisFileDirectory)YogaKitTest.cs" />
|
||||
</ItemGroup>
|
||||
</Project>
|
@@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<ProjectGuid>{63AB08F4-4F7C-42B7-A20F-D84204D0D3CE}</ProjectGuid>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.Common.Default.props" />
|
||||
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.Common.props" />
|
||||
<Import Project="Facebook.YogaKit.Shared.Tests.projitems" Label="Shared" />
|
||||
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.CSharp.targets" />
|
||||
</Project>
|
369
csharp/tests/Facebook.YogaKit.Shared.Tests/YogaKitTest.cs
Normal file
369
csharp/tests/Facebook.YogaKit.Shared.Tests/YogaKitTest.cs
Normal file
@@ -0,0 +1,369 @@
|
||||
using System.Drawing;
|
||||
using Facebook.Yoga;
|
||||
using NUnit.Framework;
|
||||
using System;
|
||||
#if __IOS__
|
||||
using NativeView = UIKit.UIView;
|
||||
using CoreGraphics;
|
||||
#endif
|
||||
|
||||
namespace Facebook.YogaKit
|
||||
{
|
||||
[TestFixture]
|
||||
public class YogaKitTest
|
||||
{
|
||||
[Test]
|
||||
public void TestUsesYoga()
|
||||
{
|
||||
var view = new NativeView();
|
||||
Assert.False(view.Yoga().IsEnabled);
|
||||
view.Yoga().IsEnabled = true;
|
||||
Assert.True(view.Yoga().IsEnabled);
|
||||
view.Yoga().IsEnabled = false;
|
||||
Assert.False(view.Yoga().IsEnabled);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestSizeThatFitsAsserts()
|
||||
{
|
||||
var view = new NativeView();
|
||||
Assert.Ignore("Not implemented yet");
|
||||
// dispatch_sync(dispatch_queue_create("com.facebook.Yoga.testing", DISPATCH_QUEUE_SERIAL), ^(void){
|
||||
// XCTAssertThrows(view.yoga.intrinsicSize);
|
||||
// });
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestSizeThatFitsSmoke()
|
||||
{
|
||||
var container = new NativeView();
|
||||
container.Yoga().IsEnabled = true;
|
||||
container.Yoga().FlexDirection = YogaFlexDirection.Row;
|
||||
container.Yoga().AlignItems = YogaAlign.FlexStart;
|
||||
|
||||
var longTextLabel = new UIKit.UILabel();
|
||||
longTextLabel.Text = @"This is a very very very very very very very very long piece of text.";
|
||||
longTextLabel.LineBreakMode = UIKit.UILineBreakMode.TailTruncation;
|
||||
longTextLabel.Lines = 1;
|
||||
longTextLabel.Yoga().IsEnabled = true;
|
||||
longTextLabel.Yoga().FlexShrink = 1;
|
||||
container.AddSubview(longTextLabel);
|
||||
|
||||
var textBadgeView = new NativeView();
|
||||
textBadgeView.Yoga().IsEnabled = true;
|
||||
textBadgeView.Yoga().MarginLeft = 3.0f;
|
||||
textBadgeView.Yoga().Width = 10;
|
||||
textBadgeView.Yoga().Height = 10;
|
||||
container.AddSubview(textBadgeView);
|
||||
|
||||
var containerSize = container.Yoga().IntrinsicSize;
|
||||
Assert.True(new SizeF(514, 21) == containerSize, $"Size is actually {containerSize})");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestThatMarkingLeafsAsDirtyWillTriggerASizeRecalculation()
|
||||
{
|
||||
var container = new NativeView(new CGRect(0, 0, 500, 500));
|
||||
container.Yoga().IsEnabled = true;
|
||||
container.Yoga().FlexDirection = YogaFlexDirection.Row;
|
||||
container.Yoga().AlignItems = YogaAlign.FlexStart;
|
||||
|
||||
var label = new UIKit.UILabel();
|
||||
label.Text = @"This is a short text.";
|
||||
label.Lines = 1;
|
||||
label.Yoga().IsEnabled = true;
|
||||
container.AddSubview(label);
|
||||
|
||||
container.Yoga().ApplyLayout();
|
||||
Assert.True(new SizeF(146, 21) == label.Bounds.Size, $"Size is actually {label.Bounds.Size})");
|
||||
|
||||
label.Text = @"This is a slightly longer text.";
|
||||
label.Yoga().MarkDirty();
|
||||
|
||||
container.Yoga().ApplyLayout();
|
||||
Assert.True(new SizeF(213, 21) == label.Bounds.Size, $"Size is actually {label.Bounds.Size})");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestFrameAndOriginPlacement()
|
||||
{
|
||||
var containerSize = new SizeF(320, 50);
|
||||
|
||||
var container = new NativeView(new CGRect(0, 0, containerSize.Width, containerSize.Height));
|
||||
container.Yoga().IsEnabled = true;
|
||||
container.Yoga().FlexDirection = YogaFlexDirection.Row;
|
||||
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
var subview = new NativeView();
|
||||
subview.Yoga().IsEnabled = true;
|
||||
subview.Yoga().FlexGrow = 1;
|
||||
container.AddSubview(subview);
|
||||
}
|
||||
container.Yoga().ApplyLayout();
|
||||
|
||||
Assert.False(CGRect.Intersect(container.Subviews[0].Frame, container.Subviews[1].Frame) == CGRect.Empty);
|
||||
Assert.False(CGRect.Intersect(container.Subviews[1].Frame, container.Subviews[2].Frame) == CGRect.Empty);
|
||||
Assert.False(CGRect.Intersect(container.Subviews[0].Frame, container.Subviews[2].Frame) == CGRect.Empty);
|
||||
|
||||
float totalWidth = 0;
|
||||
foreach (var view in container.Subviews)
|
||||
totalWidth += (float)view.Bounds.Size.Width;
|
||||
|
||||
Assert.AreEqual(containerSize.Width, totalWidth, $"The container's width is {containerSize.Width}, the subviews take up {totalWidth}");
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void TestThatLayoutIsCorrectWhenWeSwapViewOrder()
|
||||
{
|
||||
var containerSize = new SizeF(300, 50);
|
||||
|
||||
var container = new NativeView(new CGRect(0, 0, containerSize.Width, containerSize.Height));
|
||||
container.Yoga().IsEnabled = true;
|
||||
container.Yoga().FlexDirection = YogaFlexDirection.Row;
|
||||
|
||||
var subview1 = new NativeView();
|
||||
subview1.Yoga().IsEnabled = true;
|
||||
subview1.Yoga().FlexGrow = 1;
|
||||
container.AddSubview(subview1);
|
||||
|
||||
var subview2 = new NativeView();
|
||||
subview2.Yoga().IsEnabled = true;
|
||||
subview2.Yoga().FlexGrow = 1;
|
||||
container.AddSubview(subview2);
|
||||
|
||||
var subview3 = new NativeView();
|
||||
subview3.Yoga().IsEnabled = true;
|
||||
subview3.Yoga().FlexGrow = 1;
|
||||
container.AddSubview(subview3);
|
||||
|
||||
container.Yoga().ApplyLayout();
|
||||
|
||||
Assert.True(subview1.Frame == new CGRect(0, 0, 100, 50));
|
||||
Assert.True(subview2.Frame == new CGRect(100, 0, 100, 50), $"It's actually {subview2.Frame}");
|
||||
Assert.True(subview3.Frame == new CGRect(200, 0, 100, 50));
|
||||
|
||||
container.ExchangeSubview(2, 0);
|
||||
subview2.Yoga().IsIncludeInLayout = false;
|
||||
container.Yoga().ApplyLayout();
|
||||
|
||||
Assert.True(subview3.Frame == new CGRect(0, 0, 150, 50));
|
||||
Assert.True(subview1.Frame == new CGRect(150, 0, 150, 50));
|
||||
//// this frame shouldn't have been modified since last time.
|
||||
Assert.True(subview2.Frame == new CGRect(100, 0, 100, 50));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestThatWeRespectIncludeInLayoutFlag()
|
||||
{
|
||||
var containerSize = new SizeF(300, 50);
|
||||
|
||||
var container = new NativeView(new CGRect(0, 0, containerSize.Width, containerSize.Height));
|
||||
container.Yoga().IsEnabled = true;
|
||||
container.Yoga().FlexDirection = YogaFlexDirection.Row;
|
||||
|
||||
var subview1 = new NativeView();
|
||||
subview1.Yoga().IsEnabled = true;
|
||||
subview1.Yoga().FlexGrow = 1;
|
||||
container.AddSubview(subview1);
|
||||
|
||||
var subview2 = new NativeView();
|
||||
subview2.Yoga().IsEnabled = true;
|
||||
subview2.Yoga().FlexGrow = 1;
|
||||
container.AddSubview(subview2);
|
||||
|
||||
var subview3 = new NativeView();
|
||||
subview3.Yoga().IsEnabled = true;
|
||||
subview3.Yoga().FlexGrow = 1;
|
||||
container.AddSubview(subview3);
|
||||
|
||||
container.Yoga().ApplyLayout();
|
||||
|
||||
foreach (var view in container.Subviews)
|
||||
{
|
||||
Assert.True(new CGSize(100, 50) == view.Bounds.Size, $"Actual size is {view.Bounds.Size}");
|
||||
}
|
||||
|
||||
subview3.Yoga().IsIncludeInLayout = false;
|
||||
container.Yoga().ApplyLayout();
|
||||
Assert.True(subview1.Frame.Size == new CGSize(150, 50), $"Actual size is {subview1.Frame.Size}");
|
||||
Assert.True(subview2.Frame.Size == new CGSize(150, 50), $"Actual size is {subview2.Frame.Size}");
|
||||
//// We don't set the frame to zero, so, it should be set to what it was previously at.
|
||||
Assert.True(subview3.Frame.Size == new CGSize(100, 50), $"Actual size is {subview3.Frame.Size}");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestThatNumberOfChildrenIsCorrectWhenWeIgnoreSubviews()
|
||||
{
|
||||
var container = new NativeView();
|
||||
container.Yoga().IsEnabled = true;
|
||||
container.Yoga().FlexDirection = YogaFlexDirection.Row;
|
||||
|
||||
var subview1 = new NativeView();
|
||||
subview1.Yoga().IsEnabled = true;
|
||||
subview1.Yoga().IsIncludeInLayout = false;
|
||||
container.AddSubview(subview1);
|
||||
|
||||
var subview2 = new NativeView();
|
||||
subview2.Yoga().IsEnabled = true;
|
||||
subview2.Yoga().IsIncludeInLayout = false;
|
||||
container.AddSubview(subview2);
|
||||
|
||||
var subview3 = new NativeView();
|
||||
subview3.Yoga().IsEnabled = true;
|
||||
subview3.Yoga().IsIncludeInLayout = true;
|
||||
container.AddSubview(subview3);
|
||||
|
||||
container.Yoga().ApplyLayout();
|
||||
Assert.AreEqual(1, container.Yoga().NumberOfChildren);
|
||||
|
||||
subview2.Yoga().IsIncludeInLayout = true;
|
||||
container.Yoga().ApplyLayout();
|
||||
Assert.AreEqual(2, container.Yoga().NumberOfChildren);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestThatViewNotIncludedInFirstLayoutPassAreIncludedInSecond()
|
||||
{
|
||||
var containerSize = new SizeF(300, 50);
|
||||
|
||||
var container = new NativeView(new CGRect(0, 0, containerSize.Width, containerSize.Height));
|
||||
container.Yoga().IsEnabled = true;
|
||||
container.Yoga().FlexDirection = YogaFlexDirection.Row;
|
||||
|
||||
var subview1 = new NativeView();
|
||||
subview1.Yoga().IsEnabled = true;
|
||||
subview1.Yoga().FlexGrow = 1;
|
||||
container.AddSubview(subview1);
|
||||
|
||||
var subview2 = new NativeView();
|
||||
subview2.Yoga().IsEnabled = true;
|
||||
subview2.Yoga().FlexGrow = 1;
|
||||
container.AddSubview(subview2);
|
||||
|
||||
var subview3 = new NativeView();
|
||||
subview3.Yoga().IsEnabled = true;
|
||||
subview3.Yoga().FlexGrow = 1;
|
||||
subview3.Yoga().IsIncludeInLayout = false;
|
||||
container.AddSubview(subview3);
|
||||
|
||||
container.Yoga().ApplyLayout();
|
||||
|
||||
Assert.True(subview1.Frame.Size == new CGSize(150, 50), $"Actual size is {subview1.Frame.Size}");
|
||||
Assert.True(subview2.Frame.Size == new CGSize(150, 50), $"Actual size is {subview2.Frame.Size}");
|
||||
Assert.True(subview3.Frame.Size == CGSize.Empty, $"Actual size is {subview3.Frame.Size}");
|
||||
|
||||
subview3.Yoga().IsIncludeInLayout = true;
|
||||
container.Yoga().ApplyLayout();
|
||||
|
||||
foreach (var view in container.Subviews)
|
||||
{
|
||||
Assert.True(new CGSize(100, 50) == view.Bounds.Size, $"Actual size is {view.Bounds.Size}");
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestYogaIsLeafFlag()
|
||||
{
|
||||
var view = new NativeView();
|
||||
Assert.True(view.Yoga().IsLeaf);
|
||||
|
||||
for (int i = 0; i < 10; i++)
|
||||
{
|
||||
var subView = new NativeView();
|
||||
view.AddSubview(subView);
|
||||
}
|
||||
Assert.True(view.Yoga().IsLeaf);
|
||||
view.Yoga().IsEnabled = true;
|
||||
view.Yoga().Width = 50.0f;
|
||||
Assert.True(view.Yoga().IsLeaf);
|
||||
|
||||
var subView1 = view.Subviews[0];
|
||||
subView1.Yoga().IsEnabled = true;
|
||||
subView1.Yoga().Width = 50.0f;
|
||||
Assert.False(view.Yoga().IsLeaf);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestThatWeCorrectlyAttachNestedViews()
|
||||
{
|
||||
var containerSize = new SizeF(300, 50);
|
||||
|
||||
var container = new NativeView(new CGRect(0, 0, containerSize.Width, containerSize.Height));
|
||||
container.Yoga().IsEnabled = true;
|
||||
container.Yoga().FlexDirection = YogaFlexDirection.Column;
|
||||
|
||||
var subview1 = new NativeView();
|
||||
subview1.Yoga().IsEnabled = true;
|
||||
subview1.Yoga().Width = 100;
|
||||
subview1.Yoga().FlexGrow = 1;
|
||||
subview1.Yoga().FlexDirection = YogaFlexDirection.Column;
|
||||
container.AddSubview(subview1);
|
||||
|
||||
var subview2 = new NativeView();
|
||||
subview2.Yoga().IsEnabled = true;
|
||||
subview2.Yoga().Width = 150;
|
||||
subview2.Yoga().FlexGrow = 1;
|
||||
subview2.Yoga().FlexDirection = YogaFlexDirection.Column;
|
||||
container.AddSubview(subview2);
|
||||
|
||||
foreach (var view in new NativeView[] { subview1, subview2 })
|
||||
{
|
||||
var someView = new NativeView();
|
||||
someView.Yoga().IsEnabled = true;
|
||||
someView.Yoga().FlexGrow = 1;
|
||||
view.AddSubview(someView);
|
||||
}
|
||||
container.Yoga().ApplyLayout();
|
||||
|
||||
// Add the same amount of new views, reapply layout.
|
||||
foreach (var view in new NativeView[] { subview1, subview2 })
|
||||
{
|
||||
var someView = new NativeView();
|
||||
someView.Yoga().IsEnabled = true;
|
||||
someView.Yoga().FlexGrow = 1;
|
||||
view.AddSubview(someView);
|
||||
}
|
||||
container.Yoga().ApplyLayout();
|
||||
|
||||
Assert.True(new CGSize(100, 25) == subview1.Bounds.Size, $"Actual size is {subview1.Bounds.Size}");
|
||||
foreach (var subview in subview1.Subviews)
|
||||
{
|
||||
var subviewSize = subview.Bounds.Size;
|
||||
Assert.False(subviewSize.IsEmpty);
|
||||
Assert.False(nfloat.IsNaN(subviewSize.Height));
|
||||
Assert.False(nfloat.IsNaN(subviewSize.Width));
|
||||
}
|
||||
|
||||
Assert.True(new CGSize(150, 25) == subview2.Bounds.Size, $"Actual size is {subview2.Bounds.Size}");
|
||||
foreach (var subview in subview2.Subviews)
|
||||
{
|
||||
var subviewSize = subview.Bounds.Size;
|
||||
Assert.False(subviewSize.IsEmpty);
|
||||
Assert.False(nfloat.IsNaN(subviewSize.Height));
|
||||
Assert.False(nfloat.IsNaN(subviewSize.Width));
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestThatANonLeafNodeCanBecomeALeafNode()
|
||||
{
|
||||
var containerSize = new SizeF(300, 50);
|
||||
|
||||
var container = new NativeView(new CGRect(0, 0, containerSize.Width, containerSize.Height));
|
||||
container.Yoga().IsEnabled = true;
|
||||
|
||||
var subview1 = new NativeView();
|
||||
subview1.Yoga().IsEnabled = true;
|
||||
container.AddSubview(subview1);
|
||||
|
||||
var subview2 = new NativeView();
|
||||
subview2.Yoga().IsEnabled = true;
|
||||
container.AddSubview(subview2);
|
||||
container.Yoga().ApplyLayout();
|
||||
subview2.RemoveFromSuperview();
|
||||
container.Yoga().ApplyLayout();
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user