@nativescript-community/ui-label 1.2.4 → 1.2.5
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 +8 -0
- package/label.ios.d.ts +8 -1
- package/label.ios.js +26 -9
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
@@ -3,6 +3,14 @@
|
|
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.5](https://github.com/nativescript-community/ui-label/compare/v1.2.4...v1.2.5) (2022-02-09)
|
7
|
+
|
8
|
+
**Note:** Version bump only for package @nativescript-community/ui-label
|
9
|
+
|
10
|
+
|
11
|
+
|
12
|
+
|
13
|
+
|
6
14
|
## [1.2.4](https://github.com/nativescript-community/ui-label/compare/v1.2.3...v1.2.4) (2022-01-14)
|
7
15
|
|
8
16
|
|
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
|
-
|
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,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);
|
83
83
|
}
|
84
84
|
};
|
85
85
|
LabelUITextViewDelegateImpl.ObjCProtocols = [UITextViewDelegate];
|
@@ -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
|
-
|
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 (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.
|
284
|
+
this.updateAutoFontSize({ textView: this.nativeTextViewProtected });
|
276
285
|
}
|
277
286
|
}
|
278
287
|
// _htmlTappable = false;
|
@@ -634,22 +643,24 @@ export class Label extends LabelBase {
|
|
634
643
|
}
|
635
644
|
}
|
636
645
|
}
|
637
|
-
|
646
|
+
updateAutoFontSize({ textView, width, height, force = false, onlyMeasure = false }) {
|
647
|
+
let currentFont;
|
638
648
|
if (textView && this.autoFontSize) {
|
639
649
|
if ((!textView.attributedText && !textView.text) ||
|
640
650
|
(width === undefined && height === undefined && CGSizeEqualToSize(textView.bounds.size, CGSizeZero))) {
|
641
|
-
return;
|
651
|
+
return currentFont;
|
642
652
|
}
|
643
653
|
const textViewSize = textView.frame.size;
|
644
654
|
const fixedWidth = Math.floor(width !== undefined ? width : textViewSize.width);
|
645
655
|
const fixedHeight = Math.floor(height !== undefined ? height : textViewSize.height);
|
646
656
|
if (fixedWidth === 0 || fixedHeight === 0) {
|
647
|
-
return;
|
657
|
+
return currentFont;
|
648
658
|
}
|
649
659
|
const autoSizeKey = fixedWidth + '_' + fixedHeight;
|
650
660
|
if (!force && autoSizeKey === this._lastAutoSizeKey) {
|
651
|
-
return;
|
661
|
+
return null;
|
652
662
|
}
|
663
|
+
currentFont = textView.font;
|
653
664
|
this._lastAutoSizeKey = autoSizeKey;
|
654
665
|
const nbLines = textView.textContainer.maximumNumberOfLines;
|
655
666
|
// we need to reset verticalTextAlignment or computation will be wrong
|
@@ -713,14 +724,20 @@ export class Label extends LabelBase {
|
|
713
724
|
}
|
714
725
|
}
|
715
726
|
}
|
716
|
-
|
727
|
+
if (!onlyMeasure) {
|
728
|
+
this.fontSizeRatio = expectFont.pointSize / fontSize;
|
729
|
+
}
|
717
730
|
this.updateTextContainerInset();
|
718
731
|
}
|
732
|
+
return currentFont;
|
733
|
+
}
|
734
|
+
textViewDidChange(textView) {
|
735
|
+
this.updateAutoFontSize({ textView, force: true });
|
719
736
|
}
|
720
737
|
[autoFontSizeProperty.setNative](value) {
|
721
738
|
if (value) {
|
722
739
|
if (this.isLayoutValid && (this.text || this.html || this.formattedText)) {
|
723
|
-
this.
|
740
|
+
this.updateAutoFontSize({ textView: this.nativeTextViewProtected, force: true });
|
724
741
|
}
|
725
742
|
}
|
726
743
|
else {
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@nativescript-community/ui-label",
|
3
|
-
"version": "1.2.
|
3
|
+
"version": "1.2.5",
|
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,
|
@@ -34,5 +34,5 @@
|
|
34
34
|
"dependencies": {
|
35
35
|
"@nativescript-community/text": "^1.4.32"
|
36
36
|
},
|
37
|
-
"gitHead": "
|
37
|
+
"gitHead": "7af7ba4fd7ec88e0d42ec3e36e3497e318f4cb37"
|
38
38
|
}
|