You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
HtmlView on iOS resets font on binding change #1268
So basically any time you change the content bound to the html property, the font assigned gets reset...so need to keep re-calling this. I mean the UIFont is still there but what's in the view is reset to Times, and you need to re-call the .ios.font on it.
var contentHtmlView = page.getViewById("contentHtmlView");
contentHtmlView.ios.font = UIFont.fontWithNameSize(fontName,fontSize);
I use HtmlView since I didn't find a convenient/fast way to render strings with html entities. I encountered the same issue where dynamically laded texts are shown with times (or similar) on iOS.
At the moment I'm using a simple hack that I would like to share here for anyone that needs an immediate fix:
I'm leveraging the fact that html doesn't force the use of " character.
I'm avoiding both single and double quotes because if used the nativescript parser fails.
I also avoiding mapping my collection within the component/controller because I really hate mixing styles with data and I also hope to remove soon this little hack from my view :)
Hi @sitefinitysteve,
We checked the provided scenario again with replacing the font family in the HtmlView. However, it seems that the behaviour, how text is set to the view has changed. After reviewing the code in the modules, I found that at this time we are using NSAttributedString and changing the font as it is shown in the gist above is not supported on the initial time as well. Regarding that, I consider that technic is no longer supported and we could close this issue.
@sitefinitysteve in case you think that this functionality should be supported, please provide more info about the use cases, and I will reopen the issue.
For a more flexible way to modify a style in the HTML, I would suggest using WebView component.
Can we re-evaluate or solicite some extra input on this? Like @enricodeleo I feel like multiple webview to just render some markup send from my service is just going to slow the app down, and is beyond overkill.
The usecase is we store mixed content in Sitefinity, served out to our apps so like the detail views need to show multiple Html content fields in the single view. So it all works just fine until the bound content changes, then its like the HtmlView is just reset. Like Effectively this is our "Label" for most content. If the styling on a Label was reset on content change it would be just as problematic.
We have thumbs-up on the issue, more than just me have encountered this :/
We rechecked the case and have to agree that using the multiple WebViews can slow the app down. Regarding that, I am opening this issue again. Also, any PR, which provides a fix for this behaviour will be highly appreciated.
Is there any workaround for this bug? It feels very weird in any app to have Times New Roman on a well-designed page. I even tried to set custom styles directly in the HTML (with style attributes) and it doesn't work either.
@sebj54 did u resolve this out? I am facing the same problem with WebView on iOS in NativeScript 7, on Android it works well, but in iOS there is Times New Roman 😢 .. I tried to set the font almost everywhere ...
Hi @souriscloud I finally made it work, yes! I made a custom component for that in my app. It's been a while since I made and used it so I don't remember why all that was needed so feel free to comment some things and try if it works without them.
Here is the component (I was using NativeScript 6 at that time so maybe you'll have to adjust the component):
HtmlView on iOS now re-applies the view's CSS font-family, font-size and color to the rendered HTML on every html change (#8207), so there's no need to reset ios.font. Closing — if you still see the font reset on current @nativescript/core, please open a new issue with a repro.
Activity
enchev commentedon Aug 8, 2016
Hey @sitefinitysteve,
Do you still have problems with this?
sitefinitysteve commentedon Aug 17, 2016
I'm sorry, I've been stuck in windows, I havent validated this since... however would it not still be an issue unless you guys fixed it?
sitefinitysteve commentedon Aug 23, 2016
@enchev Totally still an issue, can this re-open?
Very simply just bind some value to the html property <HtmlView html="{{ property }}" shows as just plain unformatted content.
enricodeleo commentedon Nov 27, 2016
I use HtmlView since I didn't find a convenient/fast way to render strings with html entities. I encountered the same issue where dynamically laded texts are shown with times (or similar) on iOS.
At the moment I'm using a simple hack that I would like to share here for anyone that needs an immediate fix:
please note that:
"character.7 remaining items
tsonevn commentedon Feb 22, 2018
Hi @sitefinitysteve,
We checked the provided scenario again with replacing the font family in the HtmlView. However, it seems that the behaviour, how text is set to the view has changed. After reviewing the code in the modules, I found that at this time we are using NSAttributedString and changing the font as it is shown in the gist above is not supported on the initial time as well. Regarding that, I consider that technic is no longer supported and we could close this issue.
@sitefinitysteve in case you think that this functionality should be supported, please provide more info about the use cases, and I will reopen the issue.
For a more flexible way to modify a style in the HTML, I would suggest using WebView component.
sitefinitysteve commentedon Feb 22, 2018
Can we re-evaluate or solicite some extra input on this? Like @enricodeleo I feel like multiple webview to just render some markup send from my service is just going to slow the app down, and is beyond overkill.
The usecase is we store mixed content in Sitefinity, served out to our apps so like the detail views need to show multiple Html content fields in the single view. So it all works just fine until the bound content changes, then its like the HtmlView is just reset. Like Effectively this is our "Label" for most content. If the styling on a Label was reset on content change it would be just as problematic.
We have thumbs-up on the issue, more than just me have encountered this :/
Steve
tsonevn commentedon Mar 6, 2018
Hi @sitefinitysteve,
We rechecked the case and have to agree that using the multiple WebViews can slow the app down. Regarding that, I am opening this issue again. Also, any PR, which provides a fix for this behaviour will be highly appreciated.
Regards,
@tsonevn
sitefinitysteve commentedon Mar 6, 2018
sebj54 commentedon May 25, 2020
The issue is still here in version 6.5.
Is there any workaround for this bug? It feels very weird in any app to have Times New Roman on a well-designed page. I even tried to set custom styles directly in the HTML (with style attributes) and it doesn't work either.
souriscloud commentedon Nov 25, 2020
@sebj54 did u resolve this out? I am facing the same problem with WebView on iOS in NativeScript 7, on Android it works well, but in iOS there is Times New Roman 😢 .. I tried to set the font almost everywhere ...
sebj54 commentedon Nov 26, 2020
Hi @souriscloud I finally made it work, yes! I made a custom component for that in my app. It's been a while since I made and used it so I don't remember why all that was needed so feel free to comment some things and try if it works without them.
Here is the component (I was using NativeScript 6 at that time so maybe you'll have to adjust the component):
HtmlContent.vueNathanWalker commentedon Oct 23, 2026
HtmlView on iOS now re-applies the view's CSS
font-family,font-sizeandcolorto the rendered HTML on everyhtmlchange (#8207), so there's no need to resetios.font. Closing — if you still see the font reset on current@nativescript/core, please open a new issue with a repro.