@@ -11,17 +11,16 @@ const majorVersion = iOSNativeHelper.MajorVersion;
1111
1212export class HtmlView extends HtmlViewBase {
1313 nativeViewProtected : UITextView ;
14- private currentHtml : string ;
1514
1615 public createNativeView ( ) {
17- const view = UITextView . new ( ) ;
18- view . scrollEnabled = false ;
19- view . editable = false ;
20- view . selectable = true ;
21- view . userInteractionEnabled = true ;
22- view . dataDetectorTypes = UIDataDetectorTypes . All ;
23-
24- return view ;
16+ const nativeView = UITextView . new ( ) ;
17+ nativeView . scrollEnabled = false ;
18+ nativeView . editable = false ;
19+ nativeView . selectable = true ;
20+ nativeView . userInteractionEnabled = true ;
21+ nativeView . dataDetectorTypes = UIDataDetectorTypes . All ;
22+
23+ return nativeView ;
2524 }
2625
2726 public initNativeView ( ) : void {
@@ -60,24 +59,37 @@ export class HtmlView extends HtmlViewBase {
6059 }
6160
6261 private renderWithStyles ( ) {
63- let html = this . currentHtml ;
64- const styles = [ ] ;
65- if ( this . nativeViewProtected . font ) {
66- styles . push ( `font-family: '${ this . nativeViewProtected . font . fontName } ';` ) ;
67- styles . push ( `font-size: ${ this . nativeViewProtected . font . pointSize } px;` ) ;
62+ const bodyStyles : string [ ] = [ ] ;
63+
64+ let htmlContent = this . html ?? '' ;
65+
66+ htmlContent += '<style>' ;
67+
68+ bodyStyles . push ( `font-size: ${ this . style . fontSize } px;` ) ;
69+
70+ if ( this . style . fontFamily ) {
71+ bodyStyles . push ( `font-family: '${ this . style . fontFamily } ';` ) ;
6872 }
69- if ( this . nativeViewProtected . textColor ) {
70- const textColor = Color . fromIosColor ( this . nativeViewProtected . textColor ) ;
71- styles . push ( `color: ${ textColor . hex } ;` ) ;
73+
74+ if ( this . style . color ) {
75+ bodyStyles . push ( `color: ${ this . style . color . hex } ;` ) ;
7276 }
73- if ( styles . length > 0 ) {
74- html += `<style>body {${ styles . join ( '' ) } }</style>` ;
77+
78+ htmlContent += `body {${ bodyStyles . join ( '' ) } }` ;
79+
80+ if ( this . linkColor ) {
81+ htmlContent += `a, a:link, a:visited { color: ${ this . linkColor . hex } !important; }` ;
7582 }
76- const htmlString = NSString . stringWithString ( html + '' ) ;
83+
84+ htmlContent += '</style>' ;
85+
86+ const htmlString = NSString . stringWithString ( htmlContent ) ;
7787 const nsData = htmlString . dataUsingEncoding ( NSUnicodeStringEncoding ) ;
78- this . nativeViewProtected . attributedText = NSAttributedString . alloc ( ) . initWithDataOptionsDocumentAttributesError ( nsData , < any > { [ NSDocumentTypeDocumentAttribute ] : NSHTMLTextDocumentType } , null ) ;
88+ const attributes = NSDictionary . dictionaryWithObjectForKey ( NSHTMLTextDocumentType , NSDocumentTypeDocumentAttribute ) ;
7989
80- if ( majorVersion >= 13 && UIColor . labelColor ) {
90+ this . nativeViewProtected . attributedText = NSAttributedString . alloc ( ) . initWithDataOptionsDocumentAttributesError ( nsData , attributes , null ) ;
91+
92+ if ( ! this . style . color && majorVersion >= 13 && UIColor . labelColor ) {
8193 this . nativeViewProtected . textColor = UIColor . labelColor ;
8294 }
8395 }
@@ -86,7 +98,6 @@ export class HtmlView extends HtmlViewBase {
8698 return '' ;
8799 }
88100 [ htmlProperty . setNative ] ( value : string ) {
89- this . currentHtml = value ;
90101 this . renderWithStyles ( ) ;
91102 }
92103
@@ -106,14 +117,10 @@ export class HtmlView extends HtmlViewBase {
106117 this . renderWithStyles ( ) ;
107118 }
108119
109- [ linkColorProperty . getDefault ] ( ) : UIColor {
110- return this . nativeViewProtected . linkTextAttributes [ NSForegroundColorAttributeName ] ;
111- }
112120 [ linkColorProperty . setNative ] ( value : Color | UIColor ) {
113- const color = value instanceof Color ? value . ios : value ;
114- const linkTextAttributes = NSDictionary . dictionaryWithObjectForKey ( color , NSForegroundColorAttributeName ) ;
115- this . nativeViewProtected . linkTextAttributes = linkTextAttributes ;
121+ this . renderWithStyles ( ) ;
116122 }
123+
117124 [ fontInternalProperty . getDefault ] ( ) : UIFont {
118125 return this . nativeViewProtected . font ;
119126 }
0 commit comments