fix build, correctly size UIScrollViews
Summary: Closes https://github.com/facebook/yoga/pull/626 Reviewed By: emilsjolander Differential Revision: D5824425 Pulled By: splhack fbshipit-source-id: e1a8dda5e86e2705afa7f6630a6757491a94c6d6
This commit is contained in:
committed by
Facebook Github Bot
parent
bcc36cc1b2
commit
7217471427
@@ -595,12 +595,14 @@ namespace Facebook.Yoga
|
||||
Native.YGNodeSetBaselineFunc(_ygNode, _managedBaseline);
|
||||
}
|
||||
|
||||
public void CalculateLayout()
|
||||
public void CalculateLayout(
|
||||
float width = YogaConstants.Undefined,
|
||||
float height = YogaConstants.Undefined)
|
||||
{
|
||||
Native.YGNodeCalculateLayout(
|
||||
_ygNode,
|
||||
YogaConstants.Undefined,
|
||||
YogaConstants.Undefined,
|
||||
width,
|
||||
height,
|
||||
Native.YGNodeStyleGetDirection(_ygNode));
|
||||
}
|
||||
|
||||
|
@@ -4,6 +4,7 @@ using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
#if __IOS__
|
||||
using NativeView = UIKit.UIView;
|
||||
using NativeScrollView = UIKit.UIScrollView;
|
||||
#endif
|
||||
|
||||
namespace Facebook.YogaKit
|
||||
@@ -699,12 +700,12 @@ namespace Facebook.YogaKit
|
||||
{
|
||||
get
|
||||
{
|
||||
return _node.StyleAspectRatio;
|
||||
return _node.AspectRatio;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
_node.StyleAspectRatio = value;
|
||||
_node.AspectRatio = value;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -716,6 +717,17 @@ namespace Facebook.YogaKit
|
||||
float width = 0;
|
||||
float height = 0;
|
||||
GetWidthHeightOfNativeView(view, out width, out height);
|
||||
if (view is NativeScrollView)
|
||||
{
|
||||
if (FlexDirection == YogaFlexDirection.Column || FlexDirection == YogaFlexDirection.ColumnReverse)
|
||||
{
|
||||
height = float.NaN;
|
||||
}
|
||||
else
|
||||
{
|
||||
width = float.NaN;
|
||||
}
|
||||
}
|
||||
CalculateLayoutWithSize(this, width, height);
|
||||
ApplyLayoutToViewHierarchy(view);
|
||||
}
|
||||
@@ -743,9 +755,7 @@ namespace Facebook.YogaKit
|
||||
|
||||
var node = layout._node;
|
||||
|
||||
node.Width = width;
|
||||
node.Height = height;
|
||||
node.CalculateLayout();
|
||||
node.CalculateLayout(width, height);
|
||||
|
||||
return new SizeF { Width = node.LayoutWidth, Height = node.LayoutHeight };
|
||||
}
|
||||
@@ -775,14 +785,14 @@ namespace Facebook.YogaKit
|
||||
float result;
|
||||
if (measureMode == YogaMeasureMode.Exactly)
|
||||
{
|
||||
result = (float)constrainedSize;
|
||||
result = constrainedSize;
|
||||
}
|
||||
else if (measureMode == YogaMeasureMode.AtMost)
|
||||
{
|
||||
result = (float)Math.Min(constrainedSize, measuredSize);
|
||||
result = Math.Min(constrainedSize, measuredSize);
|
||||
}
|
||||
else {
|
||||
result = (float)measuredSize;
|
||||
result = measuredSize;
|
||||
}
|
||||
|
||||
return result;
|
||||
@@ -820,7 +830,7 @@ namespace Facebook.YogaKit
|
||||
var subviewsToInclude = new List<NativeView>();
|
||||
foreach (var subview in view.Subviews)
|
||||
{
|
||||
if (subview.Yoga().IsIncludeInLayout)
|
||||
if (subview.Yoga().IsEnabled && subview.Yoga().IsIncludeInLayout)
|
||||
{
|
||||
subviewsToInclude.Add(subview);
|
||||
}
|
||||
@@ -856,7 +866,7 @@ namespace Facebook.YogaKit
|
||||
|
||||
static double RoundPointValue(float value)
|
||||
{
|
||||
float scale = NativePointScale;
|
||||
float scale = NativePixelScale;
|
||||
|
||||
return Math.Round(value * scale) / scale;
|
||||
}
|
||||
|
@@ -22,8 +22,6 @@
|
||||
<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>
|
||||
@@ -39,8 +37,6 @@
|
||||
<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>
|
||||
@@ -56,8 +52,6 @@
|
||||
<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>
|
||||
@@ -76,8 +70,6 @@
|
||||
<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>
|
||||
@@ -102,6 +94,7 @@
|
||||
<ItemGroup>
|
||||
<Compile Include="Main.cs" />
|
||||
<Compile Include="UnitTestAppDelegate.cs" />
|
||||
<Compile Include="YogaKitNativeTest.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Facebook.YogaKit.iOS\Facebook.YogaKit.iOS.csproj">
|
||||
|
51
csharp/iOS/Facebook.YogaKit.iOS.Tests/YogaKitNativeTest.cs
Normal file
51
csharp/iOS/Facebook.YogaKit.iOS.Tests/YogaKitNativeTest.cs
Normal file
@@ -0,0 +1,51 @@
|
||||
using System.Drawing;
|
||||
using Facebook.Yoga;
|
||||
using NUnit.Framework;
|
||||
using System;
|
||||
using UIKit;
|
||||
using CoreGraphics;
|
||||
|
||||
namespace Facebook.YogaKit.iOS.Tests
|
||||
{
|
||||
[TestFixture]
|
||||
public class YogaKitNativeTest
|
||||
{
|
||||
[Test]
|
||||
public void ScrollViewVertical()
|
||||
{
|
||||
var view = new UIScrollView() {
|
||||
Frame = new CGRect(0, 0, 100, 100),
|
||||
};
|
||||
|
||||
view.Yoga().Overflow = YogaOverflow.Scroll;
|
||||
var subview = new UIView();
|
||||
subview.Yoga().Height = 1000;
|
||||
subview.Yoga().IsEnabled = true;
|
||||
|
||||
view.AddSubview(subview);
|
||||
view.Yoga().IsEnabled = true;
|
||||
view.Yoga().ApplyLayout();
|
||||
Assert.True(view.ContentSize.Height == 1000);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void NormalViewVertical()
|
||||
{
|
||||
var view = new UIView() {
|
||||
Frame = new CGRect(0,0, 100, 100),
|
||||
};
|
||||
|
||||
|
||||
var subview = new UIView();
|
||||
subview.Yoga().Height = 1000;
|
||||
subview.Yoga().Width = 2;
|
||||
subview.Yoga().IsEnabled = true;
|
||||
|
||||
view.AddSubview(subview);
|
||||
view.Yoga().IsEnabled = true;
|
||||
view.Yoga().ApplyLayout();
|
||||
Assert.True(view.Bounds.Height == 100);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@@ -23,14 +23,21 @@ namespace Facebook.YogaKit
|
||||
height = (float)view.Bounds.Height;
|
||||
}
|
||||
|
||||
static float NativePixelScale => (float)UIScreen.MainScreen.Scale;
|
||||
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(RoundPointValue((float)topLeft.X), RoundPointValue((float)topLeft.Y), RoundPointValue((float)bottomRight.X) - RoundPointValue((float)topLeft.X), RoundPointValue((float)bottomRight.Y) - RoundPointValue((float)topLeft.Y));
|
||||
if (view is UIScrollView scrollView)
|
||||
{
|
||||
scrollView.ContentSize = new CGSize(RoundPointValue((float)bottomRight.X) - RoundPointValue((float)topLeft.X), RoundPointValue((float)bottomRight.Y) - RoundPointValue((float)topLeft.Y));
|
||||
}
|
||||
else
|
||||
{
|
||||
view.Frame = new CGRect(RoundPointValue((float)topLeft.X), RoundPointValue((float)topLeft.Y), RoundPointValue((float)bottomRight.X) - RoundPointValue((float)topLeft.X), RoundPointValue((float)bottomRight.Y) - RoundPointValue((float)topLeft.Y));
|
||||
}
|
||||
}
|
||||
|
||||
bool _disposed;
|
||||
|
Reference in New Issue
Block a user