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
44 lines
1.1 KiB
C#
44 lines
1.1 KiB
C#
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,
|
|
}
|
|
}
|
|
}
|