Skip to content

Commit

Permalink
[iOS/MacCatalyst] Fix Editor scrolling (#13234)
Browse files Browse the repository at this point in the history
* [iOS] Don't update the offset if there's no space available

* [iOS] Use the MauiLabel to set a label with insets

Using the constrains was keeping the UITextView from scrolling
  • Loading branch information
rmarinho authored Feb 16, 2023
1 parent 2a15957 commit f6d8e15
Showing 1 changed file with 6 additions and 19 deletions.
25 changes: 6 additions & 19 deletions src/Core/src/Platform/iOS/MauiTextView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public override void LayoutSubviews()

UILabel InitPlaceholderLabel()
{
var placeholderLabel = new UILabel
var placeholderLabel = new MauiLabel
{
BackgroundColor = UIColor.Clear,
TextColor = ColorExtensions.PlaceholderColor,
Expand All @@ -129,23 +129,8 @@ UILabel InitPlaceholderLabel()
var edgeInsets = TextContainerInset;
var lineFragmentPadding = TextContainer.LineFragmentPadding;

var vConstraints = NSLayoutConstraint.FromVisualFormat(
"V:|-" + edgeInsets.Top + "-[PlaceholderLabel]-" + edgeInsets.Bottom + "-|", 0, new NSDictionary(),
NSDictionary.FromObjectsAndKeys(
new NSObject[] { placeholderLabel }, new NSObject[] { new NSString("PlaceholderLabel") })
);

var hConstraints = NSLayoutConstraint.FromVisualFormat(
"H:|-" + lineFragmentPadding + "-[PlaceholderLabel]-" + lineFragmentPadding + "-|",
0, new NSDictionary(),
NSDictionary.FromObjectsAndKeys(
new NSObject[] { placeholderLabel }, new NSObject[] { new NSString("PlaceholderLabel") })
);

placeholderLabel.TranslatesAutoresizingMaskIntoConstraints = false;

AddConstraints(hConstraints);
AddConstraints(vConstraints);
placeholderLabel.TextInsets = new UIEdgeInsets(edgeInsets.Top, edgeInsets.Left + lineFragmentPadding,
edgeInsets.Bottom, edgeInsets.Right + lineFragmentPadding);

return placeholderLabel;
}
Expand All @@ -165,7 +150,9 @@ void ShouldCenterVertically()
{
var fittingSize = new CGSize(Bounds.Width, NFloat.MaxValue);
var sizeThatFits = SizeThatFits(fittingSize);
var availableSpace = (Bounds.Height - sizeThatFits.Height * ZoomScale);
var availableSpace = Bounds.Height - sizeThatFits.Height * ZoomScale;
if (availableSpace <= 0)
return;
ContentOffset = VerticalTextAlignment switch
{
Maui.TextAlignment.Center => new CGPoint(0, -Math.Max(1, availableSpace / 2)),
Expand Down

0 comments on commit f6d8e15

Please sign in to comment.