HtmlLabelPlugin icon indicating copy to clipboard operation
HtmlLabelPlugin copied to clipboard

[iOS] UI not loading properly when html initialized with some delay

Open hemantbeast opened this issue 3 years ago • 9 comments

In the sample below, after adding a delay the UI not loading the content properly on iOS, whereas it is working fine on android. If we are not adding the delay then the content appears properly.

But my scenario is, I've an API call in the page in which I get html content. So that html content is not visible on iOS with the latest version.

Sample: HtmlLabelSample

hemantbeast avatar Jan 05 '21 08:01 hemantbeast

Mine is the same, and if I HOT RELOAD, then it loads the full content - any fix on this?

FELS-Zak avatar Jan 26 '21 18:01 FELS-Zak

try this :: <Label TextType="Html" <-- worked for me

FELS-Zak avatar Jan 26 '21 18:01 FELS-Zak

@FELS-Zak sorry, at the time I can only accept PRs. But I am happy the default implementation works for you

matteobortolazzo avatar Jan 26 '21 20:01 matteobortolazzo

Thanks!

FELS-Zak avatar Jan 26 '21 22:01 FELS-Zak

got same problem on ios. for me solutions was create HtmlLabel in c# code and then add it to stacklayout where it need to be by htmlStack.Children.Insert(0, HtmlLabel);

ipon85 avatar Mar 04 '21 16:03 ipon85

I think it's the same as #125

I set up a VM, I can give a look

matteobortolazzo avatar Mar 13 '21 18:03 matteobortolazzo

Hi, I tried everything I could find. No results... Probably the best solution is to remove the control and add it back so to force the rerender. If anyone knows more about iOS please let me know or create a PR

matteobortolazzo avatar Mar 14 '21 20:03 matteobortolazzo

I encountered the same problem in IOS: the HtmlLabel only showed the first line or nothing at all. Workaround I used:

In xaml file I added the Html text in a standard Label which is invisible:

in the xaml code behind, I added a HtmlLabel control in the OnAppearing event after a small delay (neccessary for iOS) and copied the text of the standard label into the HtmlLabel:

protected async override void OnAppearing() { await Task.Delay(500); if (!string.IsNullOrEmpty(BodyLabel.Text)) { //Only add it once if (BodyContainer.Children.Count == 1) BodyContainer.Children.Add(new HtmlLabel { Text = BodyLabel.Text, AndroidLegacyMode = true, LinkColor = Color.FromHex("#4897e7") }); } }

Bit of a hack, but it works on Android as well as iOS.

Balu2 avatar Nov 25 '21 16:11 Balu2

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;
}

sereoja avatar Jun 12 '23 18:06 sereoja