FluentLayout / Cirrious.FluentLayout

FluentLayout for Xamarin.iOS - sample uses MvvmCross
Microsoft Public License
149 stars 54 forks source link

Filter null constraints in AddConstraints() #3

Closed RocketPop closed 10 years ago

RocketPop commented 10 years ago

I often find I have optional constraints (left vs right anchoring, size switches, optional UI elements, etc.) Especially in table view cells. I changed the above code to allow me to write layouts like so:

        View.AddConstraints(
            viewHasHeader ? TableViewControl.Below(HeaderContainerView) : null,
            TableViewControl.AtLeftOf(View),
            TableViewControl.AtRightOf(View),
            TableViewControl.AtBottomOf(View)
        );

This change is so I don't have to have lists of optional constraints (i.e. separate calls to AddConstraints() ) after the core set of constraints - that are then separated by many lines of code and if blocks. I was also debating adding my own custom constraints - which when they were not needed would return null. Something like BelowIfExists(this UIView view, UIView previous, float margin = 0f)

Not sure if the allowing of nulls in lists of constraints fits the rest of the design though :)

slodge commented 10 years ago

Thanks :)