@nativescript-community/ui-label 1.1.24 → 1.2.2
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 +35 -0
- package/label.android.d.ts +0 -1
- package/label.android.js +29 -9
- package/label.ios.d.ts +6 -9
- package/label.ios.js +86 -222
- package/package.json +3 -3
- package/platforms/android/include.gradle +1 -1
- package/platforms/android/native-api-usage.json +15 -0
- package/pnpm-global/5/node_modules/.modules.yaml +0 -22
- package/pnpm-global/5/node_modules/.pnpm/@nativescript-community+text@1.4.11/node_modules/@nativescript-community/text/CHANGELOG.md +0 -212
- package/pnpm-global/5/node_modules/.pnpm/@nativescript-community+text@1.4.11/node_modules/@nativescript-community/text/LICENSE +0 -201
- package/pnpm-global/5/node_modules/.pnpm/@nativescript-community+text@1.4.11/node_modules/@nativescript-community/text/README.md +0 -14
- package/pnpm-global/5/node_modules/.pnpm/@nativescript-community+text@1.4.11/node_modules/@nativescript-community/text/index-common.d.ts +0 -40
- package/pnpm-global/5/node_modules/.pnpm/@nativescript-community+text@1.4.11/node_modules/@nativescript-community/text/index-common.js +0 -208
- package/pnpm-global/5/node_modules/.pnpm/@nativescript-community+text@1.4.11/node_modules/@nativescript-community/text/index.android.d.ts +0 -27
- package/pnpm-global/5/node_modules/.pnpm/@nativescript-community+text@1.4.11/node_modules/@nativescript-community/text/index.android.js +0 -298
- package/pnpm-global/5/node_modules/.pnpm/@nativescript-community+text@1.4.11/node_modules/@nativescript-community/text/index.d.ts +0 -1
- package/pnpm-global/5/node_modules/.pnpm/@nativescript-community+text@1.4.11/node_modules/@nativescript-community/text/index.ios.d.ts +0 -14
- package/pnpm-global/5/node_modules/.pnpm/@nativescript-community+text@1.4.11/node_modules/@nativescript-community/text/index.ios.js +0 -189
- package/pnpm-global/5/node_modules/.pnpm/@nativescript-community+text@1.4.11/node_modules/@nativescript-community/text/index.js +0 -25
- package/pnpm-global/5/node_modules/.pnpm/@nativescript-community+text@1.4.11/node_modules/@nativescript-community/text/package.json +0 -34
- package/pnpm-global/5/node_modules/.pnpm/@nativescript-community+text@1.4.11/node_modules/@nativescript-community/text/platforms/android/AndroidManifest.xml +0 -3
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- package/pnpm-global/5/node_modules/.pnpm/@nativescript-community+text@1.4.11/node_modules/@nativescript-community/text/typings/android.d.ts +0 -32
- package/pnpm-global/5/node_modules/.pnpm/lock.yaml +0 -13
- 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.2](https://github.com/nativescript-community/ui-label/compare/v1.2.1...v1.2.2) (2022-01-08)
|
7
|
+
|
8
|
+
**Note:** Version bump only for package @nativescript-community/ui-label
|
9
|
+
|
10
|
+
|
11
|
+
|
12
|
+
|
13
|
+
|
14
|
+
## [1.2.1](https://github.com/nativescript-community/ui-label/compare/v1.2.0...v1.2.1) (2022-01-02)
|
15
|
+
|
16
|
+
**Note:** Version bump only for package @nativescript-community/ui-label
|
17
|
+
|
18
|
+
|
19
|
+
|
20
|
+
|
21
|
+
|
22
|
+
# [1.2.0](https://github.com/nativescript-community/ui-label/compare/v1.1.25...v1.2.0) (2021-10-20)
|
23
|
+
|
24
|
+
|
25
|
+
### Features
|
26
|
+
|
27
|
+
* **android:** native-api-usage ([40d28dd](https://github.com/nativescript-community/ui-label/commit/40d28dd648d993f1a7d844c677e20e8dfb1d67c0))
|
28
|
+
|
29
|
+
|
30
|
+
|
31
|
+
|
32
|
+
|
33
|
+
## [1.1.25](https://github.com/nativescript-community/ui-label/compare/v1.1.24...v1.1.25) (2021-08-09)
|
34
|
+
|
35
|
+
**Note:** Version bump only for package @nativescript-community/ui-label
|
36
|
+
|
37
|
+
|
38
|
+
|
39
|
+
|
40
|
+
|
6
41
|
## [1.1.24](https://github.com/nativescript-community/ui-label/compare/v1.1.23...v1.1.24) (2021-08-09)
|
7
42
|
|
8
43
|
**Note:** Version bump only for package @nativescript-community/ui-label
|
package/label.android.d.ts
CHANGED
@@ -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
|
-
|
362
|
+
if (android.os.Build.VERSION.SDK_INT >= 26) {
|
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
|
-
|
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
|
-
|
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.
|
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
|
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
|
-
|
41
|
-
|
42
|
-
createMutableStringForSpan(span: Span, text: string): NSMutableAttributedString;
|
38
|
+
createFormattedTextNative(value: FormattedString): any;
|
39
|
+
setFormattedTextDecorationAndTransform(): void;
|
43
40
|
fontSizeRatio: number;
|
44
|
-
|
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 {
|
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,
|
6
|
-
import {
|
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
|
-
|
129
|
-
|
130
|
-
|
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
|
174
|
-
|
175
|
-
if (
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
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
|
-
|
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 ||
|
191
|
-
this.
|
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
|
-
|
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
|
-
|
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
|
-
|
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;
|
@@ -330,7 +256,6 @@ export class Label extends LabelBase {
|
|
330
256
|
const finiteWidth = widthMode === layout.EXACTLY;
|
331
257
|
const finiteHeight = heightMode === layout.EXACTLY;
|
332
258
|
if (!finiteWidth || !finiteHeight) {
|
333
|
-
this.needsAutoFontSize = true;
|
334
259
|
this.textViewDidChange(nativeView, layout.toDeviceIndependentPixels(width), layout.toDeviceIndependentPixels(height));
|
335
260
|
}
|
336
261
|
}
|
@@ -344,6 +269,12 @@ export class Label extends LabelBase {
|
|
344
269
|
this.setMeasuredDimension(widthAndState, heightAndState);
|
345
270
|
}
|
346
271
|
}
|
272
|
+
_onSizeChanged() {
|
273
|
+
super._onSizeChanged();
|
274
|
+
if (this.autoFontSize) {
|
275
|
+
this.textViewDidChange(this.nativeTextViewProtected);
|
276
|
+
}
|
277
|
+
}
|
347
278
|
// _htmlTappable = false;
|
348
279
|
// _htmlTapGestureRecognizer;
|
349
280
|
textViewShouldInteractWithURLInRangeInteraction(textView, URL, characterRange, interaction) {
|
@@ -391,14 +322,13 @@ export class Label extends LabelBase {
|
|
391
322
|
// when in collectionView or pager
|
392
323
|
// if this is done sync (without DTCoreText) while init the cell
|
393
324
|
// it breaks the UICollectionView :s
|
394
|
-
if (usingIOSDTCoreText()) {
|
395
|
-
|
396
|
-
}
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
}
|
325
|
+
// if (usingIOSDTCoreText()) {
|
326
|
+
// this._updateHTMLString();
|
327
|
+
// } else {
|
328
|
+
// setTimeout(() => {
|
329
|
+
this._updateHTMLString();
|
330
|
+
// }, 0);
|
331
|
+
// }
|
402
332
|
}
|
403
333
|
_setColor(color) {
|
404
334
|
if (this.nativeTextViewProtected instanceof UIButton) {
|
@@ -454,23 +384,15 @@ export class Label extends LabelBase {
|
|
454
384
|
nativeView.linkTextAttributes = attributes;
|
455
385
|
}
|
456
386
|
[_a = htmlProperty.setNative](value) {
|
457
|
-
this.fontSizeRatio = 1;
|
458
|
-
this.needsAutoFontSize = this.autoFontSize;
|
459
387
|
this.updateHTMLString();
|
460
388
|
}
|
461
389
|
[_b = formattedTextProperty.setNative](value) {
|
462
|
-
this.fontSizeRatio = 1;
|
463
|
-
this.needsAutoFontSize = this.autoFontSize;
|
464
390
|
super[formattedTextProperty.setNative](value);
|
465
391
|
}
|
466
392
|
[_c = letterSpacingProperty.setNative](value) {
|
467
|
-
this.fontSizeRatio = 1;
|
468
|
-
this.needsAutoFontSize = this.autoFontSize;
|
469
393
|
super[letterSpacingProperty.setNative](value);
|
470
394
|
}
|
471
395
|
[_d = lineHeightProperty.setNative](value) {
|
472
|
-
this.fontSizeRatio = 1;
|
473
|
-
this.needsAutoFontSize = this.autoFontSize;
|
474
396
|
super[lineHeightProperty.setNative](value);
|
475
397
|
}
|
476
398
|
// @needFormattedStringComputation
|
@@ -479,8 +401,6 @@ export class Label extends LabelBase {
|
|
479
401
|
// }
|
480
402
|
[fontInternalProperty.setNative](value) {
|
481
403
|
const nativeView = this.nativeTextViewProtected;
|
482
|
-
this.fontSizeRatio = 1;
|
483
|
-
this.needsAutoFontSize = this.autoFontSize;
|
484
404
|
const newFont = value instanceof Font ? value.getUIFont(nativeView.font) : value;
|
485
405
|
if (!this.formattedText && !this.html) {
|
486
406
|
nativeView.font = newFont;
|
@@ -525,6 +445,7 @@ export class Label extends LabelBase {
|
|
525
445
|
else {
|
526
446
|
super._setNativeText();
|
527
447
|
}
|
448
|
+
this.updateTextContainerInset();
|
528
449
|
this._requestLayoutOnTextChanged();
|
529
450
|
}
|
530
451
|
setTextDecorationAndTransform() {
|
@@ -549,25 +470,18 @@ export class Label extends LabelBase {
|
|
549
470
|
if (style.letterSpacing !== 0 && this.nativeTextViewProtected.font) {
|
550
471
|
const kern = style.letterSpacing * this.nativeTextViewProtected.font.pointSize;
|
551
472
|
dict.set(NSKernAttributeName, kern);
|
552
|
-
if (this.nativeTextViewProtected instanceof UITextField) {
|
553
|
-
this.nativeTextViewProtected.defaultTextAttributes.setValueForKey(kern, NSKernAttributeName);
|
554
|
-
}
|
555
473
|
}
|
556
474
|
const isTextView = false;
|
557
|
-
if (style.lineHeight) {
|
475
|
+
if (style.lineHeight !== undefined) {
|
476
|
+
let lineHeight = style.lineHeight;
|
477
|
+
if (lineHeight === 0) {
|
478
|
+
lineHeight = 0.00001;
|
479
|
+
}
|
558
480
|
const paragraphStyle = NSMutableParagraphStyle.alloc().init();
|
559
|
-
paragraphStyle.
|
481
|
+
paragraphStyle.minimumLineHeight = lineHeight;
|
482
|
+
paragraphStyle.maximumLineHeight = lineHeight;
|
560
483
|
// make sure a possible previously set text alignment setting is not lost when line height is specified
|
561
|
-
|
562
|
-
paragraphStyle.alignment = this.nativeTextViewProtected.titleLabel.textAlignment;
|
563
|
-
}
|
564
|
-
else {
|
565
|
-
paragraphStyle.alignment = this.nativeTextViewProtected.textAlignment;
|
566
|
-
}
|
567
|
-
if (this.nativeTextViewProtected instanceof UILabel) {
|
568
|
-
// make sure a possible previously set line break mode is not lost when line height is specified
|
569
|
-
paragraphStyle.lineBreakMode = this.nativeTextViewProtected.lineBreakMode;
|
570
|
-
}
|
484
|
+
paragraphStyle.alignment = this.nativeTextViewProtected.textAlignment;
|
571
485
|
dict.set(NSParagraphStyleAttributeName, paragraphStyle);
|
572
486
|
}
|
573
487
|
else if (isTextView) {
|
@@ -591,81 +505,27 @@ export class Label extends LabelBase {
|
|
591
505
|
location: 0,
|
592
506
|
length: source.length
|
593
507
|
});
|
594
|
-
|
595
|
-
this.nativeTextViewProtected.setAttributedTitleForState(result, 0 /* Normal */);
|
596
|
-
}
|
597
|
-
else {
|
598
|
-
this.nativeTextViewProtected.attributedText = result;
|
599
|
-
}
|
508
|
+
this.nativeTextViewProtected.attributedText = result;
|
600
509
|
}
|
601
510
|
else {
|
602
|
-
|
603
|
-
|
604
|
-
|
605
|
-
this.nativeTextViewProtected.setTitleForState(source, 0 /* Normal */);
|
606
|
-
}
|
607
|
-
else {
|
608
|
-
// Clear attributedText or text won't be affected.
|
609
|
-
this.nativeTextViewProtected.attributedText = undefined;
|
610
|
-
this.nativeTextViewProtected.text = source;
|
611
|
-
}
|
511
|
+
// Clear attributedText or text won't be affected.
|
512
|
+
this.nativeTextViewProtected.attributedText = undefined;
|
513
|
+
this.nativeTextViewProtected.text = source;
|
612
514
|
}
|
613
515
|
if (!style.color && majorVersion >= 13 && UIColor.labelColor) {
|
614
516
|
this._setColor(UIColor.labelColor);
|
615
517
|
}
|
616
518
|
}
|
617
|
-
|
618
|
-
|
619
|
-
|
620
|
-
|
621
|
-
|
622
|
-
|
623
|
-
|
624
|
-
|
625
|
-
maxFontSize = Math.max(maxFontSize, s.style.fontSize);
|
626
|
-
}
|
627
|
-
}
|
628
|
-
this.currentMaxFontSize = maxFontSize;
|
629
|
-
return super.createNSMutableAttributedString(formattedString);
|
630
|
-
}
|
631
|
-
createMutableStringForSpan(span, text) {
|
632
|
-
const viewFont = this.nativeTextViewProtected.font;
|
633
|
-
const attrDict = {};
|
634
|
-
const style = span.style;
|
635
|
-
let align = style.verticalAlignment || span.parent.style.verticalAlignment;
|
636
|
-
if (!align || align === 'stretch') {
|
637
|
-
align = this.verticalTextAlignment;
|
638
|
-
}
|
639
|
-
const font = new Font(style.fontFamily, style.fontSize, style.fontStyle, style.fontWeight);
|
640
|
-
const iosFont = font.getUIFont(viewFont);
|
641
|
-
attrDict[NSFontAttributeName] = iosFont;
|
642
|
-
if (span.color) {
|
643
|
-
const color = span.color instanceof Color ? span.color : new Color(span.color);
|
644
|
-
attrDict[NSForegroundColorAttributeName] = color.ios;
|
645
|
-
}
|
646
|
-
// We don't use isSet function here because defaultValue for backgroundColor is null.
|
647
|
-
const backgroundColor = style.backgroundColor || span.parent.backgroundColor;
|
648
|
-
if (backgroundColor) {
|
649
|
-
const color = backgroundColor instanceof Color ? backgroundColor : new Color(backgroundColor);
|
650
|
-
attrDict[NSBackgroundColorAttributeName] = color.ios;
|
651
|
-
}
|
652
|
-
const textDecoration = getClosestPropertyValue(textDecorationProperty, span);
|
653
|
-
if (textDecoration) {
|
654
|
-
const underline = textDecoration.indexOf('underline') !== -1;
|
655
|
-
if (underline) {
|
656
|
-
attrDict[NSUnderlineStyleAttributeName] = underline;
|
657
|
-
}
|
658
|
-
const strikethrough = textDecoration.indexOf('line-through') !== -1;
|
659
|
-
if (strikethrough) {
|
660
|
-
attrDict[NSStrikethroughStyleAttributeName] = strikethrough;
|
661
|
-
}
|
662
|
-
}
|
663
|
-
if (align && align !== 'stretch') {
|
664
|
-
if (iosFont) {
|
665
|
-
attrDict[NSBaselineOffsetAttributeName] = -computeBaseLineOffset(align, -iosFont.ascender, -iosFont.descender, -iosFont.ascender, -iosFont.descender, iosFont.pointSize, this.currentMaxFontSize);
|
666
|
-
}
|
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;
|
667
527
|
}
|
668
|
-
|
528
|
+
this.nativeTextViewProtected.attributedText = attrText;
|
669
529
|
}
|
670
530
|
[paddingTopProperty.getDefault]() {
|
671
531
|
return {
|
@@ -774,19 +634,23 @@ export class Label extends LabelBase {
|
|
774
634
|
}
|
775
635
|
}
|
776
636
|
}
|
777
|
-
textViewDidChange(textView, width, height) {
|
778
|
-
if (
|
779
|
-
this.needsAutoFontSize = false;
|
637
|
+
textViewDidChange(textView, width, height, force = false) {
|
638
|
+
if (textView && this.autoFontSize) {
|
780
639
|
if ((!textView.attributedText && !textView.text) ||
|
781
640
|
(width === undefined && height === undefined && CGSizeEqualToSize(textView.bounds.size, CGSizeZero))) {
|
782
641
|
return;
|
783
642
|
}
|
784
643
|
const textViewSize = textView.frame.size;
|
785
|
-
const fixedWidth = width !== undefined ? width : textViewSize.width;
|
786
|
-
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);
|
787
646
|
if (fixedWidth === 0 || fixedHeight === 0) {
|
788
647
|
return;
|
789
648
|
}
|
649
|
+
const autoSizeKey = fixedWidth + '_' + fixedHeight;
|
650
|
+
if (!force && autoSizeKey === this._lastAutoSizeKey) {
|
651
|
+
return;
|
652
|
+
}
|
653
|
+
this._lastAutoSizeKey = autoSizeKey;
|
790
654
|
const nbLines = textView.textContainer.maximumNumberOfLines;
|
791
655
|
// we need to reset verticalTextAlignment or computation will be wrong
|
792
656
|
this.updateTextContainerInset(false);
|
@@ -854,10 +718,10 @@ export class Label extends LabelBase {
|
|
854
718
|
}
|
855
719
|
}
|
856
720
|
[autoFontSizeProperty.setNative](value) {
|
857
|
-
if (value
|
858
|
-
this.
|
859
|
-
|
860
|
-
|
721
|
+
if (value) {
|
722
|
+
if (this.isLayoutValid && (this.text || this.html || this.formattedText)) {
|
723
|
+
this.textViewDidChange(this.nativeTextViewProtected, undefined, undefined, true);
|
724
|
+
}
|
861
725
|
}
|
862
726
|
else {
|
863
727
|
this[fontInternalProperty.setNative](this.style.fontInternal);
|