Beispiel #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);
        }
Beispiel #2
0
 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);
 }
Beispiel #3
0
        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);
                }
            }
        }
Beispiel #4
0
        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]);
                }
            }
        }
Beispiel #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
            });
        }