Forum Xamarin.Forms

HTML-content in ViewCell

DanielHJDanielHJ Member ✭✭
edited September 1 in Xamarin.Forms

Hello everyone!

I am trying to display a label with TextType HTML. When I put the app to background or when I bring it back to foreground I get the following crash:

Objective-C exception thrown.  Name: NSInternalInconsistencyException Reason: unexpected start state

I've had this problem before but didn't manage to solve it. I have tried a few different nugets for HTML-cells, but get the same crash.

Has anyone had this problem and figured out how to solve it?

I am also wondering if there is any way of supporting more HTML/CSS on Android. With my test project on iOS (before the crash) I get all the styling defined. But with Android I am just getting basic (bold, cursive etc) styling.

Thank you,
Daniel

Answers

  • JarvanJarvan Member, Xamarin Team Xamurai

    When I put the app to background or when I bring it back to foreground I get the following crash

    I created a basic sample to test the label with TextType HTML on ios and it works fine. The crash may be not caused by the label. What's the version of Xamarin.Forms package and Xamarin.iOS sdk did you use in the project? Try to update to the lastest stable version and test again.

    I get all the styling defined. But with Android I am just getting basic (bold, cursive etc) styling.

    You could use the WebView to display the html content or try the Xam.Plugin.HtmlLabel plugin.

  • DanielHJDanielHJ Member ✭✭

    Sorry. I should have made it more clear. I am trying to use a label with TextType HTML inside a viewCell.

    I believe just putting a label works fine. I am sure that it is the problem, because when I remove the cell with the label it will work.

    I have tried the plugin you mentioned, but I get the same issue.

    My iOS is set to 13.6
    Xamarin.forms version is 4.8.0.1364

  • JarvanJarvan Member, Xamarin Team Xamurai

    I am trying to use a label with TextType HTML inside a viewCell ... when I remove the cell with the label it will work.

    I tested the function code in a ListView and it also works well. How did you place the viewCell? Could you share a basic demo to reproduct the issue?

    <ListView>
        ...
        <ListView.ItemTemplate>
            <DataTemplate>
                <ViewCell>
                    <Label TextType="Html" Text="{Binding .}"/>
                </ViewCell>
            </DataTemplate>
        </ListView.ItemTemplate>
    </ListView>
    
  • DanielHJDanielHJ Member ✭✭
    edited September 2

    I made a test project that has the same functionality as my original project, and while the app didn't crash the first time, on the third time after putting it to background and back to foreground, I got the same crash.

    I made a repo with my code @ https://github.com/DanielHJA/CrashingXamarinHTMLCell

    Thank you for trying to help me!

    / Daniel

  • JarvanJarvan Member, Xamarin Team Xamurai

    I tested the sample from the link and face the same issue as you descriped. Test but not get the reason now. If I comment the Model.FetchJSON command, it'll work fine.

    public partial class MainPage : ContentPage
    {
        MainPageViewModel Model = new MainPageViewModel();
    
        public MainPage()
        {
            InitializeComponent();
            BindingContext = Model;
            //Model.FetchJSON();
        }
    }
    

    I created a basic sample to reproduce the code, it works well. I posted the demo file, you could check that. Try creating a new project and copy the code from the previous sample.

  • DanielHJDanielHJ Member ✭✭

    Sorry for the delayed response!

    Thank you for making the project, but I get the same error from your demo. It took 3-6 times to go background -> foreground before crashing. One of my friends gets the same error as me.

    Seems to be related to when Xamarin needs to use the NSAtrributedstring to create the HTML, but not really sure where to go from here.

    Thanks again for your help

  • JarvanJarvan Member, Xamarin Team Xamurai

    Sorry for my mistake, I faced the same issue when deploying the code. If remove the TextType = Html, it'll works fine. And there is nothing wrong with the Android platform. This may be a potential issue, you could report it to the product team on github.

    https://github.com/xamarin/Xamarin.Forms/issues/new/choose

  • DanielHJDanielHJ Member ✭✭

    @Jarvan said:
    Sorry for my mistake, I faced the same issue when deploying the code. If remove the TextType = Html, it'll works fine. And there is nothing wrong with the Android platform. This may be a potential issue, you could report it to the product team on github.

    https://github.com/xamarin/Xamarin.Forms/issues/new/choose

    I submitted a bug report and will leave this issue open in case someone in the product team has a solution so I can post it here :).

    Thank you!

  • JarvanJarvan Member, Xamarin Team Xamurai

    Here is the link of the topic. If others face the similar, check this link.
    https://github.com/xamarin/Xamarin.Forms/issues/12045

Sign In or Register to comment.