Permalink
Browse files

[Core] Add FlexLayout

  • Loading branch information...
rmarinho committed Feb 15, 2017
1 parent f0711c6 commit 1a6035d739ed6a00974977d0748efb760a70b2c5
Showing with 3,542 additions and 0 deletions.
  1. +9 −0 .nuget/NuGet.Config
  2. +387 −0 FlexLayout.sln
  3. +16 −0 Xamarin.Forms.FlexLayout/Xamarin.FlexLayout/Align.cs
  4. +14 −0 Xamarin.Forms.FlexLayout/Xamarin.FlexLayout/FlexDirection.cs
  5. +151 −0 Xamarin.Forms.FlexLayout/Xamarin.FlexLayout/FlexLayout.cs
  6. +17 −0 Xamarin.Forms.FlexLayout/Xamarin.FlexLayout/FlexLayoutEngine.cs
  7. +41 −0 Xamarin.Forms.FlexLayout/Xamarin.FlexLayout/FlexLayoutExtensions.cs
  8. +50 −0 Xamarin.Forms.FlexLayout/Xamarin.FlexLayout/IFlexNode.cs
  9. +15 −0 Xamarin.Forms.FlexLayout/Xamarin.FlexLayout/Justify.cs
  10. +8 −0 Xamarin.Forms.FlexLayout/Xamarin.FlexLayout/MeasureFunc.cs
  11. +9 −0 Xamarin.Forms.FlexLayout/Xamarin.FlexLayout/MeasureMode.cs
  12. +13 −0 Xamarin.Forms.FlexLayout/Xamarin.FlexLayout/Overflow.cs
  13. +12 −0 Xamarin.Forms.FlexLayout/Xamarin.FlexLayout/Position.cs
  14. +12 −0 Xamarin.Forms.FlexLayout/Xamarin.FlexLayout/Wrap.cs
  15. +13 −0 Xamarin.Forms.FlexLayout/Xamarin.FlexLayout/Xamarin.FlexLayout.Shared.shproj
  16. +25 −0 Xamarin.Forms.FlexLayout/Xamarin.FlexLayout/Xamarin.FlexLayout.projitems
  17. +67 −0 ...Forms.FlexLayout.Engine/Xamarin.Forms.FlexLayout.Engine.Yoga/Xamarin.FlexLayoutEngine.Yoga.csproj
  18. +324 −0 ...rms.FlexLayout/Xamarin.Forms.FlexLayout.Engine/Xamarin.Forms.FlexLayout.Engine.Yoga/YogaEngine.cs
  19. +4 −0 ...s.FlexLayout/Xamarin.Forms.FlexLayout.Engine/Xamarin.Forms.FlexLayout.Engine.Yoga/packages.config
  20. +323 −0 Xamarin.Forms.FlexLayout/Xamarin.Forms.FlexLayout/Xamarin.Forms.FlexLayout.cs
  21. +52 −0 Xamarin.Forms.FlexLayout/Xamarin.Forms.FlexLayout/Xamarin.Forms.FlexLayout.csproj
  22. +9 −0 Xamarin.Forms.FlexLayout/Xamarin.Forms.FlexLayout/Xamarin.Forms.FlexLayout.nuget.targets
  23. +10 −0 Xamarin.Forms.FlexLayout/Xamarin.Forms.FlexLayout/project.json
  24. +72 −0 Xamarin.Forms.sln
  25. +19 −0 samples/FormsFlexLayoutDemo/FormsFlexLayoutDemo.Droid/Assets/AboutAssets.txt
  26. +172 −0 samples/FormsFlexLayoutDemo/FormsFlexLayoutDemo.Droid/FormsFlexLayoutDemo.Droid.csproj
  27. +32 −0 samples/FormsFlexLayoutDemo/FormsFlexLayoutDemo.Droid/MainActivity.cs
  28. +5 −0 samples/FormsFlexLayoutDemo/FormsFlexLayoutDemo.Droid/Properties/AndroidManifest.xml
  29. +34 −0 samples/FormsFlexLayoutDemo/FormsFlexLayoutDemo.Droid/Properties/AssemblyInfo.cs
  30. BIN samples/FormsFlexLayoutDemo/FormsFlexLayoutDemo.Droid/Resources/drawable-hdpi/icon.png
  31. BIN samples/FormsFlexLayoutDemo/FormsFlexLayoutDemo.Droid/Resources/drawable-xhdpi/icon.png
  32. BIN samples/FormsFlexLayoutDemo/FormsFlexLayoutDemo.Droid/Resources/drawable-xxhdpi/icon.png
  33. BIN samples/FormsFlexLayoutDemo/FormsFlexLayoutDemo.Droid/Resources/drawable/icon.png
  34. +11 −0 samples/FormsFlexLayoutDemo/FormsFlexLayoutDemo.Droid/Resources/layout/Tabbar.axml
  35. +8 −0 samples/FormsFlexLayoutDemo/FormsFlexLayoutDemo.Droid/Resources/layout/Toolbar.axml
  36. +38 −0 samples/FormsFlexLayoutDemo/FormsFlexLayoutDemo.Droid/Resources/values/styles.xml
  37. +13 −0 samples/FormsFlexLayoutDemo/FormsFlexLayoutDemo.Droid/packages.config
  38. +8 −0 samples/FormsFlexLayoutDemo/FormsFlexLayoutDemo.UWP/App.xaml
  39. +106 −0 samples/FormsFlexLayoutDemo/FormsFlexLayoutDemo.UWP/App.xaml.cs
  40. BIN samples/FormsFlexLayoutDemo/FormsFlexLayoutDemo.UWP/Assets/LockScreenLogo.scale-200.png
  41. BIN samples/FormsFlexLayoutDemo/FormsFlexLayoutDemo.UWP/Assets/SplashScreen.scale-200.png
  42. BIN samples/FormsFlexLayoutDemo/FormsFlexLayoutDemo.UWP/Assets/Square150x150Logo.scale-200.png
  43. BIN samples/FormsFlexLayoutDemo/FormsFlexLayoutDemo.UWP/Assets/Square44x44Logo.scale-200.png
  44. BIN ...sFlexLayoutDemo/FormsFlexLayoutDemo.UWP/Assets/Square44x44Logo.targetsize-24_altform-unplated.png
  45. BIN samples/FormsFlexLayoutDemo/FormsFlexLayoutDemo.UWP/Assets/StoreLogo.png
  46. BIN samples/FormsFlexLayoutDemo/FormsFlexLayoutDemo.UWP/Assets/Wide310x150Logo.scale-200.png
  47. +154 −0 samples/FormsFlexLayoutDemo/FormsFlexLayoutDemo.UWP/FormsFlexLayoutDemo.UWP.csproj
  48. +10 −0 samples/FormsFlexLayoutDemo/FormsFlexLayoutDemo.UWP/FormsFlexLayoutDemo.UWP.nuget.targets
  49. BIN samples/FormsFlexLayoutDemo/FormsFlexLayoutDemo.UWP/FormsFlexLayoutDemo.UWP_TemporaryKey.pfx
  50. +11 −0 samples/FormsFlexLayoutDemo/FormsFlexLayoutDemo.UWP/MainPage.xaml
  51. +40 −0 samples/FormsFlexLayoutDemo/FormsFlexLayoutDemo.UWP/MainPage.xaml.cs
  52. +49 −0 samples/FormsFlexLayoutDemo/FormsFlexLayoutDemo.UWP/Package.appxmanifest
  53. +29 −0 samples/FormsFlexLayoutDemo/FormsFlexLayoutDemo.UWP/Properties/AssemblyInfo.cs
  54. +31 −0 samples/FormsFlexLayoutDemo/FormsFlexLayoutDemo.UWP/Properties/Default.rd.xml
  55. +15 −0 samples/FormsFlexLayoutDemo/FormsFlexLayoutDemo.UWP/project.json
  56. +34 −0 samples/FormsFlexLayoutDemo/FormsFlexLayoutDemo.iOS/AppDelegate.cs
  57. +5 −0 samples/FormsFlexLayoutDemo/FormsFlexLayoutDemo.iOS/Entitlements.plist
  58. +198 −0 samples/FormsFlexLayoutDemo/FormsFlexLayoutDemo.iOS/FormsFlexLayoutDemo.iOS.csproj
  59. +52 −0 samples/FormsFlexLayoutDemo/FormsFlexLayoutDemo.iOS/Info.plist
  60. +20 −0 samples/FormsFlexLayoutDemo/FormsFlexLayoutDemo.iOS/Main.cs
  61. +36 −0 samples/FormsFlexLayoutDemo/FormsFlexLayoutDemo.iOS/Properties/AssemblyInfo.cs
  62. BIN samples/FormsFlexLayoutDemo/FormsFlexLayoutDemo.iOS/Resources/Default-568h@2x.png
  63. BIN samples/FormsFlexLayoutDemo/FormsFlexLayoutDemo.iOS/Resources/Default-Portrait.png
  64. BIN samples/FormsFlexLayoutDemo/FormsFlexLayoutDemo.iOS/Resources/Default-Portrait@2x.png
  65. BIN samples/FormsFlexLayoutDemo/FormsFlexLayoutDemo.iOS/Resources/Default.png
  66. BIN samples/FormsFlexLayoutDemo/FormsFlexLayoutDemo.iOS/Resources/Default@2x.png
  67. BIN samples/FormsFlexLayoutDemo/FormsFlexLayoutDemo.iOS/Resources/Icon-60@2x.png
  68. BIN samples/FormsFlexLayoutDemo/FormsFlexLayoutDemo.iOS/Resources/Icon-60@3x.png
  69. BIN samples/FormsFlexLayoutDemo/FormsFlexLayoutDemo.iOS/Resources/Icon-76.png
  70. BIN samples/FormsFlexLayoutDemo/FormsFlexLayoutDemo.iOS/Resources/Icon-76@2x.png
  71. BIN samples/FormsFlexLayoutDemo/FormsFlexLayoutDemo.iOS/Resources/Icon-Small-40.png
  72. BIN samples/FormsFlexLayoutDemo/FormsFlexLayoutDemo.iOS/Resources/Icon-Small-40@2x.png
  73. BIN samples/FormsFlexLayoutDemo/FormsFlexLayoutDemo.iOS/Resources/Icon-Small-40@3x.png
  74. BIN samples/FormsFlexLayoutDemo/FormsFlexLayoutDemo.iOS/Resources/Icon-Small.png
  75. BIN samples/FormsFlexLayoutDemo/FormsFlexLayoutDemo.iOS/Resources/Icon-Small@2x.png
  76. BIN samples/FormsFlexLayoutDemo/FormsFlexLayoutDemo.iOS/Resources/Icon-Small@3x.png
  77. +39 −0 samples/FormsFlexLayoutDemo/FormsFlexLayoutDemo.iOS/Resources/LaunchScreen.storyboard
  78. BIN samples/FormsFlexLayoutDemo/FormsFlexLayoutDemo.iOS/iTunesArtwork
  79. BIN samples/FormsFlexLayoutDemo/FormsFlexLayoutDemo.iOS/iTunesArtwork@2x
  80. +5 −0 samples/FormsFlexLayoutDemo/FormsFlexLayoutDemo.iOS/packages.config
  81. +33 −0 samples/FormsFlexLayoutDemo/FormsFlexLayoutDemo/App.cs
  82. +103 −0 samples/FormsFlexLayoutDemo/FormsFlexLayoutDemo/FormsFlexLayoutDemo.csproj
  83. +53 −0 samples/FormsFlexLayoutDemo/FormsFlexLayoutDemo/Pages/FlexDemoFromCodePage.cs
  84. +41 −0 samples/FormsFlexLayoutDemo/FormsFlexLayoutDemo/Pages/FlexDemoPage.xaml
  85. +66 −0 samples/FormsFlexLayoutDemo/FormsFlexLayoutDemo/Pages/FlexDemoPage.xaml.cs
  86. +60 −0 samples/FormsFlexLayoutDemo/FormsFlexLayoutDemo/Pages/FlexOptionsPage.xaml
  87. +12 −0 samples/FormsFlexLayoutDemo/FormsFlexLayoutDemo/Pages/FlexOptionsPagexaml.cs
  88. +30 −0 samples/FormsFlexLayoutDemo/FormsFlexLayoutDemo/Properties/AssemblyInfo.cs
  89. +15 −0 samples/FormsFlexLayoutDemo/FormsFlexLayoutDemo/ViewModel/BaseViewModel.cs
  90. +90 −0 samples/FormsFlexLayoutDemo/FormsFlexLayoutDemo/ViewModel/FlexItemViewModel.cs
  91. +163 −0 samples/FormsFlexLayoutDemo/FormsFlexLayoutDemo/ViewModel/FlexLayoutViewModel.cs
  92. +26 −0 samples/FormsFlexLayoutDemo/FormsFlexLayoutDemo/Views/FlexItemView.xaml
  93. +19 −0 samples/FormsFlexLayoutDemo/FormsFlexLayoutDemo/Views/FlexItemView.xaml.cs
  94. +4 −0 samples/FormsFlexLayoutDemo/FormsFlexLayoutDemo/packages.config
