@nativescript-community/ui-label 1.2.4 → 1.2.7

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/CHANGELOG.md CHANGED
@@ -3,6 +3,30 @@
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.7](https://github.com/nativescript-community/ui-label/compare/v1.2.6...v1.2.7) (2022-04-05)
7
+
8
+ **Note:** Version bump only for package @nativescript-community/ui-label
9
+
10
+
11
+
12
+
13
+
14
+ ## [1.2.6](https://github.com/nativescript-community/ui-label/compare/v1.2.5...v1.2.6) (2022-02-09)
15
+
16
+ **Note:** Version bump only for package @nativescript-community/ui-label
17
+
18
+
19
+
20
+
21
+
22
+ ## [1.2.5](https://github.com/nativescript-community/ui-label/compare/v1.2.4...v1.2.5) (2022-02-09)
23
+
24
+ **Note:** Version bump only for package @nativescript-community/ui-label
25
+
26
+
27
+
28
+
29
+
6
30
  ## [1.2.4](https://github.com/nativescript-community/ui-label/compare/v1.2.3...v1.2.4) (2022-01-14)
7
31
 
8
32
 
package/label.ios.d.ts CHANGED
@@ -39,5 +39,12 @@ export declare class Label extends LabelBase {
39
39
  setFormattedTextDecorationAndTransform(): void;
40
40
  fontSizeRatio: number;
41
41
  _lastAutoSizeKey: string;
42
- textViewDidChange(textView: UITextView, width?: any, height?: any, force?: boolean): void;
42
+ updateAutoFontSize({ textView, width, height, force, onlyMeasure }: {
43
+ textView: UITextView;
44
+ width?: any;
45
+ height?: any;
46
+ force?: boolean;
47
+ onlyMeasure?: boolean;
48
+ }): any;
49
+ textViewDidChange(textView: UITextView): void;
43
50
  }
package/label.ios.js CHANGED
@@ -79,19 +79,19 @@ 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, undefined, undefined, true);
82
+ owner.textViewDidChange(textView);
83
83
  }
84
84
  };
85
85
  LabelUITextViewDelegateImpl.ObjCProtocols = [UITextViewDelegate];
86
86
  return LabelUITextViewDelegateImpl;
87
87
  }(NSObject));
88
- var ObserverClass = /** @class */ (function (_super) {
89
- __extends(ObserverClass, _super);
90
- function ObserverClass() {
88
+ var LabelObserverClass = /** @class */ (function (_super) {
89
+ __extends(LabelObserverClass, _super);
90
+ function LabelObserverClass() {
91
91
  return _super !== null && _super.apply(this, arguments) || this;
92
92
  }
93
93
  // NOTE: Refactor this - use Typescript property instead of strings....
94
- ObserverClass.prototype.observeValueForKeyPathOfObjectChangeContext = function (path, tv) {
94
+ LabelObserverClass.prototype.observeValueForKeyPathOfObjectChangeContext = function (path, tv) {
95
95
  if (path === 'contentSize') {
96
96
  var owner = this._owner && this._owner.get();
97
97
  if (owner) {
@@ -99,7 +99,7 @@ var ObserverClass = /** @class */ (function (_super) {
99
99
  }
100
100
  }
101
101
  };
102
- return ObserverClass;
102
+ return LabelObserverClass;
103
103
  }(NSObject));
104
104
  export class Label extends LabelBase {
105
105
  constructor() {
@@ -135,7 +135,7 @@ export class Label extends LabelBase {
135
135
  initNativeView() {
136
136
  super.initNativeView();
137
137
  this._delegate = LabelUITextViewDelegateImpl.initWithOwner(new WeakRef(this));
138
- this._observer = ObserverClass.alloc().init();
138
+ this._observer = LabelObserverClass.alloc().init();
139
139
  this._observer['_owner'] = new WeakRef(this);
140
140
  this.nativeViewProtected.addObserverForKeyPathOptionsContext(this._observer, 'contentSize', 1 /* New */, null);
141
141
  this.nativeViewProtected.attributedText = this.attributedString;
@@ -252,14 +252,23 @@ export class Label extends LabelBase {
252
252
  const widthMode = layout.getMeasureSpecMode(widthMeasureSpec);
253
253
  const height = layout.getMeasureSpecSize(heightMeasureSpec);
254
254
  const heightMode = layout.getMeasureSpecMode(heightMeasureSpec);
255
+ let resetFont;
255
256
  if (this.autoFontSize) {
256
257
  const finiteWidth = widthMode === layout.EXACTLY;
257
258
  const finiteHeight = heightMode === layout.EXACTLY;
258
259
  if (!finiteWidth || !finiteHeight) {
259
- this.textViewDidChange(nativeView, layout.toDeviceIndependentPixels(width), layout.toDeviceIndependentPixels(height));
260
+ resetFont = this.updateAutoFontSize({
261
+ textView: nativeView,
262
+ width: layout.toDeviceIndependentPixels(width),
263
+ height: layout.toDeviceIndependentPixels(height),
264
+ onlyMeasure: true
265
+ });
260
266
  }
261
267
  }
262
268
  const desiredSize = layout.measureNativeView(nativeView, width, widthMode, height, heightMode);
269
+ if (!this.formattedText && !this.html && resetFont) {
270
+ nativeView.font = resetFont;
271
+ }
263
272
  const labelWidth = widthMode === layout.AT_MOST ? Math.min(desiredSize.width, width) : desiredSize.width;
264
273
  // const labelHeight = heightMode === layout.AT_MOST ? Math.min(desiredSize.height, height) : desiredSize.height;
265
274
  const measureWidth = Math.max(labelWidth, this.effectiveMinWidth);
@@ -272,7 +281,7 @@ export class Label extends LabelBase {
272
281
  _onSizeChanged() {
273
282
  super._onSizeChanged();
274
283
  if (this.autoFontSize) {
275
- this.textViewDidChange(this.nativeTextViewProtected);
284
+ this.updateAutoFontSize({ textView: this.nativeTextViewProtected });
276
285
  }
277
286
  }
278
287
  // _htmlTappable = false;
@@ -298,7 +307,7 @@ export class Label extends LabelBase {
298
307
  fontSize,
299
308
  familyName,
300
309
  fontWeight,
301
- color: this.color,
310
+ // color: this.color,
302
311
  letterSpacing: this.letterSpacing,
303
312
  lineHeight: this.lineHeight,
304
313
  textAlignment: this.nativeTextViewProtected.textAlignment
@@ -337,7 +346,12 @@ export class Label extends LabelBase {
337
346
  }
338
347
  else {
339
348
  if (this.formattedText || this.html) {
340
- this._setNativeText();
349
+ if (this.html) {
350
+ this.updateHTMLString();
351
+ }
352
+ else {
353
+ super._setNativeText();
354
+ }
341
355
  }
342
356
  else {
343
357
  this.nativeTextViewProtected.textColor = color;
@@ -445,6 +459,10 @@ export class Label extends LabelBase {
445
459
  else {
446
460
  super._setNativeText();
447
461
  }
462
+ if (this.color) {
463
+ const color = this.color instanceof Color ? this.color.ios : this.color;
464
+ this._setColor(color);
465
+ }
448
466
  this.updateTextContainerInset();
449
467
  this._requestLayoutOnTextChanged();
450
468
  }
@@ -634,29 +652,32 @@ export class Label extends LabelBase {
634
652
  }
635
653
  }
636
654
  }
637
- textViewDidChange(textView, width, height, force = false) {
655
+ updateAutoFontSize({ textView, width, height, force = false, onlyMeasure = false }) {
656
+ let currentFont;
638
657
  if (textView && this.autoFontSize) {
639
658
  if ((!textView.attributedText && !textView.text) ||
640
659
  (width === undefined && height === undefined && CGSizeEqualToSize(textView.bounds.size, CGSizeZero))) {
641
- return;
660
+ return currentFont;
642
661
  }
643
662
  const textViewSize = textView.frame.size;
644
663
  const fixedWidth = Math.floor(width !== undefined ? width : textViewSize.width);
645
664
  const fixedHeight = Math.floor(height !== undefined ? height : textViewSize.height);
646
665
  if (fixedWidth === 0 || fixedHeight === 0) {
647
- return;
666
+ return currentFont;
648
667
  }
649
668
  const autoSizeKey = fixedWidth + '_' + fixedHeight;
650
- if (!force && autoSizeKey === this._lastAutoSizeKey) {
651
- return;
669
+ const fontSize = this.style.fontSize || 17;
670
+ let expectFont = (this.style.fontInternal || Font.default).getUIFont(UIFont.systemFontOfSize(fontSize));
671
+ //if we are not on the "default" font size we need to measure again or we could break
672
+ //the layout behavior like for flexbox where there are multiple measure passes
673
+ if (!force && autoSizeKey === this._lastAutoSizeKey && expectFont.pointSize === textView.font.pointSize) {
674
+ return null;
652
675
  }
676
+ currentFont = textView.font;
653
677
  this._lastAutoSizeKey = autoSizeKey;
654
678
  const nbLines = textView.textContainer.maximumNumberOfLines;
655
679
  // we need to reset verticalTextAlignment or computation will be wrong
656
680
  this.updateTextContainerInset(false);
657
- const fontSize = this.style.fontSize || 17;
658
- let expectFont = (this.style.fontInternal || Font.default).getUIFont(UIFont.systemFontOfSize(fontSize));
659
- //first reset the font size
660
681
  let expectSize;
661
682
  const stepSize = this.autoFontSizeStep || 1;
662
683
  const updateFontSize = (font) => {
@@ -667,6 +688,7 @@ export class Label extends LabelBase {
667
688
  textView.font = font;
668
689
  }
669
690
  };
691
+ //first reset the font size
670
692
  updateFontSize(expectFont);
671
693
  const size = () => {
672
694
  if (nbLines === 1) {
@@ -713,14 +735,20 @@ export class Label extends LabelBase {
713
735
  }
714
736
  }
715
737
  }
716
- this.fontSizeRatio = expectFont.pointSize / fontSize;
738
+ if (!onlyMeasure) {
739
+ this.fontSizeRatio = expectFont.pointSize / fontSize;
740
+ }
717
741
  this.updateTextContainerInset();
718
742
  }
743
+ return currentFont;
744
+ }
745
+ textViewDidChange(textView) {
746
+ this.updateAutoFontSize({ textView, force: true });
719
747
  }
720
748
  [autoFontSizeProperty.setNative](value) {
721
749
  if (value) {
722
750
  if (this.isLayoutValid && (this.text || this.html || this.formattedText)) {
723
- this.textViewDidChange(this.nativeTextViewProtected, undefined, undefined, true);
751
+ this.updateAutoFontSize({ textView: this.nativeTextViewProtected, force: true });
724
752
  }
725
753
  }
726
754
  else {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nativescript-community/ui-label",
3
- "version": "1.2.4",
3
+ "version": "1.2.7",
4
4
  "description": "Alternative to the built-in NativeScript Label but with better performance and additional features such as HTML rendering and more.",
5
5
  "main": "./label",
6
6
  "sideEffects": false,
@@ -32,7 +32,7 @@
32
32
  "license": "Apache-2.0",
33
33
  "readmeFilename": "README.md",
34
34
  "dependencies": {
35
- "@nativescript-community/text": "^1.4.32"
35
+ "@nativescript-community/text": "^1.4.36"
36
36
  },
37
- "gitHead": "27522e865296a86d576a68d8adc8973f384c572f"
37
+ "gitHead": "092a8246b892db73f17613a3d10b8f52444ef2ce"
38
38
  }