FluentLayout / Cirrious.FluentLayout

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

Usage of ToLayoutConstraints #32

Closed softlion closed 5 years ago

softlion commented 8 years ago

This version of AddConstraints permits the use of both simple and advanced constraints in the same call. If you remove ToLayoutConstraints it will not work anymore.

Advanced constraints methods use more than one Constraint object to achieve the result.

        public static void AddConstraints(this UIView view, params object[] fluentLayouts)
        {
            view.AddConstraints((fluentLayouts
                .Where(fluent => fluent != null)
                .OfType<FluentLayout>()
                .SelectMany(fluent => fluent.ToLayoutConstraints())
                ).Concat(fluentLayouts
                    .OfType<IEnumerable<FluentLayout>>()
                    .SelectMany(fluent => fluent.SelectMany(fluent2 => fluent2.ToLayoutConstraints()))
                ).ToArray());
        }

        public static IEnumerable<FluentLayout> WithSameRectOf(this UIView view, UIView parent, nfloat? margin = null)
        {
            return
                view.FullWidthOf(parent, margin)
                    .Concat(view.FullHeightOf(parent, margin))
                    .Concat(view.AtTopLeftOf(parent, margin));
        }

Sample usage:

ContentView.AddConstraints(
                title.AtLeftOf(ContentView, 2.5f),
                title.AtTopOf(ContentView, ItemSize.Width + 2.5f),
                image.WithSameRectOf(imageSvg)
                );

Without this extension methods, WithSameRectOf can not be used.

softlion commented 8 years ago

So what do you think ? The project is left alone again for 2 years ?

gshackles commented 8 years ago

I'm not sure I see that as being a good reason to keep ToLayoutConstraints as a public available method. If anything, we can try to enhance the API to allow for making it easier to add constraints like this without requiring separate calls.

softlion commented 8 years ago

we can try to enhance the API

Yes include this AddConstraints method directly !

softlion commented 7 years ago

So no update ? Should i publish my own nuget ? Oh i already use my own one since 2 years :D

Cheesebaron commented 7 years ago

I'd suggest, instead of adding non-constructive comments, that you made a PR so your own changes could be merged in upstream. If you don't want to do that keep using your own stuff.

softlion commented 7 years ago

I was waiting for an update from repo's owners before deciding what to do. So instead of flaming me with your hard temper, just answer that you like the idea and need a pr ... Now i know you are awake and not dead.

Cheesebaron commented 7 years ago

I don't own this repository.

My temper is not hard, you seem to have misinterpreted my comment. Maybe it hit a sore point?

I personally have no use for this extension and I can't see any good use cases for this. However, I cannot rule out that there are valid ones. So my suggestion is still to make a PR, with enough information to back it up for it to be included upstream. This information could be a valid sample which shows why it is useful.

gshackles commented 7 years ago

Sorry to let this one sit for so long, been heads down in a variety of other things lately that have kept me busy elsewhere. If you have a proposal for what a good API for this could look like that doesn't require ToLayoutConstraints, I'm certainly open to it!

gshackles commented 5 years ago

Closing this for now since it's been dormant, happy to pick up conversations again in the future!

softlion commented 5 years ago

It is dormant until you really remove the code. If you remove it i will wake it up fast!!!