Skip to content

Commit

Permalink
Add new AddViews() and DoNotTranslateSubviewsAutoresizingMaskIntoCons…
Browse files Browse the repository at this point in the history
…traints() automatically in AddCosntraints() (#29)
  • Loading branch information
evgenyvalavin authored Aug 16, 2023
1 parent 0ba4f6c commit f73b4a3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
10 changes: 3 additions & 7 deletions src/iOS.Essentials/AutoLayout/FluentLayoutExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,12 @@
//
// Project Lead - Stuart Lodge, @slodge, [email protected]

using Arbus.iOS.Essentials.BasicViewExtensions;

namespace Arbus.iOS.Essentials.AutoLayout;

public static class FluentLayoutExtensions
{
[Obsolete("Use AddSubviewsForAutoLayout. The method is to be removed in the future.")]
public static void SubviewsDoNotTranslateAutoresizingMaskIntoConstraints(this UIView view)
{
foreach (var subview in view.Subviews)
subview.TranslatesAutoresizingMaskIntoConstraints = false;
}

public static UIViewAndLayoutAttribute Left(this UIView view) => view.WithLayoutAttribute(NSLayoutAttribute.Left);

public static UIViewAndLayoutAttribute Right(this UIView view) => view.WithLayoutAttribute(NSLayoutAttribute.Right);
Expand Down Expand Up @@ -56,6 +51,7 @@ public static T AddConstraints<T>(this T view, params FluentLayout[] fluentLayou

public static T AddConstraints<T>(this T view, IEnumerable<FluentLayout> fluentLayouts) where T : UIView
{
view.DoNotTranslateSubviewsAutoresizingMaskIntoConstraints();
view.AddConstraints(fluentLayouts
.Where(fluent => fluent != null)
.Select(fluent => fluent.Constraint.Value)
Expand Down
3 changes: 3 additions & 0 deletions src/iOS.Essentials/BasicViewExtensions/UIViewExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ public static T SetLayoutMargins<T>(this T view, nfloat top, nfloat left, nfloat
}

public static T AddSubviewsForAutoLayout<T>(this T view, params UIView[] value) where T : UIView
=> view.AddViews(value);

public static T AddViews<T>(this T view, params UIView[] value) where T : UIView
{
view.AddSubviews(value);
return view.DoNotTranslateSubviewsAutoresizingMaskIntoConstraints();
Expand Down

0 comments on commit f73b4a3

Please sign in to comment.