Closed softlion closed 5 years ago
Interesting suggestion! I don't love the need for object
in the API versus finding a way for it to be a bit more well defined (though I understand the signature collision between IEnumerable<FluentLayout>
and FluentLayout[]
there, certainly). I'm wondering if it's worth just using a different set of method names to support this if we want to roll forward with it. Thoughts?
Also .ToLayoutConstraints()
is obsolete - is it actually needed here?
It is because you want to obsolete ToLayoutConstraints for obscure reasons that I have to open source my private code.
Not sure I'd call it obscure, but either way I'm asking/curious what it's actually needed for here? 😄
ToLayoutConstraints is to extract the built constraints for any fluentLayout object of type FluentLayout, as view.AddConstraints only supports iOS contraints objects.
Closing this out for now since we wouldn't be able to move ahead with this as-is and it sounds like you've got a custom fork anyway, but more than happy to continue to explore this if it still seems like you'd want to use/contribute - thanks! 😄
Sample usage of "object" parameter (can't use any other one):
public static UIView AddConstraints(this UIView view, params object[] fluentLayouts)
{
view.AddConstraints((fluentLayouts
.Where(fluent => fluent != null)
.OfType<FluentLayout>()
#pragma warning disable 618
.SelectMany(fluent => fluent.ToLayoutConstraints())
#pragma warning restore 618
).Concat(fluentLayouts
.OfType<IEnumerable<FluentLayout>>()
#pragma warning disable 618
.SelectMany(fluent => fluent.SelectMany(fluent2 => fluent2.ToLayoutConstraints()))
#pragma warning restore 618
).ToArray());
return view;
}
public static UIView AddConstraints(this UIView view, params Func<UIView, object>[] fluentLayoutActions)
{
var fluentLayouts = fluentLayoutActions.Select(fl => fl(view)).ToList();
view.AddConstraints((fluentLayouts
.Where(fluent => fluent != null)
.OfType<FluentLayout>()
#pragma warning disable 618
.SelectMany(fluent => fluent.ToLayoutConstraints())
#pragma warning restore 618
).Concat(fluentLayouts
.OfType<IEnumerable<FluentLayout>>()
#pragma warning disable 618
.SelectMany(fluent => fluent.SelectMany(fluent2 => fluent2.ToLayoutConstraints()))
#pragma warning restore 618
).ToArray());
return view;
}
public static IEnumerable<FluentLayout> WithSameCenter(this UIView view, UIView previous)
{
yield return view.WithSameCenterX(previous);
yield return view.WithSameCenterY(previous);
}
I don't have a custom fork
Could you add this method ?
It extends the existing method to accept both
FuentLayout
andIEnumerable<FluentLayout>
Usage:
Example:
Source
Other examples: