@nativescript-community/ui-label 1.1.23 → 1.2.1

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.
Files changed (33) hide show
  1. package/CHANGELOG.md +35 -0
  2. package/label.android.d.ts +0 -1
  3. package/label.android.js +29 -9
  4. package/label.ios.d.ts +6 -9
  5. package/label.ios.js +91 -223
  6. package/package.json +3 -3
  7. package/platforms/android/include.gradle +1 -1
  8. package/platforms/android/native-api-usage.json +15 -0
  9. package/pnpm-global/5/node_modules/.modules.yaml +0 -22
  10. package/pnpm-global/5/node_modules/.pnpm/@nativescript-community+text@1.4.11/node_modules/@nativescript-community/text/CHANGELOG.md +0 -212
  11. package/pnpm-global/5/node_modules/.pnpm/@nativescript-community+text@1.4.11/node_modules/@nativescript-community/text/LICENSE +0 -201
  12. package/pnpm-global/5/node_modules/.pnpm/@nativescript-community+text@1.4.11/node_modules/@nativescript-community/text/README.md +0 -14
  13. package/pnpm-global/5/node_modules/.pnpm/@nativescript-community+text@1.4.11/node_modules/@nativescript-community/text/index-common.d.ts +0 -40
  14. package/pnpm-global/5/node_modules/.pnpm/@nativescript-community+text@1.4.11/node_modules/@nativescript-community/text/index-common.js +0 -208
  15. package/pnpm-global/5/node_modules/.pnpm/@nativescript-community+text@1.4.11/node_modules/@nativescript-community/text/index.android.d.ts +0 -27
  16. package/pnpm-global/5/node_modules/.pnpm/@nativescript-community+text@1.4.11/node_modules/@nativescript-community/text/index.android.js +0 -298
  17. package/pnpm-global/5/node_modules/.pnpm/@nativescript-community+text@1.4.11/node_modules/@nativescript-community/text/index.d.ts +0 -1
  18. package/pnpm-global/5/node_modules/.pnpm/@nativescript-community+text@1.4.11/node_modules/@nativescript-community/text/index.ios.d.ts +0 -14
  19. package/pnpm-global/5/node_modules/.pnpm/@nativescript-community+text@1.4.11/node_modules/@nativescript-community/text/index.ios.js +0 -189
  20. package/pnpm-global/5/node_modules/.pnpm/@nativescript-community+text@1.4.11/node_modules/@nativescript-community/text/index.js +0 -25
  21. package/pnpm-global/5/node_modules/.pnpm/@nativescript-community+text@1.4.11/node_modules/@nativescript-community/text/package.json +0 -34
  22. package/pnpm-global/5/node_modules/.pnpm/@nativescript-community+text@1.4.11/node_modules/@nativescript-community/text/platforms/android/AndroidManifest.xml +0 -3
  23. package/pnpm-global/5/node_modules/.pnpm/@nativescript-community+text@1.4.11/node_modules/@nativescript-community/text/platforms/android/java/com/nativescript/text/BaselineAdjustedSpan.java +0 -71
  24. package/pnpm-global/5/node_modules/.pnpm/@nativescript-community+text@1.4.11/node_modules/@nativescript-community/text/platforms/android/java/com/nativescript/text/CustomBackgroundSpan.java +0 -70
  25. package/pnpm-global/5/node_modules/.pnpm/@nativescript-community+text@1.4.11/node_modules/@nativescript-community/text/platforms/android/java/com/nativescript/text/CustomTypefaceSpan.java +0 -37
  26. package/pnpm-global/5/node_modules/.pnpm/@nativescript-community+text@1.4.11/node_modules/@nativescript-community/text/platforms/android/java/com/nativescript/text/Font.java +0 -431
  27. package/pnpm-global/5/node_modules/.pnpm/@nativescript-community+text@1.4.11/node_modules/@nativescript-community/text/platforms/android/java/com/nativescript/text/HeightSpan.java +0 -81
  28. package/pnpm-global/5/node_modules/.pnpm/@nativescript-community+text@1.4.11/node_modules/@nativescript-community/text/platforms/android/java/com/nativescript/text/HtmlToSpannedConverter.java +0 -690
  29. package/pnpm-global/5/node_modules/.pnpm/@nativescript-community+text@1.4.11/node_modules/@nativescript-community/text/platforms/android/java/com/nativescript/text/URLSpanNoUnderline.java +0 -24
  30. package/pnpm-global/5/node_modules/.pnpm/@nativescript-community+text@1.4.11/node_modules/@nativescript-community/text/typings/DTCoreText.ios.d.ts +0 -22
  31. package/pnpm-global/5/node_modules/.pnpm/@nativescript-community+text@1.4.11/node_modules/@nativescript-community/text/typings/android.d.ts +0 -32
  32. package/pnpm-global/5/node_modules/.pnpm/lock.yaml +0 -13
  33. package/pnpm-global/5/pnpm-lock.yaml +0 -13
package/CHANGELOG.md CHANGED
@@ -3,6 +3,41 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [1.2.1](https://github.com/nativescript-community/ui-label/compare/v1.2.0...v1.2.1) (2022-01-02)
7
+
8
+ **Note:** Version bump only for package @nativescript-community/ui-label
9
+
10
+
11
+
12
+
13
+
14
+ # [1.2.0](https://github.com/nativescript-community/ui-label/compare/v1.1.25...v1.2.0) (2021-10-20)
15
+
16
+
17
+ ### Features
18
+
19
+ * **android:** native-api-usage ([40d28dd](https://github.com/nativescript-community/ui-label/commit/40d28dd648d993f1a7d844c677e20e8dfb1d67c0))
20
+
21
+
22
+
23
+
24
+
25
+ ## [1.1.25](https://github.com/nativescript-community/ui-label/compare/v1.1.24...v1.1.25) (2021-08-09)
26
+
27
+ **Note:** Version bump only for package @nativescript-community/ui-label
28
+
29
+
30
+
31
+
32
+
33
+ ## [1.1.24](https://github.com/nativescript-community/ui-label/compare/v1.1.23...v1.1.24) (2021-08-09)
34
+
35
+ **Note:** Version bump only for package @nativescript-community/ui-label
36
+
37
+
38
+
39
+
40
+
6
41
  ## [1.1.23](https://github.com/nativescript-community/ui-label/compare/v1.1.22...v1.1.23) (2021-08-08)
7
42
 
8
43
  **Note:** Version bump only for package @nativescript-community/ui-label
@@ -44,7 +44,6 @@ declare abstract class LabelBase extends View implements LabelViewDefinition {
44
44
  selectable: boolean;
45
45
  _isSingleLine: boolean;
46
46
  text: string;
47
- spannableStringBuilder: globalAndroid.text.SpannableStringBuilder;
48
47
  formattedText: FormattedString;
49
48
  get nativeTextViewProtected(): any;
50
49
  _setTappableState(value: boolean): void;
package/label.android.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { LightFormattedString, createNativeAttributedString, cssProperty, overrideSpanAndFormattedStringEnabled, verticalTextAlignmentProperty } from '@nativescript-community/text';
2
- import { CSSType, FormattedString, Observable, Property, Span, View, booleanConverter, profile } from '@nativescript/core';
2
+ import { CSSType, Device, FormattedString, Observable, Property, Span, View, booleanConverter, profile } from '@nativescript/core';
3
3
  import { Color } from '@nativescript/core/color';
4
4
  import { Font } from '@nativescript/core/ui/styling/font';
5
5
  import { Length, colorProperty, fontInternalProperty, fontSizeProperty, paddingBottomProperty, paddingLeftProperty, paddingRightProperty, paddingTopProperty } from '@nativescript/core/ui/styling/style-properties';
@@ -7,8 +7,10 @@ import { letterSpacingProperty, textAlignmentProperty, textDecorationProperty, t
7
7
  import { lineHeightProperty } from '@nativescript/core/ui/text-base/text-base-common';
8
8
  import { layout } from '@nativescript/core/utils/utils';
9
9
  import { autoFontSizeProperty, lineBreakProperty, maxLinesProperty, selectableProperty, textShadowProperty } from './label-common';
10
+ import lazy from '@nativescript/core/utils/lazy';
10
11
  export { createNativeAttributedString, enableIOSDTCoreText } from '@nativescript-community/text';
11
12
  export * from './label-common';
13
+ const sdkVersion = lazy(() => parseInt(Device.sdkVersion, 10));
12
14
  let TextView;
13
15
  const CHILD_SPAN = 'Span';
14
16
  const CHILD_FORMATTED_TEXT = 'formattedText';
@@ -357,7 +359,18 @@ export class Label extends LabelBase {
357
359
  }
358
360
  [textAlignmentProperty.setNative](value) {
359
361
  const view = this.nativeTextViewProtected;
360
- view.setGravity(getHorizontalGravity(value) | getVerticalGravity(this.verticalTextAlignment));
362
+ if (android.os.Build.VERSION.SDK_INT >= 25) {
363
+ if (value === 'justify') {
364
+ view.setJustificationMode(android.text.Layout.JUSTIFICATION_MODE_INTER_WORD);
365
+ }
366
+ else {
367
+ view.setJustificationMode(android.text.Layout.JUSTIFICATION_MODE_NONE);
368
+ view.setGravity(getHorizontalGravity(value) | getVerticalGravity(this.verticalTextAlignment));
369
+ }
370
+ }
371
+ else {
372
+ view.setGravity(getHorizontalGravity(value) | getVerticalGravity(this.verticalTextAlignment));
373
+ }
361
374
  }
362
375
  [colorProperty.setNative](value) {
363
376
  const color = !value || value instanceof Color ? value : new Color(value);
@@ -377,10 +390,21 @@ export class Label extends LabelBase {
377
390
  }
378
391
  }
379
392
  [lineHeightProperty.setNative](value) {
380
- this.nativeTextViewProtected.setLineSpacing(value * layout.getDisplayDensity(), 1);
393
+ if (sdkVersion() >= 28) {
394
+ this.nativeTextViewProtected.setLineHeight(value * layout.getDisplayDensity());
395
+ }
396
+ else {
397
+ const fontHeight = this.nativeTextViewProtected.getPaint().getFontMetricsInt(null);
398
+ this.nativeTextViewProtected.setLineSpacing(value * layout.getDisplayDensity() - fontHeight, 1);
399
+ }
381
400
  }
382
401
  [fontInternalProperty.setNative](value) {
383
- this.nativeTextViewProtected.setTypeface(value instanceof Font ? value.getAndroidTypeface() : value);
402
+ const androidFont = value instanceof Font ? value.getAndroidTypeface() : value;
403
+ this.nativeTextViewProtected.setTypeface(androidFont);
404
+ if (this.lineHeight && sdkVersion() < 28) {
405
+ const fontHeight = this.nativeTextViewProtected.getPaint().getFontMetricsInt(null);
406
+ this.nativeTextViewProtected.setLineSpacing(this.lineHeight * layout.getDisplayDensity() - fontHeight, 1);
407
+ }
384
408
  }
385
409
  [textDecorationProperty.setNative](value) {
386
410
  switch (value) {
@@ -499,11 +523,7 @@ export class Label extends LabelBase {
499
523
  return;
500
524
  }
501
525
  let transformedText = null;
502
- if (this.spannableStringBuilder) {
503
- transformedText = this.spannableStringBuilder;
504
- // textProperty.nativeValueChange(this, this.html === null || this.html === undefined ? '' : this.html);
505
- }
506
- else if (this.html) {
526
+ if (this.html) {
507
527
  transformedText = this.createHTMLString();
508
528
  textProperty.nativeValueChange(this, this.html === null || this.html === undefined ? '' : this.html);
509
529
  }
package/label.ios.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { CoreTypes, FormattedString, Span } from '@nativescript/core';
1
+ import { CoreTypes, FormattedString } from '@nativescript/core';
2
2
  import { LabelBase } from './label-common';
3
3
  export { createNativeAttributedString, enableIOSDTCoreText } from '@nativescript-community/text';
4
4
  export * from './label-common';
@@ -6,8 +6,6 @@ declare module '@nativescript/core/ui/text-base' {
6
6
  interface TextBase {
7
7
  _requestLayoutOnTextChanged(): any;
8
8
  _setNativeText(): any;
9
- createMutableStringForSpan?(span: any, text: any): NSMutableAttributedString;
10
- createNSMutableAttributedString?(formattedString: FormattedString): NSMutableAttributedString;
11
9
  }
12
10
  }
13
11
  export declare function getTransformedText(text: string, textTransform: CoreTypes.TextTransformType): string;
@@ -18,7 +16,6 @@ export declare class Label extends LabelBase {
18
16
  attributedString: NSMutableAttributedString;
19
17
  private _delegate;
20
18
  static DTCORETEXT_INIT: boolean;
21
- constructor();
22
19
  createNativeView(): UITextView;
23
20
  initNativeView(): void;
24
21
  disposeNativeView(): void;
@@ -30,6 +27,7 @@ export declare class Label extends LabelBase {
30
27
  private _fixedSize;
31
28
  _requestLayoutOnTextChanged(): void;
32
29
  onMeasure(widthMeasureSpec: number, heightMeasureSpec: number): void;
30
+ _onSizeChanged(): void;
33
31
  textViewShouldInteractWithURLInRangeInteraction?(textView: UITextView, URL: NSURL, characterRange: NSRange, interaction: UITextItemInteraction): boolean;
34
32
  _updateHTMLString(fontSize?: number): void;
35
33
  updateHTMLString(fontSize?: number): void;
@@ -37,10 +35,9 @@ export declare class Label extends LabelBase {
37
35
  _setSpannablesFontSizeWithRatio(ratio: any): void;
38
36
  _setNativeText(): void;
39
37
  setTextDecorationAndTransform(): void;
40
- currentMaxFontSize: number;
41
- createNSMutableAttributedString(formattedString: FormattedString): NSMutableAttributedString;
42
- createMutableStringForSpan(span: Span, text: string): NSMutableAttributedString;
38
+ createFormattedTextNative(value: FormattedString): any;
39
+ setFormattedTextDecorationAndTransform(): void;
43
40
  fontSizeRatio: number;
44
- needsAutoFontSize: boolean;
45
- textViewDidChange(textView: UITextView, width?: any, height?: any): void;
41
+ _lastAutoSizeKey: string;
42
+ textViewDidChange(textView: UITextView, width?: any, height?: any, force?: boolean): void;
46
43
  }
package/label.ios.js CHANGED
@@ -1,9 +1,9 @@
1
1
  var _a, _b, _c, _d;
2
- import { computeBaseLineOffset, createNativeAttributedString, usingIOSDTCoreText, verticalTextAlignmentProperty } from '@nativescript-community/text';
2
+ import { createNativeAttributedString, verticalTextAlignmentProperty } from '@nativescript-community/text';
3
3
  import { Color, Font, View } from '@nativescript/core';
4
4
  import { borderBottomWidthProperty, borderLeftWidthProperty, borderRightWidthProperty, borderTopWidthProperty, fontInternalProperty, paddingBottomProperty, paddingLeftProperty, paddingRightProperty, paddingTopProperty } from '@nativescript/core/ui/styling/style-properties';
5
- import { formattedTextProperty, letterSpacingProperty, textDecorationProperty, whiteSpaceProperty } from '@nativescript/core/ui/text-base';
6
- import { getClosestPropertyValue, lineHeightProperty } from '@nativescript/core/ui/text-base/text-base-common';
5
+ import { formattedTextProperty, letterSpacingProperty, whiteSpaceProperty } from '@nativescript/core/ui/text-base';
6
+ import { lineHeightProperty } from '@nativescript/core/ui/text-base/text-base-common';
7
7
  import { isNullOrUndefined, isString } from '@nativescript/core/utils/types';
8
8
  import { iOSNativeHelper, layout } from '@nativescript/core/utils/utils';
9
9
  import { LabelBase, autoFontSizeProperty, htmlProperty, lineBreakProperty, linkColorProperty, linkUnderlineProperty, maxLinesProperty, needFormattedStringComputation, selectableProperty, textShadowProperty } from './label-common';
@@ -79,7 +79,7 @@ var LabelUITextViewDelegateImpl = /** @class */ (function (_super) {
79
79
  LabelUITextViewDelegateImpl.prototype.textViewDidChange = function (textView) {
80
80
  var owner = this._owner.get();
81
81
  if (owner) {
82
- owner.textViewDidChange(textView);
82
+ owner.textViewDidChange(textView, undefined, undefined, true);
83
83
  }
84
84
  };
85
85
  LabelUITextViewDelegateImpl.ObjCProtocols = [UITextViewDelegate];
@@ -103,15 +103,16 @@ var ObserverClass = /** @class */ (function (_super) {
103
103
  }(NSObject));
104
104
  export class Label extends LabelBase {
105
105
  constructor() {
106
- super();
107
- this.currentMaxFontSize = 0;
106
+ super(...arguments);
108
107
  this.fontSizeRatio = 1;
109
- this.needsAutoFontSize = false;
110
- // if (iOSUseDTCoreText && !Label.DTCORETEXT_INIT) {
111
- // Label.DTCORETEXT_INIT = true;
112
- // DTCoreTextFontDescriptor.asyncPreloadFontLookupTable();
113
- // }
114
108
  }
109
+ // constructor() {
110
+ // super();
111
+ // if (iOSUseDTCoreText && !Label.DTCORETEXT_INIT) {
112
+ // Label.DTCORETEXT_INIT = true;
113
+ // DTCoreTextFontDescriptor.asyncPreloadFontLookupTable();
114
+ // }
115
+ // }
115
116
  createNativeView() {
116
117
  const view = UITextView.new();
117
118
  if (!view.font) {
@@ -124,13 +125,10 @@ export class Label extends LabelBase {
124
125
  view.backgroundColor = UIColor.clearColor;
125
126
  view.userInteractionEnabled = true;
126
127
  view.dataDetectorTypes = -1 /* All */;
127
- view.textContainerInset = {
128
- top: 0,
129
- left: 0,
130
- bottom: 0,
131
- right: 0
132
- };
133
- view.textContainer.lineFragmentPadding = 0; // to remove left padding
128
+ view.textContainerInset = UIEdgeInsetsZero;
129
+ view.textContainer.lineFragmentPadding = 0;
130
+ // ignore font leading just like UILabel does
131
+ view.layoutManager.usesFontLeading = false;
134
132
  // view.textContainer.lineBreakMode = NSLineBreakMode.ByCharWrapping;
135
133
  return view;
136
134
  }
@@ -141,12 +139,6 @@ export class Label extends LabelBase {
141
139
  this._observer['_owner'] = new WeakRef(this);
142
140
  this.nativeViewProtected.addObserverForKeyPathOptionsContext(this._observer, 'contentSize', 1 /* New */, null);
143
141
  this.nativeViewProtected.attributedText = this.attributedString;
144
- // this.htmlText = null;
145
- // this.needsHTMLUpdate = false;
146
- // this.updatingHTML = false;
147
- // if (this.htmlText && this.needsHTMLUpdate) {
148
- // this.updateHTMLString();
149
- // }
150
142
  }
151
143
  disposeNativeView() {
152
144
  this._delegate = null;
@@ -170,25 +162,31 @@ export class Label extends LabelBase {
170
162
  }
171
163
  computeTextHeight(size) {
172
164
  const tv = this.nativeTextViewProtected;
173
- const font = this.nativeViewProtected.font;
174
- const text = this.formattedText || this.html ? tv.attributedText : tv.text;
175
- if (text instanceof NSAttributedString) {
176
- const rect = text.boundingRectWithSizeOptionsContext(size, 1 /* UsesLineFragmentOrigin */, null);
177
- return rect.size.height;
178
- }
179
- return NSString.stringWithString(text).sizeWithFontConstrainedToSizeLineBreakMode(font, size, tv.textContainer.lineBreakMode).height;
165
+ const oldtextContainerInset = tv.textContainerInset;
166
+ tv.textContainerInset = UIEdgeInsetsZero;
167
+ // if (tv.attributedText) {
168
+ // const result = tv.attributedText.boundingRectWithSizeOptionsContext(
169
+ // size,
170
+ // NSStringDrawingOptions.UsesLineFragmentOrigin | NSStringDrawingOptions.UsesFontLeading,
171
+ // null
172
+ // );
173
+ // return Math.round(CGRectGetHeight(result));
174
+ // }
175
+ const result = tv.sizeThatFits(size);
176
+ tv.textContainerInset = oldtextContainerInset;
177
+ return result.height;
180
178
  }
181
179
  updateTextContainerInset(applyVerticalTextAlignment = true) {
182
- // if (!this.text) {
183
- // return;
184
- // }
180
+ var _e, _f;
185
181
  const tv = this.nativeTextViewProtected;
186
182
  const top = layout.toDeviceIndependentPixels(this.effectivePaddingTop + this.effectiveBorderTopWidth);
187
183
  const right = layout.toDeviceIndependentPixels(this.effectivePaddingRight + this.effectiveBorderRightWidth);
188
184
  const bottom = layout.toDeviceIndependentPixels(this.effectivePaddingBottom + this.effectiveBorderBottomWidth);
189
185
  const left = layout.toDeviceIndependentPixels(this.effectivePaddingLeft + this.effectiveBorderLeftWidth);
190
- if (!applyVerticalTextAlignment || !this.verticalTextAlignment) {
191
- this.nativeViewProtected.textContainerInset = {
186
+ if (!applyVerticalTextAlignment ||
187
+ !this.verticalTextAlignment ||
188
+ (((_e = tv.text) === null || _e === void 0 ? void 0 : _e.length) === 0 && ((_f = tv.attributedText) === null || _f === void 0 ? void 0 : _f.length) === 0)) {
189
+ tv.textContainerInset = {
192
190
  top,
193
191
  left,
194
192
  bottom,
@@ -199,7 +197,7 @@ export class Label extends LabelBase {
199
197
  switch (this.verticalTextAlignment) {
200
198
  case 'initial': // not supported
201
199
  case 'top':
202
- this.nativeViewProtected.textContainerInset = {
200
+ tv.textContainerInset = {
203
201
  top,
204
202
  left,
205
203
  bottom,
@@ -211,7 +209,7 @@ export class Label extends LabelBase {
211
209
  const height = this.computeTextHeight(CGSizeMake(tv.bounds.size.width, 10000));
212
210
  let topCorrect = (tv.bounds.size.height - top - bottom - height * tv.zoomScale) / 2.0;
213
211
  topCorrect = topCorrect < 0.0 ? 0.0 : topCorrect;
214
- this.nativeViewProtected.textContainerInset = {
212
+ tv.textContainerInset = {
215
213
  top: top + topCorrect,
216
214
  left,
217
215
  bottom,
@@ -221,9 +219,9 @@ export class Label extends LabelBase {
221
219
  }
222
220
  case 'bottom': {
223
221
  const height = this.computeTextHeight(CGSizeMake(tv.bounds.size.width, 10000));
224
- let bottomCorrect = tv.bounds.size.height - bottom - height * tv.zoomScale;
222
+ let bottomCorrect = tv.bounds.size.height - top - bottom - height * tv.zoomScale;
225
223
  bottomCorrect = bottomCorrect < 0.0 ? 0.0 : bottomCorrect;
226
- this.nativeViewProtected.textContainerInset = {
224
+ tv.textContainerInset = {
227
225
  top: top + bottomCorrect,
228
226
  left,
229
227
  bottom,
@@ -237,78 +235,6 @@ export class Label extends LabelBase {
237
235
  get ios() {
238
236
  return this.nativeViewProtected;
239
237
  }
240
- // setTextDecorationAndTransform() {
241
- // const style = this.style;
242
- // const dict = new Map<string, any>();
243
- // switch (style.textDecoration) {
244
- // case 'none':
245
- // break;
246
- // case 'underline':
247
- // // TODO: Replace deprecated `StyleSingle` with `Single` after the next typings update
248
- // dict.set(NSUnderlineStyleAttributeName, NSUnderlineStyle.Single);
249
- // break;
250
- // case 'line-through':
251
- // // TODO: Replace deprecated `StyleSingle` with `Single` after the next typings update
252
- // dict.set(NSStrikethroughStyleAttributeName, NSUnderlineStyle.Single);
253
- // break;
254
- // case 'underline line-through':
255
- // // TODO: Replace deprecated `StyleSingle` with `Single` after the next typings update
256
- // dict.set(NSUnderlineStyleAttributeName, NSUnderlineStyle.Single);
257
- // dict.set(NSStrikethroughStyleAttributeName, NSUnderlineStyle.Single);
258
- // break;
259
- // default:
260
- // throw new Error(`Invalid text decoration value: ${style.textDecoration}. Valid values are: 'none', 'underline', 'line-through', 'underline line-through'.`);
261
- // }
262
- // if (style.letterSpacing !== 0) {
263
- // dict.set(NSKernAttributeName, style.letterSpacing * this.nativeTextViewProtected.font.pointSize);
264
- // }
265
- // if (style.lineHeight || style.whiteSpace === 'nowrap' || (style['lineBreak'] && style['lineBreak'] !== 'none')) {
266
- // const paragraphStyle = NSMutableParagraphStyle.alloc().init();
267
- // paragraphStyle.minimumLineHeight = style.lineHeight;
268
- // // make sure a possible previously set text alignment setting is not lost when line height is specified
269
- // paragraphStyle.alignment = (this.nativeTextViewProtected as UITextField | UITextView | UILabel).textAlignment;
270
- // // make sure a possible previously set line break mode is not lost when line height is specified
271
- // if (style['lineBreak']) {
272
- // paragraphStyle.lineBreakMode = lineBreakToLineBreakMode(style['lineBreak']);
273
- // } else if (style.whiteSpace) {
274
- // paragraphStyle.lineBreakMode = whiteSpaceToLineBreakMode(style.whiteSpace);
275
- // }
276
- // dict.set(NSParagraphStyleAttributeName, paragraphStyle);
277
- // } else if (isTextView && this.style.textAlignment !== 'initial') {
278
- // const paragraphStyle = NSMutableParagraphStyle.alloc().init();
279
- // paragraphStyle.alignment = this.nativeTextViewProtected.textAlignment;
280
- // dict.set(NSParagraphStyleAttributeName, paragraphStyle);
281
- // }
282
- // if (style.color && dict.size > 0) {
283
- // // dict.set(NSForegroundColorAttributeName, style.color.ios);
284
- // }
285
- // const text = this.text;
286
- // const str = text === undefined || text === null ? '' : text.toString();
287
- // const source = getTransformedText(str, this.textTransform);
288
- // if (dict.size > 0) {
289
- // if (isTextView) {
290
- // // UITextView's font seems to change inside.
291
- // dict.set(NSFontAttributeName, this.nativeTextViewProtected.font);
292
- // }
293
- // const result = NSMutableAttributedString.alloc().initWithString(source);
294
- // result.setAttributesRange(dict as any, { location: 0, length: source.length });
295
- // if (this.nativeTextViewProtected instanceof UIButton) {
296
- // this.nativeTextViewProtected.setAttributedTitleForState(result, UIControlState.Normal);
297
- // } else {
298
- // this.nativeTextViewProtected.attributedText = result;
299
- // }
300
- // } else {
301
- // if (this.nativeTextViewProtected instanceof UIButton) {
302
- // // Clear attributedText or title won't be affected.
303
- // this.nativeTextViewProtected.setAttributedTitleForState(null, UIControlState.Normal);
304
- // this.nativeTextViewProtected.setTitleForState(source, UIControlState.Normal);
305
- // } else {
306
- // // Clear attributedText or text won't be affected.
307
- // this.nativeTextViewProtected.attributedText = undefined;
308
- // this.nativeTextViewProtected.text = source;
309
- // }
310
- // }
311
- // }
312
238
  _requestLayoutOnTextChanged() {
313
239
  if (this._fixedSize === FixedSize.BOTH) {
314
240
  return;
@@ -327,8 +253,11 @@ export class Label extends LabelBase {
327
253
  const height = layout.getMeasureSpecSize(heightMeasureSpec);
328
254
  const heightMode = layout.getMeasureSpecMode(heightMeasureSpec);
329
255
  if (this.autoFontSize) {
330
- // this.needsAutoFontSize = true;
331
- this.textViewDidChange(nativeView, layout.toDeviceIndependentPixels(width), layout.toDeviceIndependentPixels(height));
256
+ const finiteWidth = widthMode === layout.EXACTLY;
257
+ const finiteHeight = heightMode === layout.EXACTLY;
258
+ if (!finiteWidth || !finiteHeight) {
259
+ this.textViewDidChange(nativeView, layout.toDeviceIndependentPixels(width), layout.toDeviceIndependentPixels(height));
260
+ }
332
261
  }
333
262
  const desiredSize = layout.measureNativeView(nativeView, width, widthMode, height, heightMode);
334
263
  const labelWidth = widthMode === layout.AT_MOST ? Math.min(desiredSize.width, width) : desiredSize.width;
@@ -340,6 +269,12 @@ export class Label extends LabelBase {
340
269
  this.setMeasuredDimension(widthAndState, heightAndState);
341
270
  }
342
271
  }
272
+ _onSizeChanged() {
273
+ super._onSizeChanged();
274
+ if (this.autoFontSize) {
275
+ this.textViewDidChange(this.nativeTextViewProtected);
276
+ }
277
+ }
343
278
  // _htmlTappable = false;
344
279
  // _htmlTapGestureRecognizer;
345
280
  textViewShouldInteractWithURLInRangeInteraction(textView, URL, characterRange, interaction) {
@@ -387,14 +322,13 @@ export class Label extends LabelBase {
387
322
  // when in collectionView or pager
388
323
  // if this is done sync (without DTCoreText) while init the cell
389
324
  // it breaks the UICollectionView :s
390
- if (usingIOSDTCoreText()) {
391
- this._updateHTMLString();
392
- }
393
- else {
394
- // setTimeout(() => {
395
- this._updateHTMLString();
396
- // }, 0);
397
- }
325
+ // if (usingIOSDTCoreText()) {
326
+ // this._updateHTMLString();
327
+ // } else {
328
+ // setTimeout(() => {
329
+ this._updateHTMLString();
330
+ // }, 0);
331
+ // }
398
332
  }
399
333
  _setColor(color) {
400
334
  if (this.nativeTextViewProtected instanceof UIButton) {
@@ -450,23 +384,15 @@ export class Label extends LabelBase {
450
384
  nativeView.linkTextAttributes = attributes;
451
385
  }
452
386
  [_a = htmlProperty.setNative](value) {
453
- this.fontSizeRatio = 1;
454
- this.needsAutoFontSize = this.autoFontSize;
455
387
  this.updateHTMLString();
456
388
  }
457
389
  [_b = formattedTextProperty.setNative](value) {
458
- this.fontSizeRatio = 1;
459
- this.needsAutoFontSize = this.autoFontSize;
460
390
  super[formattedTextProperty.setNative](value);
461
391
  }
462
392
  [_c = letterSpacingProperty.setNative](value) {
463
- this.fontSizeRatio = 1;
464
- this.needsAutoFontSize = this.autoFontSize;
465
393
  super[letterSpacingProperty.setNative](value);
466
394
  }
467
395
  [_d = lineHeightProperty.setNative](value) {
468
- this.fontSizeRatio = 1;
469
- this.needsAutoFontSize = this.autoFontSize;
470
396
  super[lineHeightProperty.setNative](value);
471
397
  }
472
398
  // @needFormattedStringComputation
@@ -475,8 +401,6 @@ export class Label extends LabelBase {
475
401
  // }
476
402
  [fontInternalProperty.setNative](value) {
477
403
  const nativeView = this.nativeTextViewProtected;
478
- this.fontSizeRatio = 1;
479
- this.needsAutoFontSize = this.autoFontSize;
480
404
  const newFont = value instanceof Font ? value.getUIFont(nativeView.font) : value;
481
405
  if (!this.formattedText && !this.html) {
482
406
  nativeView.font = newFont;
@@ -521,6 +445,7 @@ export class Label extends LabelBase {
521
445
  else {
522
446
  super._setNativeText();
523
447
  }
448
+ this.updateTextContainerInset();
524
449
  this._requestLayoutOnTextChanged();
525
450
  }
526
451
  setTextDecorationAndTransform() {
@@ -545,25 +470,18 @@ export class Label extends LabelBase {
545
470
  if (style.letterSpacing !== 0 && this.nativeTextViewProtected.font) {
546
471
  const kern = style.letterSpacing * this.nativeTextViewProtected.font.pointSize;
547
472
  dict.set(NSKernAttributeName, kern);
548
- if (this.nativeTextViewProtected instanceof UITextField) {
549
- this.nativeTextViewProtected.defaultTextAttributes.setValueForKey(kern, NSKernAttributeName);
550
- }
551
473
  }
552
474
  const isTextView = false;
553
- if (style.lineHeight) {
475
+ if (style.lineHeight !== undefined) {
476
+ let lineHeight = style.lineHeight;
477
+ if (lineHeight === 0) {
478
+ lineHeight = 0.00001;
479
+ }
554
480
  const paragraphStyle = NSMutableParagraphStyle.alloc().init();
555
- paragraphStyle.lineSpacing = style.lineHeight;
481
+ paragraphStyle.minimumLineHeight = lineHeight;
482
+ paragraphStyle.maximumLineHeight = lineHeight;
556
483
  // make sure a possible previously set text alignment setting is not lost when line height is specified
557
- if (this.nativeTextViewProtected instanceof UIButton) {
558
- paragraphStyle.alignment = this.nativeTextViewProtected.titleLabel.textAlignment;
559
- }
560
- else {
561
- paragraphStyle.alignment = this.nativeTextViewProtected.textAlignment;
562
- }
563
- if (this.nativeTextViewProtected instanceof UILabel) {
564
- // make sure a possible previously set line break mode is not lost when line height is specified
565
- paragraphStyle.lineBreakMode = this.nativeTextViewProtected.lineBreakMode;
566
- }
484
+ paragraphStyle.alignment = this.nativeTextViewProtected.textAlignment;
567
485
  dict.set(NSParagraphStyleAttributeName, paragraphStyle);
568
486
  }
569
487
  else if (isTextView) {
@@ -587,81 +505,27 @@ export class Label extends LabelBase {
587
505
  location: 0,
588
506
  length: source.length
589
507
  });
590
- if (this.nativeTextViewProtected instanceof UIButton) {
591
- this.nativeTextViewProtected.setAttributedTitleForState(result, 0 /* Normal */);
592
- }
593
- else {
594
- this.nativeTextViewProtected.attributedText = result;
595
- }
508
+ this.nativeTextViewProtected.attributedText = result;
596
509
  }
597
510
  else {
598
- if (this.nativeTextViewProtected instanceof UIButton) {
599
- // Clear attributedText or title won't be affected.
600
- this.nativeTextViewProtected.setAttributedTitleForState(null, 0 /* Normal */);
601
- this.nativeTextViewProtected.setTitleForState(source, 0 /* Normal */);
602
- }
603
- else {
604
- // Clear attributedText or text won't be affected.
605
- this.nativeTextViewProtected.attributedText = undefined;
606
- this.nativeTextViewProtected.text = source;
607
- }
511
+ // Clear attributedText or text won't be affected.
512
+ this.nativeTextViewProtected.attributedText = undefined;
513
+ this.nativeTextViewProtected.text = source;
608
514
  }
609
515
  if (!style.color && majorVersion >= 13 && UIColor.labelColor) {
610
516
  this._setColor(UIColor.labelColor);
611
517
  }
612
518
  }
613
- createNSMutableAttributedString(formattedString) {
614
- var _e;
615
- // we need to store the max Font size to pass it to createMutableStringForSpan
616
- const length = formattedString.spans.length;
617
- let maxFontSize = ((_e = formattedString.style) === null || _e === void 0 ? void 0 : _e.fontSize) || (this === null || this === void 0 ? void 0 : this.style.fontSize) || 0;
618
- for (let i = 0; i < length; i++) {
619
- const s = formattedString.spans.getItem(i);
620
- if (s.style.fontSize) {
621
- maxFontSize = Math.max(maxFontSize, s.style.fontSize);
622
- }
623
- }
624
- this.currentMaxFontSize = maxFontSize;
625
- return super.createNSMutableAttributedString(formattedString);
626
- }
627
- createMutableStringForSpan(span, text) {
628
- const viewFont = this.nativeTextViewProtected.font;
629
- const attrDict = {};
630
- const style = span.style;
631
- let align = style.verticalAlignment || span.parent.style.verticalAlignment;
632
- if (!align || align === 'stretch') {
633
- align = this.verticalTextAlignment;
634
- }
635
- const font = new Font(style.fontFamily, style.fontSize, style.fontStyle, style.fontWeight);
636
- const iosFont = font.getUIFont(viewFont);
637
- attrDict[NSFontAttributeName] = iosFont;
638
- if (span.color) {
639
- const color = span.color instanceof Color ? span.color : new Color(span.color);
640
- attrDict[NSForegroundColorAttributeName] = color.ios;
641
- }
642
- // We don't use isSet function here because defaultValue for backgroundColor is null.
643
- const backgroundColor = style.backgroundColor || span.parent.backgroundColor;
644
- if (backgroundColor) {
645
- const color = backgroundColor instanceof Color ? backgroundColor : new Color(backgroundColor);
646
- attrDict[NSBackgroundColorAttributeName] = color.ios;
647
- }
648
- const textDecoration = getClosestPropertyValue(textDecorationProperty, span);
649
- if (textDecoration) {
650
- const underline = textDecoration.indexOf('underline') !== -1;
651
- if (underline) {
652
- attrDict[NSUnderlineStyleAttributeName] = underline;
653
- }
654
- const strikethrough = textDecoration.indexOf('line-through') !== -1;
655
- if (strikethrough) {
656
- attrDict[NSStrikethroughStyleAttributeName] = strikethrough;
657
- }
658
- }
659
- if (align && align !== 'stretch') {
660
- if (iosFont) {
661
- attrDict[NSBaselineOffsetAttributeName] = -computeBaseLineOffset(align, -iosFont.ascender, -iosFont.descender, -iosFont.ascender, -iosFont.descender, iosFont.pointSize, this.currentMaxFontSize);
662
- }
519
+ createFormattedTextNative(value) {
520
+ return createNativeAttributedString(value, this, this.autoFontSize, this.fontSizeRatio);
521
+ }
522
+ setFormattedTextDecorationAndTransform() {
523
+ const attrText = this.createFormattedTextNative(this.formattedText);
524
+ // we override parent class behavior because we apply letterSpacing and lineHeight on a per Span basis
525
+ if (majorVersion >= 13 && UIColor.labelColor) {
526
+ this.nativeTextViewProtected.textColor = UIColor.labelColor;
663
527
  }
664
- return NSMutableAttributedString.alloc().initWithStringAttributes(text, attrDict);
528
+ this.nativeTextViewProtected.attributedText = attrText;
665
529
  }
666
530
  [paddingTopProperty.getDefault]() {
667
531
  return {
@@ -770,19 +634,23 @@ export class Label extends LabelBase {
770
634
  }
771
635
  }
772
636
  }
773
- textViewDidChange(textView, width, height) {
774
- if (this.autoFontSize && this.needsAutoFontSize) {
775
- this.needsAutoFontSize = false;
637
+ textViewDidChange(textView, width, height, force = false) {
638
+ if (textView && this.autoFontSize) {
776
639
  if ((!textView.attributedText && !textView.text) ||
777
640
  (width === undefined && height === undefined && CGSizeEqualToSize(textView.bounds.size, CGSizeZero))) {
778
641
  return;
779
642
  }
780
643
  const textViewSize = textView.frame.size;
781
- const fixedWidth = width !== undefined ? width : textViewSize.width;
782
- const fixedHeight = height !== undefined ? height : textViewSize.height;
644
+ const fixedWidth = Math.floor(width !== undefined ? width : textViewSize.width);
645
+ const fixedHeight = Math.floor(height !== undefined ? height : textViewSize.height);
783
646
  if (fixedWidth === 0 || fixedHeight === 0) {
784
647
  return;
785
648
  }
649
+ const autoSizeKey = fixedWidth + '_' + fixedHeight;
650
+ if (!force && autoSizeKey === this._lastAutoSizeKey) {
651
+ return;
652
+ }
653
+ this._lastAutoSizeKey = autoSizeKey;
786
654
  const nbLines = textView.textContainer.maximumNumberOfLines;
787
655
  // we need to reset verticalTextAlignment or computation will be wrong
788
656
  this.updateTextContainerInset(false);
@@ -850,10 +718,10 @@ export class Label extends LabelBase {
850
718
  }
851
719
  }
852
720
  [autoFontSizeProperty.setNative](value) {
853
- if (value && (this.text || this.html || this.formattedText)) {
854
- this.fontSizeRatio = 1;
855
- this.needsAutoFontSize = true;
856
- this.textViewDidChange(this.nativeTextViewProtected);
721
+ if (value) {
722
+ if (this.isLayoutValid && (this.text || this.html || this.formattedText)) {
723
+ this.textViewDidChange(this.nativeTextViewProtected, undefined, undefined, true);
724
+ }
857
725
  }
858
726
  else {
859
727
  this[fontInternalProperty.setNative](this.style.fontInternal);