View
@@ -3,4 +3,13 @@
<solution>
<add key="disableSourceControlIntegration" value="true" />
</solution>
<packageSources>
<add key="XFCI" value="https://www.myget.org/F/xamarinforms-ci/api/v2/" />
<add key="Nuget" value="https://api.nuget.org/v3/index.json" />
<add key="nuget.org" value="https://www.nuget.org/api/v2/" />
<add key="YOGACI" value="https://www.myget.org/F/yoga/api/v3/index.json" />
</packageSources>
<activePackageSource>
<add key="All" value="(Aggregate source)" />
</activePackageSource>
</configuration>
View

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -0,0 +1,16 @@
#if FORMS
namespace Xamarin.Forms
#else
namespace Xamarin.FlexLayout
#endif
{
public enum Align
{
Auto,
FlexStart,
Center,
FlexEnd,
Stretch,
Baseline
}
}
@@ -0,0 +1,14 @@
#if FORMS
namespace Xamarin.Forms.Flex
#else
namespace Xamarin.FlexLayout
#endif
{
public enum FlexDirection
{
Column,
ColumnReverse,
Row,
RowReverse
}
}
@@ -0,0 +1,151 @@
using System;
using System.ComponentModel;
using System.Linq;
#if FORMS
using NativeView = Xamarin.Forms.View;
namespace Xamarin.Forms
#else
namespace Xamarin.FlexLayout
#endif
{
public partial class FlexLayout
{
const string _FlexOrderPropertyName = "Order";
const string _FlexPropertyName = "Flex";
const string _FlexGrowPropertyName = "Grow";
const string _FlexShrinkPropertyName = "Shrink";
const string _FlexBasisPropertyName = "Basis";
const string _FlexAlignSelfPropertyName = "AlignSelf";
const string _FlexIsIncludedPropertyName = "IsIncluded";
const string _FlexNodePropertyName = "Node";
IFlexNode _root;
public FlexLayout()
{
InitNode();
}
public void ApplyLayout(double x, double y, double width, double height)
{
_root.Left = (float)x;
_root.Top = (float)y;
AttachNodesFromViewHierachy(this);
CalculateLayoutWithSize((float)width, (float)height);
ApplyLayoutToViewHierarchy(this);
}
static float SanitizeMeasurement(float constrainedSize, float measuredSize, FlexMeasureMode measureMode)
{
float result;
if (measureMode == FlexMeasureMode.Exactly)
{
result = constrainedSize;
}
else if (measureMode == FlexMeasureMode.AtMost)
{
result = Math.Min(constrainedSize, measuredSize);
}
else
{
result = measuredSize;
}
return result;
}
static void ApplyLayoutToViewHierarchy(NativeView view)
{
if (!GetIsIncluded(view))
return;
var node = GetNode(view);
if (!(view is FlexLayout))
ApplyLayoutToNativeView(view, node);
if (view.IsLeaf())
return;
foreach (var subView in FlexLayoutExtensions.GetChildren(view))
ApplyLayoutToViewHierarchy(subView);
}
static bool NodeHasExactSameChildren(IFlexNode node, NativeView[] subviews)
{
if (node.Count() != subviews.Length)
return false;
for (int i = 0; i < subviews.Length; i++)
{
var childNode = GetNode(subviews[i]);
if (node.ElementAt(i) != childNode)
{
return false;
}
}
return true;
}
protected virtual IFlexNode InitNode()
{
_root = GetNewFlexNode();
SetNode(this, _root);
FlexLayoutExtensions.Bridges.Add(_root, this);
UpdateRootNode();
return _root;
}
void RegisterChild(NativeView view)
{
IFlexNode node = GetNewFlexNode();
SetNode(view, node);
FlexLayoutExtensions.Bridges.Add(node, view);
var viewINPC = view as INotifyPropertyChanged;
if (viewINPC != null)
viewINPC.PropertyChanged += ChildPropertyChanged;
}
void UnregisterChild(NativeView view)
{
var node = GetNode(view);
SetNode(view, null);
FlexLayoutExtensions.Bridges.Remove(node);
var viewINPC = view as INotifyPropertyChanged;
if (viewINPC != null)
viewINPC.PropertyChanged -= ChildPropertyChanged;
}
void ChildPropertyChanged(object sender, PropertyChangedEventArgs e)
{
UpdateNode(this, sender, e.PropertyName);
}
void CalculateLayoutWithSize(float width, float height)
{
var node = _root;
node.Width = width;
node.Height = height;
node.CalculateLayout();
}
private static Type _engineType;
IFlexNode GetNewFlexNode()
{
if (_engineType == null)
throw new InvalidOperationException("You must call FlexLayout.RegisterEngine");
var instance = Activator.CreateInstance(_engineType);
return instance as IFlexNode;
}
public static void RegisterEngine(Type engineType)
{
_engineType = engineType;
}
}
}
@@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Text;
#if FORMS
namespace Xamarin.Forms
#else
namespace Xamarin.FlexLayout
#endif
{
public class FlexLayoutEngine
{
public static void SetEngine()
{
}
}
}
@@ -0,0 +1,41 @@
using System.Collections.Generic;
#if FORMS
using NativeView = Xamarin.Forms.View;
namespace Xamarin.Forms
#else
namespace Xamarin.FlexLayout
#endif
{
internal static class FlexLayoutExtensions
{
internal static Dictionary<IFlexNode, NativeView> Bridges = new Dictionary<IFlexNode, NativeView>();
public static bool IsLeaf(this NativeView view)
{
if (view.IsEnabled)
{
foreach (NativeView subview in GetChildren(view))
{
if (subview.IsEnabled && FlexLayout.GetIsIncluded(subview))
{
return false;
}
}
}
return true;
}
public static IEnumerable<NativeView> GetChildren(NativeView view)
{
var result = new List<NativeView>();
if (view is Xamarin.Forms.Layout<Xamarin.Forms.View>)
{
result.AddRange((view as Xamarin.Forms.Layout<Xamarin.Forms.View>).Children);
}
return result;
}
}
}
@@ -0,0 +1,50 @@
using System;
using System.Collections;
using System.Collections.Generic;
#if FORMS
using Xamarin.Forms.Flex;
namespace Xamarin.Forms
#else
namespace Xamarin.FlexLayout
#endif
{
public interface IFlexNode : IEnumerable<IFlexNode>
{
bool IsDirty { get; }
float LayoutTop { get; }
float LayoutLeft { get; }
float LayoutHeight { get; }
float LayoutWidth { get; }
float Top { get; set; }
float Height { get; set; }
float Left { get; set; }
float Width { get; set; }
float Flex { get; set; }
float FlexGrow { get; set; }
float FlexShrink { get; set; }
float FlexBasis { get; set; }
Position PositionType { get; set; }
Align AlignItems { get; set; }
Align AlignSelf { get; set; }
Align AlignContent { get; set; }
Wrap Wrap { get; set; }
Overflow Overflow { get; set; }
Justify JustifyContent { get; set; }
FlexDirection FlexDirection { get; set; }
float MarginLeft { get; set; }
float MarginTop { get; set; }
float MarginRight { get; set; }
float MarginBottom { get; set; }
float MinHeight { get; set; }
float MinWidth { get; set; }
void CalculateLayout();
void Clear();
void Insert(int i, IFlexNode subViewNode);
void SetMeasure(MeasureFunc measureView);
void MarkDirty();
}
}
@@ -0,0 +1,15 @@
#if FORMS
namespace Xamarin.Forms.Flex
#else
namespace Xamarin.FlexLayout
#endif
{
public enum Justify
{
FlexStart,
Center,
FlexEnd,
SpaceBetween,
SpaceAround
}
}
@@ -0,0 +1,8 @@
#if FORMS
namespace Xamarin.Forms.Flex
#else
namespace Xamarin.FlexLayout
#endif
{
public delegate object MeasureFunc(IFlexNode node, float width, FlexMeasureMode widthMode, float height, FlexMeasureMode heightMode);
}
@@ -0,0 +1,9 @@
namespace Xamarin.Forms
{
public enum FlexMeasureMode
{
None,
Exactly,
AtMost,
}
}
@@ -0,0 +1,13 @@
#if FORMS
namespace Xamarin.Forms.Flex
#else
namespace Xamarin.FlexLayout
#endif
{
public enum Overflow
{
Visible,
Hidden,
Scroll
}
}
@@ -0,0 +1,12 @@
#if FORMS
namespace Xamarin.Forms.Flex
#else
namespace Xamarin.FlexLayout
#endif
{
public enum Position
{
Relative,
Absolute
}
}
@@ -0,0 +1,12 @@
#if FORMS
namespace Xamarin.Forms.Flex
#else
namespace Xamarin.FlexLayout
#endif
{
public enum Wrap
{
NoWrap,
Wrap
}
}
Oops, something went wrong.

0 comments on commit 1a6035d

Please sign in to comment.