HtmlLabelPlugin
HtmlLabelPlugin copied to clipboard
[iOS] UI not loading properly when html initialized with some delay
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
Mine is the same, and if I HOT RELOAD, then it loads the full content - any fix on this?
try this :: <Label TextType="Html" <-- worked for me
@FELS-Zak sorry, at the time I can only accept PRs. But I am happy the default implementation works for you
Thanks!
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);
I think it's the same as #125
I set up a VM, I can give a look
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
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.
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;
}