Skip to content

Commit 091d0e8

Browse files
kubafloPureWeen
authored andcommitted
[iOS] Shell/NavigationPage TitleView
Replaces the custom CalculateUIEdgeInsets method with an override of AlignmentRectInsets that leverages the IView.Margin property. This ensures the alignment insets reflect the view’s actual margins, allowing developers to align the TitleView directly with the screen edges.
1 parent 336be4b commit 091d0e8

File tree

1 file changed

+11
-22
lines changed

1 file changed

+11
-22
lines changed

src/Controls/src/Core/Compatibility/Handlers/NavigationPage/iOS/NavigationRenderer.cs

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1946,31 +1946,20 @@ public Container(View view, UINavigationBar bar) : base(bar.Bounds)
19461946
ClipsToBounds = true;
19471947
}
19481948

1949-
UIEdgeInsets CalculateUIEdgeInsets()
1949+
public override UIEdgeInsets AlignmentRectInsets
19501950
{
1951-
var type = UIBarButtonSystemItem.FixedSpace;
1952-
var spacer = new UIBarButtonItem(type, (_, _) => { });
1953-
spacer.Width = SystemMargin + (OperatingSystem.IsIOSVersionAtLeast(11) ? 8 : -16);
1954-
1955-
nfloat screenWidth = UIScreen.MainScreen.Bounds.Size.Width;
1956-
1957-
if (!OperatingSystem.IsIOSVersionAtLeast(11) && screenWidth < 375)
1958-
{
1959-
// 3.5 and 4 inch
1960-
spacer.Width += 8;
1961-
}
1962-
else if (screenWidth >= 414)
1951+
get
19631952
{
1964-
// 5.5 inch
1965-
spacer.Width -= 4;
1953+
if (_child?.VirtualView is IView view)
1954+
{
1955+
var margin = view.Margin;
1956+
return new UIEdgeInsets(-(nfloat)margin.Top, -(nfloat)margin.Left, -(nfloat)margin.Bottom, -(nfloat)margin.Right);
1957+
}
1958+
else
1959+
{
1960+
return base.AlignmentRectInsets;
1961+
}
19661962
}
1967-
1968-
return new UIEdgeInsets(0, spacer.Width, 0, spacer.Width);
1969-
}
1970-
1971-
public override UIEdgeInsets AlignmentRectInsets
1972-
{
1973-
get => CalculateUIEdgeInsets();
19741963
}
19751964

19761965
void OnTitleViewParentSet(object sender, EventArgs e)

0 commit comments

Comments
 (0)