@@ -11,17 +11,16 @@ const majorVersion = iOSNativeHelper.MajorVersion;
11
11
12
12
export class HtmlView extends HtmlViewBase {
13
13
nativeViewProtected : UITextView ;
14
- private currentHtml : string ;
15
14
16
15
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 ;
25
24
}
26
25
27
26
public initNativeView ( ) : void {
@@ -60,24 +59,37 @@ export class HtmlView extends HtmlViewBase {
60
59
}
61
60
62
61
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 } ';` ) ;
68
72
}
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 } ;` ) ;
72
76
}
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; }` ;
75
82
}
76
- const htmlString = NSString . stringWithString ( html + '' ) ;
83
+
84
+ htmlContent += '</style>' ;
85
+
86
+ const htmlString = NSString . stringWithString ( htmlContent ) ;
77
87
const nsData = htmlString . dataUsingEncoding ( NSUnicodeStringEncoding ) ;
78
- this . nativeViewProtected . attributedText = NSAttributedString . alloc ( ) . initWithDataOptionsDocumentAttributesError ( nsData , < any > { [ NSDocumentTypeDocumentAttribute ] : NSHTMLTextDocumentType } , null ) ;
88
+ const attributes = NSDictionary . dictionaryWithObjectForKey ( NSHTMLTextDocumentType , NSDocumentTypeDocumentAttribute ) ;
79
89
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 ) {
81
93
this . nativeViewProtected . textColor = UIColor . labelColor ;
82
94
}
83
95
}
@@ -86,7 +98,6 @@ export class HtmlView extends HtmlViewBase {
86
98
return '' ;
87
99
}
88
100
[ htmlProperty . setNative ] ( value : string ) {
89
- this . currentHtml = value ;
90
101
this . renderWithStyles ( ) ;
91
102
}
92
103
@@ -106,14 +117,10 @@ export class HtmlView extends HtmlViewBase {
106
117
this . renderWithStyles ( ) ;
107
118
}
108
119
109
- [ linkColorProperty . getDefault ] ( ) : UIColor {
110
- return this . nativeViewProtected . linkTextAttributes [ NSForegroundColorAttributeName ] ;
111
- }
112
120
[ 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 ( ) ;
116
122
}
123
+
117
124
[ fontInternalProperty . getDefault ] ( ) : UIFont {
118
125
return this . nativeViewProtected . font ;
119
126
}
0 commit comments