@@ -6,13 +6,20 @@ import {
6
6
borderRightWidthProperty ,
7
7
borderTopWidthProperty ,
8
8
colorProperty ,
9
- lineHeightProperty ,
10
9
paddingBottomProperty ,
11
10
paddingLeftProperty ,
12
11
paddingRightProperty ,
13
12
paddingTopProperty ,
14
13
} from '@nativescript/core/ui/styling/style-properties' ;
15
- import { TextAlignment , TextTransform , WhiteSpace , letterSpacingProperty , whiteSpaceProperty } from '@nativescript/core/ui/text-base' ;
14
+
15
+ import { lineHeightProperty } from '@nativescript/core/ui/text-base/text-base-common' ;
16
+ import {
17
+ TextAlignment ,
18
+ TextTransform ,
19
+ WhiteSpace ,
20
+ letterSpacingProperty ,
21
+ whiteSpaceProperty ,
22
+ } from '@nativescript/core/ui/text-base' ;
16
23
import { isString } from '@nativescript/core/utils/types' ;
17
24
import { layout } from '@nativescript/core/utils/utils' ;
18
25
import { TextShadow , VerticalTextAlignment } from './label' ;
@@ -127,15 +134,17 @@ function HTMLStringToNSMutableAttributedString({
127
134
if ( iOSUseDTCoreText ) {
128
135
htmlString =
129
136
color || familyName || fontSize
130
- ? `<span style=" ${ color ? `color: ${ color } ;` : '' } ${ familyName ? `font-family:' ${ familyName . replace ( / ' / g , '' ) } ';` : '' } ${
131
- fontSize ? `font-size: ${ fontSize } px ;` : ''
132
- } ">${ text } </span>`
137
+ ? `<span style=" ${ color ? `color: ${ color } ;` : '' } ${
138
+ familyName ? `font-family:' ${ familyName . replace ( / ' / g , '' ) } ' ;` : ''
139
+ } ${ fontSize ? `font-size: ${ fontSize } px;` : '' } ">${ text } </span>`
133
140
: text ;
134
141
// `<span style="font-family: ${fontFamily}; font-size:${fontSize};">${htmlString}</span>`;
135
142
} else {
136
143
htmlString =
137
144
color || familyName || fontSize
138
- ? `<style>body{ ${ color ? `color: ${ color } ;` : '' } ${ familyName ? `font-family:"${ familyName . replace ( / ' / g, '' ) } ";` : '' } ${ fontSize ? `font-size: ${ fontSize } px;` : '' } }</style>${ text } `
145
+ ? `<style>body{ ${ color ? `color: ${ color } ;` : '' } ${
146
+ familyName ? `font-family:"${ familyName . replace ( / ' / g, '' ) } ";` : ''
147
+ } ${ fontSize ? `font-size: ${ fontSize } px;` : '' } }</style>${ text } `
139
148
: text ;
140
149
}
141
150
const nsString = NSString . stringWithString ( htmlString ) ;
@@ -156,14 +165,18 @@ function HTMLStringToNSMutableAttributedString({
156
165
// [DTDefaultLineBreakMode]: kCTLineBreakByWordWrapping
157
166
} as any ;
158
167
attrText = NSMutableAttributedString . alloc ( ) . initWithHTMLDataOptionsDocumentAttributes ( nsData , options , null ) ;
159
- attrText . enumerateAttributesInRangeOptionsUsingBlock ( { location : 0 , length : attrText . length } , NSAttributedStringEnumerationReverse , ( attributes : NSDictionary < any , any > , range , stop ) => {
160
- if ( ! ! attributes . valueForKey ( 'DTGUID' ) ) {
161
- // We need to remove this attribute or links are not colored right
162
- //
163
- // @see https://github.com/Cocoanetics/DTCoreText/issues/792
164
- attrText . removeAttributeRange ( 'CTForegroundColorFromContext' , range ) ;
168
+ attrText . enumerateAttributesInRangeOptionsUsingBlock (
169
+ { location : 0 , length : attrText . length } ,
170
+ NSAttributedStringEnumerationReverse ,
171
+ ( attributes : NSDictionary < any , any > , range , stop ) => {
172
+ if ( ! ! attributes . valueForKey ( 'DTGUID' ) ) {
173
+ // We need to remove this attribute or links are not colored right
174
+ //
175
+ // @see https://github.com/Cocoanetics/DTCoreText/issues/792
176
+ attrText . removeAttributeRange ( 'CTForegroundColorFromContext' , range ) ;
177
+ }
165
178
}
166
- } ) ;
179
+ ) ;
167
180
} else {
168
181
attrText = NSMutableAttributedString . alloc ( ) . initWithDataOptionsDocumentAttributesError (
169
182
nsData ,
@@ -252,7 +265,12 @@ export class Label extends LabelBase {
252
265
super . initNativeView ( ) ;
253
266
this . _observer = ObserverClass . alloc ( ) . init ( ) ;
254
267
this . _observer [ '_owner' ] = new WeakRef ( this ) ;
255
- this . nativeViewProtected . addObserverForKeyPathOptionsContext ( this . _observer , 'contentSize' , NSKeyValueObservingOptions . New , null ) ;
268
+ this . nativeViewProtected . addObserverForKeyPathOptionsContext (
269
+ this . _observer ,
270
+ 'contentSize' ,
271
+ NSKeyValueObservingOptions . New ,
272
+ null
273
+ ) ;
256
274
this . nativeViewProtected . attributedText = this . attributedString ;
257
275
// this.htmlText = null;
258
276
// this.needsHTMLUpdate = false;
@@ -276,7 +294,11 @@ export class Label extends LabelBase {
276
294
const rect = text . boundingRectWithSizeOptionsContext ( size , NSStringDrawingOptions . UsesLineFragmentOrigin , null ) ;
277
295
return rect . size . height ;
278
296
}
279
- return NSString . stringWithString ( text ) . sizeWithFontConstrainedToSizeLineBreakMode ( font , size , tv . textContainer . lineBreakMode ) . height ;
297
+ return NSString . stringWithString ( text ) . sizeWithFontConstrainedToSizeLineBreakMode (
298
+ font ,
299
+ size ,
300
+ tv . textContainer . lineBreakMode
301
+ ) . height ;
280
302
}
281
303
updateVerticalAlignment ( ) {
282
304
const tv = this . nativeTextViewProtected ;
0 commit comments