Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Text not displayed correctly (iOS) #125

Open
AlleSchonWeg opened this issue Nov 27, 2020 · 1 comment
Open

Text not displayed correctly (iOS) #125

AlleSchonWeg opened this issue Nov 27, 2020 · 1 comment
Labels

Comments

@AlleSchonWeg
Copy link

Hi,

i have this simple demo xaml width a binding:

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:ios="clr-namespace:Xamarin.Forms.PlatformConfiguration.iOSSpecific;assembly=Xamarin.Forms.Core"
             ios:Page.UseSafeArea="True"
             xmlns:htmlLabel="clr-namespace:LabelHtml.Forms.Plugin.Abstractions;assembly=HtmlLabel.Forms.Plugin"
             x:Class="HtmlLabelTest.MainPage">
  <StackLayout>
    <htmlLabel:HtmlLabel Text="{Binding HtmlString}" />
  </StackLayout>
</ContentPage>

and updated via nuget to version 5. With version 5 the text flows outside the screen:
html500
with version 4.1.3 it works as it should be:
html413

The text is only a demo string. If it is a real html string the behavior is the same.

Demo:
HtmlLabelTest.zip

@sereoja
Copy link

sereoja commented May 11, 2023

Does anyone know what this is supposed to accomplish, asking because when I commented out this method this issue was solved.

public override SizeRequest GetDesiredSize(double widthConstraint, double heightConstraint)
{
if (!_perfectSizeValid)
{
_perfectSize = base.GetDesiredSize(double.PositiveInfinity, double.PositiveInfinity);
_perfectSize.Minimum = new Size(Math.Min(10, _perfectSize.Request.Width), _perfectSize.Request.Height);
_perfectSizeValid = true;
}

		var widthFits = widthConstraint >= _perfectSize.Request.Width;
		var heightFits = heightConstraint >= _perfectSize.Request.Height;

		if (widthFits && heightFits)
			return _perfectSize;

		var result = base.GetDesiredSize(widthConstraint, heightConstraint);
		var tinyWidth = Math.Min(10, result.Request.Width);
		result.Minimum = new Size(tinyWidth, result.Request.Height);

		if (widthFits || Element.LineBreakMode == LineBreakMode.NoWrap)
			return result;

		var containerIsNotInfinitelyWide = !double.IsInfinity(widthConstraint);

		if (containerIsNotInfinitelyWide)
		{
			var textCouldHaveWrapped = Element.LineBreakMode == LineBreakMode.WordWrap || Element.LineBreakMode == LineBreakMode.CharacterWrap;
			var textExceedsContainer = result.Request.Width > widthConstraint;

			if (textExceedsContainer || textCouldHaveWrapped)
			{
				var expandedWidth = Math.Max(tinyWidth, widthConstraint);
				result.Request = new Size(expandedWidth, result.Request.Height);
			}
		}

		return result;
	}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants