示例#1
0
        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);
        }
示例#2
0
文件: YogaLayout.cs 项目: zmjios/yoga
 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);
 }
示例#3
0
文件: YogaLayout.cs 项目: zmjios/yoga
        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);
                }
            }
        }
示例#4
0
文件: YogaLayout.cs 项目: zmjios/yoga
        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]);
                }
            }
        }
示例#5
0
        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.CalculateLayout(width, height);

            return(new SizeF {
                Width = node.LayoutWidth, Height = node.LayoutHeight
            });
        }