@nativescript-community/ui-label 1.2.27 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/label-common.d.ts +4 -3
- package/label-common.js +17 -17
- package/label-common.js.map +1 -1
- package/label.android.d.ts +2 -2
- package/label.android.js +27 -22
- package/label.android.js.map +1 -1
- package/label.ios.d.ts +26 -11
- package/label.ios.js +432 -343
- package/label.ios.js.map +1 -1
- package/package.json +3 -3
- package/platforms/android/native-api-usage.json +1 -0
- package/platforms/ios/src/NSLabel.swift +93 -0
- package/platforms/ios/src/NSLabelUtils.swift +165 -0
- package/platforms/ios/src/NSTextView.swift +37 -0
- package/platforms/ios/src/UILabelLinkHandler.swift +97 -0
package/label.ios.js
CHANGED
@@ -1,15 +1,39 @@
|
|
1
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r;
|
1
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u;
|
2
2
|
import { createNativeAttributedString, verticalTextAlignmentProperty } from '@nativescript-community/text';
|
3
|
-
import { Color, Font, Span, Utils, View } from '@nativescript/core';
|
3
|
+
import { Color, Font, Span, Utils, View, profile } from '@nativescript/core';
|
4
4
|
import { borderBottomWidthProperty, borderLeftWidthProperty, borderRightWidthProperty, borderTopWidthProperty, fontInternalProperty, paddingBottomProperty, paddingLeftProperty, paddingRightProperty, paddingTopProperty } from '@nativescript/core/ui/styling/style-properties';
|
5
5
|
import { formattedTextProperty, letterSpacingProperty, lineHeightProperty, textProperty, whiteSpaceProperty } from '@nativescript/core/ui/text-base';
|
6
6
|
import { maxLinesProperty } from '@nativescript/core/ui/text-base/text-base-common';
|
7
|
-
import { iOSNativeHelper } from '@nativescript/core/utils';
|
8
7
|
import { isNullOrUndefined, isString } from '@nativescript/core/utils/types';
|
9
|
-
import { LabelBase, autoFontSizeProperty, htmlProperty, lineBreakProperty, linkColorProperty, linkUnderlineProperty, maxFontSizeProperty, minFontSizeProperty,
|
10
|
-
export { createNativeAttributedString
|
8
|
+
import { LabelBase, autoFontSizeProperty, htmlProperty, lineBreakProperty, linkColorProperty, linkUnderlineProperty, maxFontSizeProperty, minFontSizeProperty, needSetText, selectableProperty, textShadowProperty } from './label-common';
|
9
|
+
export { createNativeAttributedString } from '@nativescript-community/text';
|
11
10
|
export * from './label-common';
|
12
|
-
|
11
|
+
var UILabelLinkHandlerTapDelegateImpl = /** @class */ (function (_super) {
|
12
|
+
__extends(UILabelLinkHandlerTapDelegateImpl, _super);
|
13
|
+
function UILabelLinkHandlerTapDelegateImpl() {
|
14
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
15
|
+
}
|
16
|
+
UILabelLinkHandlerTapDelegateImpl.initWithOwner = function (owner) {
|
17
|
+
var handler = UILabelLinkHandlerTapDelegateImpl.new();
|
18
|
+
handler.mOwner = owner;
|
19
|
+
return handler;
|
20
|
+
};
|
21
|
+
UILabelLinkHandlerTapDelegateImpl.prototype.onLinkTapped = function (value) {
|
22
|
+
var _a;
|
23
|
+
var owner = (_a = this.mOwner) === null || _a === void 0 ? void 0 : _a.deref();
|
24
|
+
if (owner) {
|
25
|
+
var formattedText = owner.formattedText;
|
26
|
+
if (formattedText && typeof value === 'number' && value < formattedText.spans.length) {
|
27
|
+
formattedText.spans.getItem(value)._emit(Span.linkTapEvent);
|
28
|
+
}
|
29
|
+
else {
|
30
|
+
owner.notify({ eventName: 'linkTap', link: value });
|
31
|
+
}
|
32
|
+
}
|
33
|
+
};
|
34
|
+
UILabelLinkHandlerTapDelegateImpl.ObjCProtocols = [UILabelLinkHandlerTapDelegate];
|
35
|
+
return UILabelLinkHandlerTapDelegateImpl;
|
36
|
+
}(NSObject));
|
13
37
|
const AttributeOriginalFontSize = 'OriginalFontSize';
|
14
38
|
var FixedSize;
|
15
39
|
(function (FixedSize) {
|
@@ -59,6 +83,14 @@ function whiteSpaceToLineBreakMode(value) {
|
|
59
83
|
return 4 /* NSLineBreakMode.ByTruncatingTail */;
|
60
84
|
}
|
61
85
|
}
|
86
|
+
export const needUpdateVerticalAlignment = function (target, propertyKey, descriptor) {
|
87
|
+
const originalMethod = descriptor.value;
|
88
|
+
descriptor.value = function (...args) {
|
89
|
+
const result = originalMethod.apply(this, args);
|
90
|
+
this.updateVerticalAlignment();
|
91
|
+
return result;
|
92
|
+
};
|
93
|
+
};
|
62
94
|
export const needAutoFontSizeComputation = function (target, propertyKey, descriptor) {
|
63
95
|
const originalMethod = descriptor.value;
|
64
96
|
descriptor.value = function (...args) {
|
@@ -106,13 +138,11 @@ var LabelObserverClass = /** @class */ (function (_super) {
|
|
106
138
|
function LabelObserverClass() {
|
107
139
|
return _super !== null && _super.apply(this, arguments) || this;
|
108
140
|
}
|
109
|
-
// NOTE: Refactor this - use Typescript property instead of strings....
|
110
141
|
LabelObserverClass.prototype.observeValueForKeyPathOfObjectChangeContext = function (path, tv) {
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
}
|
142
|
+
var _a;
|
143
|
+
var owner = (_a = this._owner) === null || _a === void 0 ? void 0 : _a.get();
|
144
|
+
if (owner) {
|
145
|
+
owner.updateVerticalAlignment();
|
116
146
|
}
|
117
147
|
};
|
118
148
|
return LabelObserverClass;
|
@@ -121,70 +151,53 @@ export class Label extends LabelBase {
|
|
121
151
|
constructor() {
|
122
152
|
super(...arguments);
|
123
153
|
this.fontSizeRatio = 1;
|
154
|
+
this.isUsingUITextView = false;
|
124
155
|
this.mCanUpdateAutoFontSize = true;
|
156
|
+
this.mCanUpdateVerticalAlignment = true;
|
125
157
|
this.mNeedAutoFontSizeComputation = false;
|
158
|
+
this.mNeedUpdateVerticalAlignment = false;
|
126
159
|
}
|
127
|
-
// constructor() {
|
128
|
-
// super();
|
129
|
-
// if (iOSUseDTCoreText && !Label.DTCORETEXT_INIT) {
|
130
|
-
// Label.DTCORETEXT_INIT = true;
|
131
|
-
// DTCoreTextFontDescriptor.asyncPreloadFontLookupTable();
|
132
|
-
// }
|
133
|
-
// }
|
134
160
|
createNativeView() {
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
}
|
139
|
-
|
140
|
-
view.scrollEnabled = false;
|
141
|
-
view.editable = false;
|
142
|
-
view.selectable = false;
|
143
|
-
view.backgroundColor = UIColor.clearColor;
|
144
|
-
view.userInteractionEnabled = true;
|
145
|
-
view.dataDetectorTypes = -1 /* UIDataDetectorTypes.All */;
|
146
|
-
view.textContainerInset = UIEdgeInsetsZero;
|
147
|
-
view.textContainer.lineFragmentPadding = 0;
|
148
|
-
// ignore font leading just like UILabel does
|
149
|
-
view.layoutManager.usesFontLeading = false;
|
150
|
-
// view.textContainer.lineBreakMode = NSLineBreakMode.ByCharWrapping;
|
151
|
-
return view;
|
161
|
+
if (this.selectable) {
|
162
|
+
this.isUsingUITextView = true;
|
163
|
+
return NSTextView.new();
|
164
|
+
}
|
165
|
+
return NSLabel.new();
|
152
166
|
}
|
153
167
|
initNativeView() {
|
154
168
|
super.initNativeView();
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
169
|
+
const nativeView = this.nativeTextViewProtected;
|
170
|
+
if (this.isUsingUITextView) {
|
171
|
+
this.mObserver = LabelObserverClass.alloc().init();
|
172
|
+
this.mObserver._owner = new WeakRef(this);
|
173
|
+
this.mDelegate = LabelUITextViewDelegateImpl.initWithOwner(new WeakRef(this));
|
174
|
+
nativeView.delegate = this.mDelegate;
|
175
|
+
nativeView.addObserverForKeyPathOptionsContext(this.mObserver, 'contentSize', 1 /* NSKeyValueObservingOptions.New */, null);
|
176
|
+
}
|
160
177
|
}
|
161
178
|
disposeNativeView() {
|
162
179
|
this.mDelegate = null;
|
163
|
-
this.nativeTextViewProtected
|
180
|
+
const nativeView = this.nativeTextViewProtected;
|
181
|
+
if (this.isUsingUITextView) {
|
182
|
+
nativeView.delegate = null;
|
183
|
+
}
|
184
|
+
if (this.mTapGestureRecognizer) {
|
185
|
+
this.nativeViewProtected.removeGestureRecognizer(this.mTapGestureRecognizer);
|
186
|
+
this.mTapGestureRecognizer = null;
|
187
|
+
}
|
188
|
+
this.mTapDelegate = null;
|
164
189
|
super.disposeNativeView();
|
165
|
-
// if (this._htmlTapGestureRecognizer) {
|
166
|
-
// this.nativeViewProtected.removeGestureRecognizer(this._htmlTapGestureRecognizer);
|
167
|
-
// this._htmlTapGestureRecognizer = null;
|
168
|
-
// }
|
169
190
|
if (this.mObserver) {
|
170
|
-
this.
|
191
|
+
const nativeView = this.nativeTextViewProtected;
|
192
|
+
if (this.isUsingUITextView) {
|
193
|
+
nativeView.removeObserverForKeyPath(this.mObserver, 'contentSize');
|
194
|
+
}
|
171
195
|
this.mObserver = null;
|
172
196
|
}
|
173
197
|
}
|
174
|
-
onLoaded() {
|
175
|
-
super.onLoaded();
|
176
|
-
if (this.nativeTextViewProtected) {
|
177
|
-
this.nativeTextViewProtected.delegate = this.mDelegate;
|
178
|
-
}
|
179
|
-
}
|
180
|
-
onUnloaded() {
|
181
|
-
if (this.nativeTextViewProtected) {
|
182
|
-
this.nativeTextViewProtected.delegate = null;
|
183
|
-
}
|
184
|
-
super.onUnloaded();
|
185
|
-
}
|
186
198
|
onResumeNativeUpdates() {
|
187
199
|
// {N} suspends properties update on `_suspendNativeUpdates`. So we only need to do this in onResumeNativeUpdates
|
200
|
+
this.mCanUpdateVerticalAlignment = false;
|
188
201
|
this.mCanUpdateAutoFontSize = false;
|
189
202
|
super.onResumeNativeUpdates();
|
190
203
|
this.mCanUpdateAutoFontSize = true;
|
@@ -194,9 +207,13 @@ export class Label extends LabelBase {
|
|
194
207
|
this.updateAutoFontSize({ textView: this.nativeTextViewProtected, force: true });
|
195
208
|
}
|
196
209
|
}
|
210
|
+
this.mCanUpdateVerticalAlignment = true;
|
211
|
+
if (this.mNeedUpdateVerticalAlignment) {
|
212
|
+
this.mNeedUpdateVerticalAlignment = false;
|
213
|
+
this.updateVerticalAlignment();
|
214
|
+
}
|
197
215
|
}
|
198
|
-
computeTextHeight(size) {
|
199
|
-
const tv = this.nativeTextViewProtected;
|
216
|
+
computeTextHeight(tv, size) {
|
200
217
|
const oldtextContainerInset = tv.textContainerInset;
|
201
218
|
tv.textContainerInset = UIEdgeInsetsZero;
|
202
219
|
// if (tv.attributedText) {
|
@@ -211,8 +228,24 @@ export class Label extends LabelBase {
|
|
211
228
|
tv.textContainerInset = oldtextContainerInset;
|
212
229
|
return result.height;
|
213
230
|
}
|
214
|
-
|
215
|
-
const
|
231
|
+
updateVerticalAlignment(applyVerticalTextAlignment = true) {
|
232
|
+
const nativeView = this.nativeTextViewProtected;
|
233
|
+
if (!this.mCanUpdateVerticalAlignment) {
|
234
|
+
this.mNeedUpdateVerticalAlignment = true;
|
235
|
+
return;
|
236
|
+
}
|
237
|
+
if (!this.isUsingUITextView && !this.isLayoutValid) {
|
238
|
+
return;
|
239
|
+
}
|
240
|
+
const result = this.updateTextContainerInset(nativeView, applyVerticalTextAlignment);
|
241
|
+
nativeView.textContainerInset = result;
|
242
|
+
if (this.isUsingUITextView) {
|
243
|
+
nativeView.contentInset = UIEdgeInsetsZero;
|
244
|
+
}
|
245
|
+
// this.requestLayout();
|
246
|
+
}
|
247
|
+
updateTextContainerInset(tv, applyVerticalTextAlignment = true) {
|
248
|
+
let inset;
|
216
249
|
const top = Utils.layout.toDeviceIndependentPixels(this.effectivePaddingTop + this.effectiveBorderTopWidth);
|
217
250
|
const right = Utils.layout.toDeviceIndependentPixels(this.effectivePaddingRight + this.effectiveBorderRightWidth);
|
218
251
|
const bottom = Utils.layout.toDeviceIndependentPixels(this.effectivePaddingBottom + this.effectiveBorderBottomWidth);
|
@@ -220,42 +253,65 @@ export class Label extends LabelBase {
|
|
220
253
|
if (!applyVerticalTextAlignment ||
|
221
254
|
!this.verticalTextAlignment ||
|
222
255
|
(tv.text?.length === 0 && tv.attributedText?.length === 0)) {
|
223
|
-
|
256
|
+
inset = {
|
224
257
|
top,
|
225
258
|
left,
|
226
259
|
bottom,
|
227
260
|
right
|
228
261
|
};
|
229
|
-
return;
|
262
|
+
return inset;
|
230
263
|
}
|
231
264
|
switch (this.verticalTextAlignment) {
|
232
265
|
case 'initial': // not supported
|
233
266
|
case 'top':
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
267
|
+
if (this.isUsingUITextView) {
|
268
|
+
inset = {
|
269
|
+
top,
|
270
|
+
left,
|
271
|
+
bottom,
|
272
|
+
right
|
273
|
+
};
|
274
|
+
}
|
275
|
+
else {
|
276
|
+
const height = this.computeTextHeight(tv, CGSizeMake(tv.bounds.size.width, Number.MAX_SAFE_INTEGER));
|
277
|
+
let topCorrect = tv.bounds.size.height - top - bottom - height * tv.zoomScale;
|
278
|
+
topCorrect = topCorrect < 0.0 ? 0.0 : topCorrect;
|
279
|
+
inset = {
|
280
|
+
top,
|
281
|
+
left,
|
282
|
+
bottom: bottom + topCorrect,
|
283
|
+
right
|
284
|
+
};
|
285
|
+
}
|
240
286
|
break;
|
241
287
|
case 'middle':
|
242
288
|
case 'center': {
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
289
|
+
if (this.isUsingUITextView) {
|
290
|
+
const height = this.computeTextHeight(tv, CGSizeMake(tv.bounds.size.width, Number.MAX_SAFE_INTEGER));
|
291
|
+
let topCorrect = (tv.bounds.size.height - top - bottom - height * tv.zoomScale) / 2.0;
|
292
|
+
topCorrect = topCorrect < 0.0 ? 0.0 : topCorrect;
|
293
|
+
inset = {
|
294
|
+
top: top + topCorrect,
|
295
|
+
left,
|
296
|
+
bottom,
|
297
|
+
right
|
298
|
+
};
|
299
|
+
}
|
300
|
+
else {
|
301
|
+
inset = {
|
302
|
+
top,
|
303
|
+
left,
|
304
|
+
bottom,
|
305
|
+
right
|
306
|
+
};
|
307
|
+
}
|
252
308
|
break;
|
253
309
|
}
|
254
310
|
case 'bottom': {
|
255
|
-
const height = this.computeTextHeight(CGSizeMake(tv.bounds.size.width, Number.MAX_SAFE_INTEGER));
|
311
|
+
const height = this.computeTextHeight(tv, CGSizeMake(tv.bounds.size.width, Number.MAX_SAFE_INTEGER));
|
256
312
|
let bottomCorrect = tv.bounds.size.height - top - bottom - height * tv.zoomScale;
|
257
313
|
bottomCorrect = bottomCorrect < 0.0 ? 0.0 : bottomCorrect;
|
258
|
-
|
314
|
+
inset = {
|
259
315
|
top: top + bottomCorrect,
|
260
316
|
left,
|
261
317
|
bottom,
|
@@ -264,6 +320,7 @@ export class Label extends LabelBase {
|
|
264
320
|
break;
|
265
321
|
}
|
266
322
|
}
|
323
|
+
return inset;
|
267
324
|
}
|
268
325
|
_requestLayoutOnTextChanged() {
|
269
326
|
if (this.mFixedSize === FixedSize.BOTH) {
|
@@ -275,6 +332,17 @@ export class Label extends LabelBase {
|
|
275
332
|
}
|
276
333
|
super._requestLayoutOnTextChanged();
|
277
334
|
}
|
335
|
+
_measureNativeView(width, widthMode, height, heightMode) {
|
336
|
+
const view = this.nativeTextViewProtected;
|
337
|
+
const nativeSize = view.textRectForBoundsLimitedToNumberOfLines(CGRectMake(0, 0, widthMode === 0 /* layout.UNSPECIFIED */
|
338
|
+
? Number.POSITIVE_INFINITY
|
339
|
+
: Utils.layout.toDeviceIndependentPixels(width), heightMode === 0 /* layout.UNSPECIFIED */
|
340
|
+
? Number.POSITIVE_INFINITY
|
341
|
+
: Utils.layout.toDeviceIndependentPixels(height)), view.numberOfLines).size;
|
342
|
+
nativeSize.width = Utils.layout.round(Utils.layout.toDevicePixels(nativeSize.width));
|
343
|
+
nativeSize.height = Utils.layout.round(Utils.layout.toDevicePixels(nativeSize.height));
|
344
|
+
return nativeSize;
|
345
|
+
}
|
278
346
|
onMeasure(widthMeasureSpec, heightMeasureSpec) {
|
279
347
|
const nativeView = this.nativeTextViewProtected;
|
280
348
|
if (nativeView) {
|
@@ -296,7 +364,10 @@ export class Label extends LabelBase {
|
|
296
364
|
}
|
297
365
|
}
|
298
366
|
const desiredSize = Utils.layout.measureNativeView(nativeView, width, widthMode, height, heightMode);
|
299
|
-
if (
|
367
|
+
// if (this.isUsingUITextView) {
|
368
|
+
// desiredSize.height += nativeView.textContainerInset.top + nativeView.textContainerInset.bottom;
|
369
|
+
// }
|
370
|
+
if (resetFont && !this.formattedText && !this.html) {
|
300
371
|
nativeView.font = resetFont;
|
301
372
|
}
|
302
373
|
const labelWidth = widthMode === Utils.layout.AT_MOST ? Math.min(desiredSize.width, width) : desiredSize.width;
|
@@ -310,16 +381,36 @@ export class Label extends LabelBase {
|
|
310
381
|
}
|
311
382
|
_onSizeChanged() {
|
312
383
|
super._onSizeChanged();
|
384
|
+
this.updateVerticalAlignment();
|
313
385
|
if (this.autoFontSize) {
|
314
386
|
this.updateAutoFontSize({ textView: this.nativeTextViewProtected });
|
315
387
|
}
|
316
388
|
}
|
389
|
+
// _htmlTappable = false;
|
390
|
+
// _htmlTapGestureRecognizer;
|
391
|
+
updateInteractionState(hasLink = false) {
|
392
|
+
this.nativeTextViewProtected.userInteractionEnabled = this._tappable || this.selectable || hasLink;
|
393
|
+
}
|
317
394
|
_setTappableState(tappable) {
|
318
395
|
if (this._tappable !== tappable) {
|
319
396
|
this._tappable = tappable;
|
320
|
-
|
321
|
-
|
397
|
+
if (this.isUsingUITextView) {
|
398
|
+
// we dont want the label gesture recognizer for linkTap
|
399
|
+
// so we override
|
400
|
+
}
|
401
|
+
else {
|
402
|
+
if (this._tappable && !this.mTapGestureRecognizer) {
|
403
|
+
this.mTapDelegate = UILabelLinkHandlerTapDelegateImpl.initWithOwner(new WeakRef(this));
|
404
|
+
// associate handler with menuItem or it will get collected by JSC.
|
405
|
+
this.mTapGestureRecognizer = LabelLinkGestureRecognizer.alloc().initWithDelegate(this.mTapDelegate);
|
406
|
+
this.nativeViewProtected.addGestureRecognizer(this.mTapGestureRecognizer);
|
407
|
+
}
|
408
|
+
else if (this.mTapGestureRecognizer) {
|
409
|
+
this.nativeViewProtected.removeGestureRecognizer(this.mTapGestureRecognizer);
|
410
|
+
}
|
411
|
+
}
|
322
412
|
}
|
413
|
+
this.updateInteractionState();
|
323
414
|
}
|
324
415
|
textViewShouldInteractWithURLInRangeInteraction(textView, url, characterRange, interaction) {
|
325
416
|
if (!this.formattedText?.spans) {
|
@@ -349,18 +440,24 @@ export class Label extends LabelBase {
|
|
349
440
|
return false;
|
350
441
|
}
|
351
442
|
_updateHTMLString(fontSize) {
|
443
|
+
const nativeView = this.nativeTextViewProtected;
|
352
444
|
if (!this.html) {
|
353
|
-
|
445
|
+
if (this.isUsingUITextView) {
|
446
|
+
nativeView.selectable = this.selectable === true;
|
447
|
+
}
|
354
448
|
this.attributedString = null;
|
355
449
|
}
|
356
450
|
else {
|
357
|
-
const font =
|
451
|
+
const font = nativeView.font;
|
452
|
+
const style = this.style;
|
358
453
|
if (!fontSize) {
|
359
454
|
fontSize = this.fontSize || font?.pointSize || 17;
|
360
455
|
}
|
361
|
-
const fontWeight =
|
362
|
-
const familyName =
|
363
|
-
|
456
|
+
const fontWeight = style.fontWeight;
|
457
|
+
const familyName = style.fontFamily || (style.fontInternal && style.fontInternal.fontFamily) || undefined;
|
458
|
+
// we need to pass color because initWithDataOptionsDocumentAttributesError
|
459
|
+
// will set a default color preventing the UITextView from applying its color
|
460
|
+
const params = {
|
364
461
|
text: this.html,
|
365
462
|
fontSize,
|
366
463
|
familyName,
|
@@ -368,22 +465,30 @@ export class Label extends LabelBase {
|
|
368
465
|
color: this.color,
|
369
466
|
letterSpacing: this.letterSpacing,
|
370
467
|
lineHeight: this.lineHeight,
|
371
|
-
textAlignment:
|
372
|
-
}
|
468
|
+
textAlignment: nativeView.textAlignment
|
469
|
+
};
|
470
|
+
if (!this.isUsingUITextView) {
|
471
|
+
Object.assign(params, {
|
472
|
+
useCustomLinkTag: true,
|
473
|
+
lineBreak: nativeView.lineBreakMode,
|
474
|
+
linkDecoration: this.linkUnderline ? 'underline' : undefined,
|
475
|
+
linkColor: this.linkColor
|
476
|
+
});
|
477
|
+
}
|
478
|
+
const result = createNativeAttributedString(params, this, this.autoFontSize, this.fontSizeRatio);
|
373
479
|
let hasLink = false;
|
374
480
|
if (result) {
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
481
|
+
hasLink = result.hasAttribute('CustomLinkAttribute');
|
482
|
+
}
|
483
|
+
this._setTappableState(hasLink);
|
484
|
+
this.updateInteractionState(hasLink);
|
485
|
+
if (this.isUsingUITextView) {
|
486
|
+
nativeView.selectable = this.selectable === true || hasLink;
|
381
487
|
}
|
382
|
-
this.nativeTextViewProtected.selectable = this.selectable === true || hasLink;
|
383
488
|
this.attributedString = result;
|
384
489
|
}
|
385
|
-
if (
|
386
|
-
|
490
|
+
if (nativeView) {
|
491
|
+
nativeView.attributedText = this.attributedString;
|
387
492
|
this._requestLayoutOnTextChanged();
|
388
493
|
}
|
389
494
|
}
|
@@ -406,12 +511,7 @@ export class Label extends LabelBase {
|
|
406
511
|
}
|
407
512
|
else {
|
408
513
|
if (this.formattedText || this.html) {
|
409
|
-
|
410
|
-
this.updateHTMLString();
|
411
|
-
}
|
412
|
-
else {
|
413
|
-
super._setNativeText();
|
414
|
-
}
|
514
|
+
this._setNativeText();
|
415
515
|
}
|
416
516
|
else {
|
417
517
|
this.nativeTextViewProtected.textColor = color;
|
@@ -419,62 +519,74 @@ export class Label extends LabelBase {
|
|
419
519
|
}
|
420
520
|
}
|
421
521
|
updateLinkTextAttributes() {
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
522
|
+
if (this.isUsingUITextView) {
|
523
|
+
const color = !this.linkColor || this.linkColor instanceof Color ? this.linkColor : new Color(this.linkColor);
|
524
|
+
const nativeView = this.nativeTextViewProtected;
|
525
|
+
let attributes = this.isUsingUITextView ? nativeView.linkTextAttributes : null;
|
526
|
+
if (!(attributes instanceof NSMutableDictionary)) {
|
527
|
+
this.defaultLinkTextAttributes = attributes;
|
528
|
+
attributes = NSMutableDictionary.new();
|
529
|
+
}
|
530
|
+
if (color) {
|
531
|
+
attributes.setValueForKey(color.ios, NSForegroundColorAttributeName);
|
532
|
+
if (this.linkUnderline !== false) {
|
533
|
+
attributes.setValueForKey(color.ios, NSUnderlineColorAttributeName);
|
534
|
+
}
|
535
|
+
else {
|
536
|
+
attributes.setValueForKey(UIColor.clearColor, NSUnderlineColorAttributeName);
|
537
|
+
}
|
538
|
+
}
|
539
|
+
else if (this.defaultLinkTextAttributes) {
|
540
|
+
attributes.setValueForKey(this.defaultLinkTextAttributes.objectForKey(NSForegroundColorAttributeName), NSForegroundColorAttributeName);
|
541
|
+
if (this.linkUnderline !== false) {
|
542
|
+
attributes.setValueForKey(this.defaultLinkTextAttributes.objectForKey(NSUnderlineColorAttributeName), NSUnderlineColorAttributeName);
|
543
|
+
}
|
544
|
+
else {
|
545
|
+
attributes.setValueForKey(UIColor.clearColor, NSUnderlineColorAttributeName);
|
546
|
+
}
|
433
547
|
}
|
434
548
|
else {
|
435
|
-
|
549
|
+
if (this.linkUnderline === false) {
|
550
|
+
attributes.setValueForKey(UIColor.clearColor, NSUnderlineColorAttributeName);
|
551
|
+
}
|
436
552
|
}
|
553
|
+
nativeView.linkTextAttributes = attributes;
|
437
554
|
}
|
438
555
|
else {
|
439
|
-
|
440
|
-
if (this.linkUnderline !== false) {
|
441
|
-
attributes.setValueForKey(this.defaultLinkTextAttributes.objectForKey(NSUnderlineColorAttributeName), NSUnderlineColorAttributeName);
|
442
|
-
}
|
443
|
-
else {
|
444
|
-
attributes.setValueForKey(UIColor.clearColor, NSUnderlineColorAttributeName);
|
445
|
-
}
|
556
|
+
this._setNativeText();
|
446
557
|
}
|
447
|
-
nativeView.linkTextAttributes = attributes;
|
448
558
|
}
|
449
|
-
[linkColorProperty.setNative](value) {
|
559
|
+
[_a = linkColorProperty.setNative](value) {
|
450
560
|
this.updateLinkTextAttributes();
|
451
561
|
}
|
452
562
|
[selectableProperty.setNative](value) {
|
453
|
-
this.nativeTextViewProtected
|
563
|
+
const nativeView = this.nativeTextViewProtected;
|
564
|
+
if (this.isUsingUITextView) {
|
565
|
+
nativeView.selectable = value;
|
566
|
+
}
|
567
|
+
this.updateInteractionState();
|
454
568
|
}
|
455
|
-
[linkUnderlineProperty.setNative](value) {
|
569
|
+
[_b = linkUnderlineProperty.setNative](value) {
|
456
570
|
this.updateLinkTextAttributes();
|
457
571
|
}
|
458
|
-
[
|
459
|
-
|
460
|
-
}
|
461
|
-
[_b = formattedTextProperty.setNative](value) {
|
572
|
+
[_c = htmlProperty.setNative](value) { }
|
573
|
+
[_d = formattedTextProperty.setNative](value) {
|
462
574
|
super[formattedTextProperty.setNative](value);
|
463
575
|
}
|
464
|
-
[
|
576
|
+
[_e = textProperty.setNative](value) {
|
465
577
|
super[textProperty.setNative](value);
|
466
578
|
}
|
467
|
-
[
|
579
|
+
[_f = letterSpacingProperty.setNative](value) {
|
468
580
|
super[letterSpacingProperty.setNative](value);
|
469
581
|
}
|
470
|
-
[
|
582
|
+
[_g = lineHeightProperty.setNative](value) {
|
471
583
|
super[lineHeightProperty.setNative](value);
|
472
584
|
}
|
473
|
-
// @
|
585
|
+
// @needSetText
|
474
586
|
// [colorProperty.setNative](value: number) {
|
475
587
|
// super[colorProperty.setNative](value);
|
476
588
|
// }
|
477
|
-
[
|
589
|
+
[_h = fontInternalProperty.setNative](value) {
|
478
590
|
const nativeView = this.nativeTextViewProtected;
|
479
591
|
const newFont = value instanceof Font ? value.getUIFont(nativeView.font) : value;
|
480
592
|
if (!this.formattedText && !this.html) {
|
@@ -482,7 +594,7 @@ export class Label extends LabelBase {
|
|
482
594
|
}
|
483
595
|
else if (newFont) {
|
484
596
|
if (!this.mCanChangeText) {
|
485
|
-
this.
|
597
|
+
this.mNeedSetText = true;
|
486
598
|
return;
|
487
599
|
}
|
488
600
|
this._setNativeText();
|
@@ -498,211 +610,146 @@ export class Label extends LabelBase {
|
|
498
610
|
this.updateAutoFontSize({ textView: this.nativeTextViewProtected, force: true });
|
499
611
|
}
|
500
612
|
}
|
501
|
-
_setSpannablesFontSizeWithRatio(ratio) {
|
502
|
-
const nativeView = this.nativeTextViewProtected;
|
503
|
-
const toChange = nativeView.attributedText instanceof NSMutableAttributedString
|
504
|
-
? nativeView.attributedText
|
505
|
-
: NSMutableAttributedString.alloc().initWithAttributedString(nativeView.attributedText);
|
506
|
-
let found = false;
|
507
|
-
toChange.enumerateAttributeInRangeOptionsUsingBlock(AttributeOriginalFontSize, { location: 0, length: nativeView.attributedText.length }, 0, (value, range, stop) => {
|
508
|
-
if (!value) {
|
509
|
-
return;
|
510
|
-
}
|
511
|
-
toChange.enumerateAttributeInRangeOptionsUsingBlock(NSFontAttributeName, range, 0, (value2, range, stop) => {
|
512
|
-
if (value2 && value * ratio !== value2.pointSize) {
|
513
|
-
const newFont = value2.fontWithSize(Math.round(value * ratio));
|
514
|
-
if (newFont) {
|
515
|
-
found = true;
|
516
|
-
toChange.removeAttributeRange(NSFontAttributeName, range);
|
517
|
-
toChange.addAttributeValueRange(NSFontAttributeName, newFont, range);
|
518
|
-
}
|
519
|
-
}
|
520
|
-
});
|
521
|
-
});
|
522
|
-
if (found) {
|
523
|
-
nativeView.attributedText = toChange;
|
524
|
-
}
|
525
|
-
}
|
526
613
|
_setNativeText() {
|
614
|
+
if (!this.mCanChangeText) {
|
615
|
+
this.mNeedSetText = true;
|
616
|
+
return;
|
617
|
+
}
|
618
|
+
// reset the fontSizeRatio or it could break attributedString sizes in collectionview
|
619
|
+
this.fontSizeRatio = 1;
|
527
620
|
if (this.html) {
|
528
621
|
this.updateHTMLString();
|
529
622
|
}
|
530
623
|
else {
|
531
624
|
super._setNativeText();
|
532
625
|
}
|
533
|
-
|
534
|
-
|
535
|
-
this.
|
626
|
+
this.updateVerticalAlignment();
|
627
|
+
if (this.autoFontSize) {
|
628
|
+
this.updateAutoFontSize({ textView: this.nativeTextViewProtected, force: true });
|
536
629
|
}
|
537
|
-
this.updateTextContainerInset();
|
538
630
|
this._requestLayoutOnTextChanged();
|
539
631
|
}
|
540
632
|
setTextDecorationAndTransform() {
|
541
633
|
const style = this.style;
|
542
|
-
const
|
543
|
-
|
544
|
-
|
545
|
-
|
546
|
-
|
547
|
-
|
548
|
-
|
549
|
-
case 'line-through':
|
550
|
-
dict.set(NSStrikethroughStyleAttributeName, 1 /* Single */);
|
551
|
-
break;
|
552
|
-
case 'underline line-through':
|
553
|
-
dict.set(NSUnderlineStyleAttributeName, 1 /* Single */);
|
554
|
-
dict.set(NSStrikethroughStyleAttributeName, 1 /* Single */);
|
555
|
-
break;
|
556
|
-
default:
|
557
|
-
throw new Error(`Invalid text decoration value: ${style.textDecoration}. Valid values are: 'none', 'underline', 'line-through', 'underline line-through'.`);
|
558
|
-
}
|
559
|
-
let paragraphStyle;
|
560
|
-
const createParagraphStyle = () => {
|
561
|
-
if (!paragraphStyle) {
|
562
|
-
paragraphStyle = NSMutableParagraphStyle.alloc().init();
|
563
|
-
paragraphStyle.alignment = this.nativeTextViewProtected.textAlignment;
|
564
|
-
// make sure a possible previously set text alignment setting is not lost when line height is specified
|
565
|
-
dict.set(NSParagraphStyleAttributeName, paragraphStyle);
|
566
|
-
}
|
567
|
-
};
|
568
|
-
if (style.letterSpacing !== 0 && this.nativeTextViewProtected.font) {
|
569
|
-
const kern = style.letterSpacing * this.nativeTextViewProtected.font.pointSize;
|
570
|
-
dict.set(NSKernAttributeName, kern);
|
571
|
-
createParagraphStyle();
|
572
|
-
}
|
573
|
-
// const isTextView = false;
|
574
|
-
if (style.lineHeight !== undefined) {
|
575
|
-
let lineHeight = style.lineHeight;
|
576
|
-
if (lineHeight === 0) {
|
577
|
-
lineHeight = 0.00001;
|
578
|
-
}
|
579
|
-
createParagraphStyle();
|
580
|
-
paragraphStyle.minimumLineHeight = lineHeight;
|
581
|
-
paragraphStyle.maximumLineHeight = lineHeight;
|
582
|
-
// } else if (isTextView) {
|
583
|
-
// createParagraphStyle();
|
584
|
-
}
|
585
|
-
const source = getTransformedText(isNullOrUndefined(this.text) ? '' : `${this.text}`, this.textTransform);
|
586
|
-
if (dict.size > 0) {
|
587
|
-
if (this.nativeTextViewProtected.font) {
|
588
|
-
dict.set(NSFontAttributeName, this.nativeTextViewProtected.font);
|
589
|
-
}
|
590
|
-
if (style.color) {
|
591
|
-
const color = !style.color || style.color instanceof Color ? style.color : new Color(style.color);
|
592
|
-
if (color) {
|
593
|
-
dict.set(NSForegroundColorAttributeName, color.ios);
|
594
|
-
}
|
634
|
+
const letterSpacing = style.letterSpacing ?? 0;
|
635
|
+
const lineHeight = style.lineHeight ?? -1;
|
636
|
+
let uiColor;
|
637
|
+
if (style.color) {
|
638
|
+
const color = !style.color || style.color instanceof Color ? style.color : new Color(style.color);
|
639
|
+
if (color) {
|
640
|
+
uiColor = color.ios;
|
595
641
|
}
|
596
|
-
const result = NSMutableAttributedString.alloc().initWithString(source);
|
597
|
-
result.setAttributesRange(dict, {
|
598
|
-
location: 0,
|
599
|
-
length: source.length
|
600
|
-
});
|
601
|
-
this.nativeTextViewProtected.attributedText = result;
|
602
|
-
}
|
603
|
-
else {
|
604
|
-
// Clear attributedText or text won't be affected.
|
605
|
-
this.nativeTextViewProtected.attributedText = undefined;
|
606
|
-
this.nativeTextViewProtected.text = source;
|
607
|
-
}
|
608
|
-
if (!style.color && majorVersion >= 13 && UIColor.labelColor) {
|
609
|
-
this._setColor(UIColor.labelColor);
|
610
642
|
}
|
643
|
+
const text = getTransformedText(isNullOrUndefined(this.text) ? '' : `${this.text}`, this.textTransform);
|
644
|
+
NSLabelUtils.setTextDecorationAndTransformOnViewTextTextDecorationLetterSpacingLineHeightColor(this.nativeTextViewProtected, text, this.style.textDecoration || '', letterSpacing, lineHeight, uiColor);
|
611
645
|
}
|
612
646
|
createFormattedTextNative(value) {
|
613
647
|
return createNativeAttributedString(value, this, this.autoFontSize, this.fontSizeRatio);
|
614
648
|
}
|
615
649
|
setFormattedTextDecorationAndTransform() {
|
650
|
+
const nativeView = this.nativeTextViewProtected;
|
616
651
|
const attrText = this.createFormattedTextNative(this.formattedText);
|
617
652
|
// we override parent class behavior because we apply letterSpacing and lineHeight on a per Span basis
|
618
|
-
if (majorVersion >= 13 && UIColor.labelColor) {
|
619
|
-
|
653
|
+
// if (majorVersion >= 13 && UIColor.labelColor) {
|
654
|
+
// this.nativeTextViewProtected.textColor = UIColor.labelColor;
|
655
|
+
// }
|
656
|
+
nativeView.attributedText = attrText;
|
657
|
+
}
|
658
|
+
updateTextViewContentInset(data) {
|
659
|
+
// const nativeView = this.nativeTextViewProtected as NSTextView;
|
660
|
+
// const contentInset = nativeView.contentInset;
|
661
|
+
// nativeView.contentInset = Object.assign(
|
662
|
+
// {
|
663
|
+
// top: contentInset.top,
|
664
|
+
// right: contentInset.right,
|
665
|
+
// bottom: contentInset.bottom,
|
666
|
+
// left: contentInset.left
|
667
|
+
// },
|
668
|
+
// data
|
669
|
+
// );
|
670
|
+
}
|
671
|
+
[_j = paddingTopProperty.setNative](value) {
|
672
|
+
if (this.isUsingUITextView) {
|
673
|
+
// this.updateTextViewContentInset({ top: Utils.layout.toDeviceIndependentPixels(this.effectivePaddingTop) });
|
674
|
+
}
|
675
|
+
else {
|
676
|
+
super[paddingTopProperty.setNative](value);
|
677
|
+
}
|
678
|
+
}
|
679
|
+
[_k = paddingRightProperty.setNative](value) {
|
680
|
+
if (this.isUsingUITextView) {
|
681
|
+
// this.updateTextViewContentInset({ right: Utils.layout.toDeviceIndependentPixels(this.effectivePaddingRight) });
|
682
|
+
}
|
683
|
+
else {
|
684
|
+
super[paddingRightProperty.setNative](value);
|
620
685
|
}
|
621
|
-
this.nativeTextViewProtected.attributedText = attrText;
|
622
686
|
}
|
623
|
-
[
|
624
|
-
|
625
|
-
|
626
|
-
|
627
|
-
|
687
|
+
[_l = paddingBottomProperty.setNative](value) {
|
688
|
+
if (this.isUsingUITextView) {
|
689
|
+
// this.updateTextViewContentInset({ bottom: Utils.layout.toDeviceIndependentPixels(this.effectivePaddingBottom) });
|
690
|
+
}
|
691
|
+
else {
|
692
|
+
super[paddingBottomProperty.setNative](value);
|
693
|
+
}
|
694
|
+
}
|
695
|
+
[_m = paddingLeftProperty.setNative](value) {
|
696
|
+
if (this.isUsingUITextView) {
|
697
|
+
// this.updateTextViewContentInset({ left: Utils.layout.toDeviceIndependentPixels(this.effectivePaddingLeft) });
|
698
|
+
}
|
699
|
+
else {
|
700
|
+
super[paddingLeftProperty.setNative](value);
|
701
|
+
}
|
628
702
|
}
|
629
|
-
[
|
630
|
-
this.
|
703
|
+
[_o = borderTopWidthProperty.setNative](value) {
|
704
|
+
if (this.isUsingUITextView) {
|
705
|
+
// this.updateTextViewContentInset({ left: Utils.layout.toDeviceIndependentPixels(this.effectivePaddingLeft) });
|
706
|
+
}
|
707
|
+
else {
|
708
|
+
super[borderTopWidthProperty.setNative](value);
|
709
|
+
}
|
631
710
|
}
|
632
|
-
[
|
633
|
-
|
634
|
-
|
635
|
-
|
636
|
-
|
711
|
+
[_p = borderRightWidthProperty.setNative](value) {
|
712
|
+
if (this.isUsingUITextView) {
|
713
|
+
// this.updateTextViewContentInset({ left: Utils.layout.toDeviceIndependentPixels(this.effectivePaddingLeft) });
|
714
|
+
}
|
715
|
+
else {
|
716
|
+
super[borderRightWidthProperty.setNative](value);
|
717
|
+
}
|
637
718
|
}
|
638
|
-
[
|
639
|
-
this.
|
640
|
-
|
641
|
-
[_l = paddingBottomProperty.getDefault]() {
|
642
|
-
return {
|
643
|
-
value: 0,
|
644
|
-
unit: 'px'
|
645
|
-
};
|
646
|
-
}
|
647
|
-
[_m = paddingBottomProperty.setNative](value) {
|
648
|
-
this.updateTextContainerInset();
|
649
|
-
}
|
650
|
-
[_o = paddingLeftProperty.getDefault]() {
|
651
|
-
return {
|
652
|
-
value: 0,
|
653
|
-
unit: 'px'
|
654
|
-
};
|
655
|
-
}
|
656
|
-
[paddingLeftProperty.setNative](value) {
|
657
|
-
this.updateTextContainerInset();
|
658
|
-
}
|
659
|
-
[borderTopWidthProperty.getDefault]() {
|
660
|
-
return {
|
661
|
-
value: 0,
|
662
|
-
unit: 'px'
|
663
|
-
};
|
664
|
-
}
|
665
|
-
[borderTopWidthProperty.setNative](value) {
|
666
|
-
this.updateTextContainerInset();
|
667
|
-
}
|
668
|
-
[borderRightWidthProperty.getDefault]() {
|
669
|
-
return {
|
670
|
-
value: 0,
|
671
|
-
unit: 'px'
|
672
|
-
};
|
673
|
-
}
|
674
|
-
[borderRightWidthProperty.setNative](value) {
|
675
|
-
this.updateTextContainerInset();
|
676
|
-
}
|
677
|
-
[borderBottomWidthProperty.getDefault]() {
|
678
|
-
return {
|
679
|
-
value: 0,
|
680
|
-
unit: 'px'
|
681
|
-
};
|
682
|
-
}
|
683
|
-
[borderBottomWidthProperty.setNative](value) {
|
684
|
-
this.updateTextContainerInset();
|
685
|
-
}
|
686
|
-
[borderLeftWidthProperty.getDefault]() {
|
687
|
-
return {
|
688
|
-
value: 0,
|
689
|
-
unit: 'px'
|
690
|
-
};
|
691
|
-
}
|
692
|
-
[borderLeftWidthProperty.setNative](value) {
|
693
|
-
this.updateTextContainerInset();
|
694
|
-
}
|
695
|
-
[_p = maxLinesProperty.setNative](value) {
|
696
|
-
if (!value || value === 'none') {
|
697
|
-
this.nativeViewProtected.textContainer.maximumNumberOfLines = 0;
|
719
|
+
[_q = borderBottomWidthProperty.setNative](value) {
|
720
|
+
if (this.isUsingUITextView) {
|
721
|
+
// this.updateTextViewContentInset({ left: Utils.layout.toDeviceIndependentPixels(this.effectivePaddingLeft) });
|
698
722
|
}
|
699
723
|
else {
|
700
|
-
|
724
|
+
super[borderBottomWidthProperty.setNative](value);
|
701
725
|
}
|
702
726
|
}
|
703
|
-
[
|
727
|
+
[_r = borderLeftWidthProperty.setNative](value) {
|
728
|
+
if (this.isUsingUITextView) {
|
729
|
+
// this.updateTextViewContentInset({ left: Utils.layout.toDeviceIndependentPixels(this.effectivePaddingLeft) });
|
730
|
+
}
|
731
|
+
else {
|
732
|
+
super[borderLeftWidthProperty.setNative](value);
|
733
|
+
}
|
734
|
+
}
|
735
|
+
[_s = maxLinesProperty.setNative](value) {
|
736
|
+
const numberLines = !value || value === 'none' ? 0 : typeof value === 'string' ? parseInt(value, 10) : value;
|
704
737
|
const nativeView = this.nativeTextViewProtected;
|
705
|
-
|
738
|
+
if (this.isUsingUITextView) {
|
739
|
+
nativeView.textContainer.maximumNumberOfLines = numberLines;
|
740
|
+
}
|
741
|
+
else {
|
742
|
+
nativeView.numberOfLines = numberLines;
|
743
|
+
}
|
744
|
+
}
|
745
|
+
[_t = lineBreakProperty.setNative](value) {
|
746
|
+
const nativeView = this.nativeTextViewProtected;
|
747
|
+
if (this.isUsingUITextView) {
|
748
|
+
nativeView.textContainer.lineBreakMode = lineBreakToLineBreakMode(value);
|
749
|
+
}
|
750
|
+
else {
|
751
|
+
nativeView.lineBreakMode = lineBreakToLineBreakMode(value);
|
752
|
+
}
|
706
753
|
}
|
707
754
|
[textShadowProperty.setNative](value) {
|
708
755
|
this.nativeTextViewProtected.layer.shadowOpacity = 1;
|
@@ -712,29 +759,45 @@ export class Label extends LabelBase {
|
|
712
759
|
this.nativeTextViewProtected.layer.shouldRasterize = true;
|
713
760
|
this.nativeTextViewProtected.layer.masksToBounds = false;
|
714
761
|
}
|
715
|
-
[
|
762
|
+
[_u = whiteSpaceProperty.setNative](value) {
|
716
763
|
const nativeView = this.nativeTextViewProtected;
|
717
764
|
// only if no lineBreak
|
718
|
-
if (!this.lineBreak) {
|
765
|
+
// if (!this.lineBreak) {
|
766
|
+
if (this.isUsingUITextView) {
|
719
767
|
nativeView.textContainer.lineBreakMode = whiteSpaceToLineBreakMode(value);
|
720
768
|
if (!this.maxLines) {
|
721
769
|
if (value === 'normal') {
|
722
|
-
|
770
|
+
nativeView.textContainer.maximumNumberOfLines = 0;
|
771
|
+
}
|
772
|
+
else {
|
773
|
+
nativeView.textContainer.maximumNumberOfLines = 1;
|
774
|
+
}
|
775
|
+
}
|
776
|
+
}
|
777
|
+
else {
|
778
|
+
nativeView.lineBreakMode = whiteSpaceToLineBreakMode(value);
|
779
|
+
if (!this.maxLines) {
|
780
|
+
if (value === 'normal') {
|
781
|
+
nativeView.numberOfLines = 0;
|
723
782
|
}
|
724
783
|
else {
|
725
|
-
|
784
|
+
nativeView.numberOfLines = 1;
|
726
785
|
}
|
727
786
|
}
|
728
787
|
}
|
788
|
+
// }
|
729
789
|
}
|
730
790
|
updateAutoFontSize({ textView, width, height, force = false, onlyMeasure = false }) {
|
791
|
+
if (!this.mCanUpdateAutoFontSize) {
|
792
|
+
this.mNeedAutoFontSizeComputation = true;
|
793
|
+
}
|
731
794
|
let currentFont;
|
732
795
|
if (textView && this.autoFontSize) {
|
733
796
|
if ((!textView.attributedText && !textView.text) ||
|
734
797
|
(width === undefined && height === undefined && CGSizeEqualToSize(textView.bounds.size, CGSizeZero))) {
|
735
798
|
return currentFont;
|
736
799
|
}
|
737
|
-
const textViewSize = textView.
|
800
|
+
const textViewSize = NSLabelUtils.insetWithRectUIEdgeInsets(textView.bounds, textView.padding).size;
|
738
801
|
const fixedWidth = Math.floor(width !== undefined ? width : textViewSize.width);
|
739
802
|
const fixedHeight = Math.floor(height !== undefined ? height : textViewSize.height);
|
740
803
|
if (fixedWidth === 0 || fixedHeight === 0) {
|
@@ -750,14 +813,14 @@ export class Label extends LabelBase {
|
|
750
813
|
}
|
751
814
|
currentFont = textView.font;
|
752
815
|
this.mLastAutoSizeKey = autoSizeKey;
|
753
|
-
const nbLines = textView.textContainer.
|
816
|
+
const nbLines = textView instanceof UITextView ? textView.textContainer?.maximumNumberOfLines : textView.numberOfLines;
|
754
817
|
// we need to reset verticalTextAlignment or computation will be wrong
|
755
|
-
this.
|
818
|
+
// this.updateVerticalAlignment(false);
|
756
819
|
let expectSize;
|
757
820
|
const stepSize = this.autoFontSizeStep || 2;
|
758
821
|
const updateFontSize = (font) => {
|
759
822
|
if (this.formattedText || this.html) {
|
760
|
-
|
823
|
+
NSLabelUtils.updateFontRatioRatio(textView, font.pointSize / fontSize);
|
761
824
|
}
|
762
825
|
else {
|
763
826
|
textView.font = font;
|
@@ -794,7 +857,7 @@ export class Label extends LabelBase {
|
|
794
857
|
}
|
795
858
|
else {
|
796
859
|
const maxFontSize = this.maxFontSize || 200;
|
797
|
-
while (expectSize.height < fixedHeight
|
860
|
+
while ((expectSize.height < fixedHeight || expectSize.width < fixedWidth) && expectFont.pointSize < maxFontSize) {
|
798
861
|
const newFont = expectFont.fontWithSize(expectFont.pointSize + stepSize);
|
799
862
|
updateFontSize(newFont);
|
800
863
|
size();
|
@@ -802,9 +865,8 @@ export class Label extends LabelBase {
|
|
802
865
|
expectFont = newFont;
|
803
866
|
}
|
804
867
|
else {
|
805
|
-
|
806
|
-
|
807
|
-
}
|
868
|
+
// we need to restore old font
|
869
|
+
updateFontSize(expectFont);
|
808
870
|
break;
|
809
871
|
}
|
810
872
|
}
|
@@ -812,7 +874,7 @@ export class Label extends LabelBase {
|
|
812
874
|
if (!onlyMeasure) {
|
813
875
|
this.fontSizeRatio = expectFont.pointSize / fontSize;
|
814
876
|
}
|
815
|
-
this.
|
877
|
+
this.updateVerticalAlignment();
|
816
878
|
}
|
817
879
|
return currentFont;
|
818
880
|
}
|
@@ -831,60 +893,87 @@ export class Label extends LabelBase {
|
|
831
893
|
}
|
832
894
|
}
|
833
895
|
[verticalTextAlignmentProperty.setNative](value) {
|
834
|
-
this.
|
896
|
+
// this.nativeTextViewProtected.verticalTextAlignment = value;
|
897
|
+
this.updateVerticalAlignment();
|
835
898
|
}
|
836
899
|
}
|
837
900
|
Label.DTCORETEXT_INIT = false;
|
838
901
|
__decorate([
|
839
|
-
|
840
|
-
|
902
|
+
profile
|
903
|
+
], Label.prototype, "createNativeView", null);
|
904
|
+
__decorate([
|
905
|
+
profile
|
906
|
+
], Label.prototype, "initNativeView", null);
|
907
|
+
__decorate([
|
908
|
+
needSetText
|
841
909
|
], Label.prototype, _a, null);
|
842
910
|
__decorate([
|
843
|
-
|
844
|
-
needAutoFontSizeComputation
|
911
|
+
needSetText
|
845
912
|
], Label.prototype, _b, null);
|
846
913
|
__decorate([
|
914
|
+
needSetText,
|
847
915
|
needAutoFontSizeComputation
|
848
916
|
], Label.prototype, _c, null);
|
849
917
|
__decorate([
|
850
|
-
|
918
|
+
needSetText,
|
851
919
|
needAutoFontSizeComputation
|
852
920
|
], Label.prototype, _d, null);
|
853
921
|
__decorate([
|
854
|
-
|
855
|
-
needAutoFontSizeComputation
|
922
|
+
needSetText
|
856
923
|
], Label.prototype, _e, null);
|
857
924
|
__decorate([
|
925
|
+
needSetText,
|
858
926
|
needAutoFontSizeComputation
|
859
927
|
], Label.prototype, _f, null);
|
860
928
|
__decorate([
|
929
|
+
needSetText,
|
861
930
|
needAutoFontSizeComputation
|
862
931
|
], Label.prototype, _g, null);
|
863
932
|
__decorate([
|
864
933
|
needAutoFontSizeComputation
|
865
934
|
], Label.prototype, _h, null);
|
866
935
|
__decorate([
|
867
|
-
|
936
|
+
profile
|
937
|
+
], Label.prototype, "_setNativeText", null);
|
938
|
+
__decorate([
|
939
|
+
needAutoFontSizeComputation,
|
940
|
+
needUpdateVerticalAlignment
|
868
941
|
], Label.prototype, _j, null);
|
869
942
|
__decorate([
|
870
|
-
needAutoFontSizeComputation
|
943
|
+
needAutoFontSizeComputation,
|
944
|
+
needUpdateVerticalAlignment
|
871
945
|
], Label.prototype, _k, null);
|
872
946
|
__decorate([
|
873
|
-
needAutoFontSizeComputation
|
947
|
+
needAutoFontSizeComputation,
|
948
|
+
needUpdateVerticalAlignment
|
874
949
|
], Label.prototype, _l, null);
|
875
950
|
__decorate([
|
876
|
-
needAutoFontSizeComputation
|
951
|
+
needAutoFontSizeComputation,
|
952
|
+
needUpdateVerticalAlignment
|
877
953
|
], Label.prototype, _m, null);
|
878
954
|
__decorate([
|
879
|
-
needAutoFontSizeComputation
|
955
|
+
needAutoFontSizeComputation,
|
956
|
+
needUpdateVerticalAlignment
|
880
957
|
], Label.prototype, _o, null);
|
881
958
|
__decorate([
|
882
|
-
needAutoFontSizeComputation
|
959
|
+
needAutoFontSizeComputation,
|
960
|
+
needUpdateVerticalAlignment
|
883
961
|
], Label.prototype, _p, null);
|
884
962
|
__decorate([
|
885
|
-
needAutoFontSizeComputation
|
963
|
+
needAutoFontSizeComputation,
|
964
|
+
needUpdateVerticalAlignment
|
886
965
|
], Label.prototype, _q, null);
|
887
966
|
__decorate([
|
888
|
-
needAutoFontSizeComputation
|
967
|
+
needAutoFontSizeComputation,
|
968
|
+
needUpdateVerticalAlignment
|
889
969
|
], Label.prototype, _r, null);
|
970
|
+
__decorate([
|
971
|
+
needAutoFontSizeComputation
|
972
|
+
], Label.prototype, _s, null);
|
973
|
+
__decorate([
|
974
|
+
needAutoFontSizeComputation
|
975
|
+
], Label.prototype, _t, null);
|
976
|
+
__decorate([
|
977
|
+
needAutoFontSizeComputation
|
978
|
+
], Label.prototype, _u, null);
|
890
979
|
//# sourceMappingURL=label.ios.js.map
|