Summary: ...to reflect the modern world we live in with dynamic DPI platforms :) Closes https://github.com/facebook/yoga/pull/375 Reviewed By: dshahidehpour Differential Revision: D4528518 Pulled By: emilsjolander fbshipit-source-id: e422bd4ae148e02c598a7b484a6adfa8c0e1e0c9
53 lines
1.6 KiB
C#
53 lines
1.6 KiB
C#
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(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;
|
|
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);
|
|
}
|
|
}
|
|
}
|