Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 67b1d6e

Browse files
committedSep 8, 2020
fix(ios): crash
1 parent e33313c commit 67b1d6e

File tree

1 file changed

+37
-15
lines changed

1 file changed

+37
-15
lines changed
 

Diff for: ‎src/label.ios.ts

+37-15
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,20 @@ import {
66
borderRightWidthProperty,
77
borderTopWidthProperty,
88
colorProperty,
9-
lineHeightProperty,
109
paddingBottomProperty,
1110
paddingLeftProperty,
1211
paddingRightProperty,
1312
paddingTopProperty,
1413
} 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';
1623
import { isString } from '@nativescript/core/utils/types';
1724
import { layout } from '@nativescript/core/utils/utils';
1825
import { TextShadow, VerticalTextAlignment } from './label';
@@ -127,15 +134,17 @@ function HTMLStringToNSMutableAttributedString({
127134
if (iOSUseDTCoreText) {
128135
htmlString =
129136
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>`
133140
: text;
134141
// `<span style="font-family: ${fontFamily}; font-size:${fontSize};">${htmlString}</span>`;
135142
} else {
136143
htmlString =
137144
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}`
139148
: text;
140149
}
141150
const nsString = NSString.stringWithString(htmlString);
@@ -156,14 +165,18 @@ function HTMLStringToNSMutableAttributedString({
156165
// [DTDefaultLineBreakMode]: kCTLineBreakByWordWrapping
157166
} as any;
158167
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+
}
165178
}
166-
});
179+
);
167180
} else {
168181
attrText = NSMutableAttributedString.alloc().initWithDataOptionsDocumentAttributesError(
169182
nsData,
@@ -252,7 +265,12 @@ export class Label extends LabelBase {
252265
super.initNativeView();
253266
this._observer = ObserverClass.alloc().init();
254267
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+
);
256274
this.nativeViewProtected.attributedText = this.attributedString;
257275
// this.htmlText = null;
258276
// this.needsHTMLUpdate = false;
@@ -276,7 +294,11 @@ export class Label extends LabelBase {
276294
const rect = text.boundingRectWithSizeOptionsContext(size, NSStringDrawingOptions.UsesLineFragmentOrigin, null);
277295
return rect.size.height;
278296
}
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;
280302
}
281303
updateVerticalAlignment() {
282304
const tv = this.nativeTextViewProtected;

0 commit comments

Comments
 (0)
Please sign in to comment.