@nativescript-community/ui-label 1.1.25 → 1.2.3
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 +5 -3
- package/label.android.js +48 -12
- package/label.ios.d.ts +3 -7
- package/label.ios.js +66 -200
- package/package.json +3 -3
- package/platforms/android/include.gradle +1 -1
- package/platforms/android/native-api-usage.json +15 -0
- package/platforms/android/java/com/nativescript/label/EllipsizingTextView.java +0 -497
- 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.3](https://github.com/nativescript-community/ui-label/compare/v1.2.2...v1.2.3) (2022-01-13)
|
7
|
+
|
8
|
+
**Note:** Version bump only for package @nativescript-community/ui-label
|
9
|
+
|
10
|
+
|
11
|
+
|
12
|
+
|
13
|
+
|
14
|
+
## [1.2.2](https://github.com/nativescript-community/ui-label/compare/v1.2.1...v1.2.2) (2022-01-08)
|
15
|
+
|
16
|
+
**Note:** Version bump only for package @nativescript-community/ui-label
|
17
|
+
|
18
|
+
|
19
|
+
|
20
|
+
|
21
|
+
|
22
|
+
## [1.2.1](https://github.com/nativescript-community/ui-label/compare/v1.2.0...v1.2.1) (2022-01-02)
|
23
|
+
|
24
|
+
**Note:** Version bump only for package @nativescript-community/ui-label
|
25
|
+
|
26
|
+
|
27
|
+
|
28
|
+
|
29
|
+
|
30
|
+
# [1.2.0](https://github.com/nativescript-community/ui-label/compare/v1.1.25...v1.2.0) (2021-10-20)
|
31
|
+
|
32
|
+
|
33
|
+
### Features
|
34
|
+
|
35
|
+
* **android:** native-api-usage ([40d28dd](https://github.com/nativescript-community/ui-label/commit/40d28dd648d993f1a7d844c677e20e8dfb1d67c0))
|
36
|
+
|
37
|
+
|
38
|
+
|
39
|
+
|
40
|
+
|
6
41
|
## [1.1.25](https://github.com/nativescript-community/ui-label/compare/v1.1.24...v1.1.25) (2021-08-09)
|
7
42
|
|
8
43
|
**Note:** Version bump only for package @nativescript-community/ui-label
|
package/label.android.d.ts
CHANGED
@@ -42,9 +42,8 @@ declare abstract class LabelBase extends View implements LabelViewDefinition {
|
|
42
42
|
linkUnderline: boolean;
|
43
43
|
html: string;
|
44
44
|
selectable: boolean;
|
45
|
-
|
45
|
+
mIsSingleLine: 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;
|
@@ -77,10 +76,13 @@ declare abstract class LabelBase extends View implements LabelViewDefinition {
|
|
77
76
|
}
|
78
77
|
export declare class Label extends LabelBase {
|
79
78
|
nativeViewProtected: com.nativescript.label.EllipsizingTextView;
|
80
|
-
|
79
|
+
mHandleFontSize: boolean;
|
80
|
+
private mAutoFontSize;
|
81
81
|
private _defaultMovementMethod;
|
82
82
|
get nativeTextViewProtected(): com.nativescript.label.EllipsizingTextView;
|
83
83
|
createNativeView(): com.nativescript.label.EllipsizingTextView;
|
84
|
+
private enableAutoSize;
|
85
|
+
private disableAutoSize;
|
84
86
|
createFormattedTextNative(value: any): any;
|
85
87
|
createHTMLString(): globalAndroid.text.SpannableStringBuilder;
|
86
88
|
_tappable: boolean;
|
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';
|
@@ -267,7 +269,8 @@ LabelBase = __decorate([
|
|
267
269
|
export class Label extends LabelBase {
|
268
270
|
constructor() {
|
269
271
|
super(...arguments);
|
270
|
-
this.
|
272
|
+
this.mHandleFontSize = true;
|
273
|
+
this.mAutoFontSize = false;
|
271
274
|
this._tappable = false;
|
272
275
|
}
|
273
276
|
get nativeTextViewProtected() {
|
@@ -357,7 +360,18 @@ export class Label extends LabelBase {
|
|
357
360
|
}
|
358
361
|
[textAlignmentProperty.setNative](value) {
|
359
362
|
const view = this.nativeTextViewProtected;
|
360
|
-
|
363
|
+
if (android.os.Build.VERSION.SDK_INT >= 26) {
|
364
|
+
if (value === 'justify') {
|
365
|
+
view.setJustificationMode(android.text.Layout.JUSTIFICATION_MODE_INTER_WORD);
|
366
|
+
}
|
367
|
+
else {
|
368
|
+
view.setJustificationMode(android.text.Layout.JUSTIFICATION_MODE_NONE);
|
369
|
+
view.setGravity(getHorizontalGravity(value) | getVerticalGravity(this.verticalTextAlignment));
|
370
|
+
}
|
371
|
+
}
|
372
|
+
else {
|
373
|
+
view.setGravity(getHorizontalGravity(value) | getVerticalGravity(this.verticalTextAlignment));
|
374
|
+
}
|
361
375
|
}
|
362
376
|
[colorProperty.setNative](value) {
|
363
377
|
const color = !value || value instanceof Color ? value : new Color(value);
|
@@ -369,18 +383,37 @@ export class Label extends LabelBase {
|
|
369
383
|
}
|
370
384
|
}
|
371
385
|
[fontSizeProperty.setNative](value) {
|
386
|
+
// setTextSize is ignored if autoFontSize is enabled
|
387
|
+
// so we need to disable autoFontSize just to set textSize
|
388
|
+
if (this.mAutoFontSize) {
|
389
|
+
this.disableAutoSize();
|
390
|
+
}
|
372
391
|
if (typeof value === 'number') {
|
373
392
|
this.nativeTextViewProtected.setTextSize(value);
|
374
393
|
}
|
375
394
|
else {
|
376
395
|
this.nativeTextViewProtected.setTextSize(android.util.TypedValue.COMPLEX_UNIT_PX, value.nativeSize);
|
377
396
|
}
|
397
|
+
if (this.mAutoFontSize) {
|
398
|
+
this.enableAutoSize();
|
399
|
+
}
|
378
400
|
}
|
379
401
|
[lineHeightProperty.setNative](value) {
|
380
|
-
|
402
|
+
if (sdkVersion() >= 28) {
|
403
|
+
this.nativeTextViewProtected.setLineHeight(value * layout.getDisplayDensity());
|
404
|
+
}
|
405
|
+
else {
|
406
|
+
const fontHeight = this.nativeTextViewProtected.getPaint().getFontMetricsInt(null);
|
407
|
+
this.nativeTextViewProtected.setLineSpacing(value * layout.getDisplayDensity() - fontHeight, 1);
|
408
|
+
}
|
381
409
|
}
|
382
410
|
[fontInternalProperty.setNative](value) {
|
383
|
-
|
411
|
+
const androidFont = value instanceof Font ? value.getAndroidTypeface() : value;
|
412
|
+
this.nativeTextViewProtected.setTypeface(androidFont);
|
413
|
+
if (this.lineHeight && sdkVersion() < 28) {
|
414
|
+
const fontHeight = this.nativeTextViewProtected.getPaint().getFontMetricsInt(null);
|
415
|
+
this.nativeTextViewProtected.setLineSpacing(this.lineHeight * layout.getDisplayDensity() - fontHeight, 1);
|
416
|
+
}
|
384
417
|
}
|
385
418
|
[textDecorationProperty.setNative](value) {
|
386
419
|
switch (value) {
|
@@ -428,12 +461,19 @@ export class Label extends LabelBase {
|
|
428
461
|
[paddingLeftProperty.setNative](value) {
|
429
462
|
org.nativescript.widgets.ViewHelper.setPaddingLeft(this.nativeTextViewProtected, Length.toDevicePixels(value, 0) + Length.toDevicePixels(this.style.borderLeftWidth, 0));
|
430
463
|
}
|
464
|
+
enableAutoSize() {
|
465
|
+
androidx.core.widget.TextViewCompat.setAutoSizeTextTypeUniformWithConfiguration(this.nativeView, this.minFontSize || 10, this.maxFontSize || 200, this.autoFontSizeStep || 1, android.util.TypedValue.COMPLEX_UNIT_DIP);
|
466
|
+
}
|
467
|
+
disableAutoSize() {
|
468
|
+
androidx.core.widget.TextViewCompat.setAutoSizeTextTypeWithDefaults(this.nativeView, androidx.core.widget.TextViewCompat.AUTO_SIZE_TEXT_TYPE_NONE);
|
469
|
+
}
|
431
470
|
[autoFontSizeProperty.setNative](value) {
|
471
|
+
this.mAutoFontSize = value;
|
432
472
|
if (value) {
|
433
|
-
|
473
|
+
this.enableAutoSize();
|
434
474
|
}
|
435
475
|
else {
|
436
|
-
|
476
|
+
this.disableAutoSize();
|
437
477
|
}
|
438
478
|
}
|
439
479
|
[selectableProperty.setNative](value) {
|
@@ -499,11 +539,7 @@ export class Label extends LabelBase {
|
|
499
539
|
return;
|
500
540
|
}
|
501
541
|
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) {
|
542
|
+
if (this.html) {
|
507
543
|
transformedText = this.createHTMLString();
|
508
544
|
textProperty.nativeValueChange(this, this.html === null || this.html === undefined ? '' : this.html);
|
509
545
|
}
|
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;
|
@@ -38,9 +35,8 @@ export declare class Label extends LabelBase {
|
|
38
35
|
_setSpannablesFontSizeWithRatio(ratio: any): void;
|
39
36
|
_setNativeText(): void;
|
40
37
|
setTextDecorationAndTransform(): void;
|
41
|
-
|
42
|
-
|
43
|
-
createMutableStringForSpan(span: Span, text: string): NSMutableAttributedString;
|
38
|
+
createFormattedTextNative(value: FormattedString): any;
|
39
|
+
setFormattedTextDecorationAndTransform(): void;
|
44
40
|
fontSizeRatio: number;
|
45
41
|
_lastAutoSizeKey: string;
|
46
42
|
textViewDidChange(textView: UITextView, width?: any, height?: any, force?: boolean): void;
|
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';
|
@@ -103,14 +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
|
-
// if (iOSUseDTCoreText && !Label.DTCORETEXT_INIT) {
|
110
|
-
// Label.DTCORETEXT_INIT = true;
|
111
|
-
// DTCoreTextFontDescriptor.asyncPreloadFontLookupTable();
|
112
|
-
// }
|
113
108
|
}
|
109
|
+
// constructor() {
|
110
|
+
// super();
|
111
|
+
// if (iOSUseDTCoreText && !Label.DTCORETEXT_INIT) {
|
112
|
+
// Label.DTCORETEXT_INIT = true;
|
113
|
+
// DTCoreTextFontDescriptor.asyncPreloadFontLookupTable();
|
114
|
+
// }
|
115
|
+
// }
|
114
116
|
createNativeView() {
|
115
117
|
const view = UITextView.new();
|
116
118
|
if (!view.font) {
|
@@ -123,13 +125,10 @@ export class Label extends LabelBase {
|
|
123
125
|
view.backgroundColor = UIColor.clearColor;
|
124
126
|
view.userInteractionEnabled = true;
|
125
127
|
view.dataDetectorTypes = -1 /* All */;
|
126
|
-
view.textContainerInset =
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
right: 0
|
131
|
-
};
|
132
|
-
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;
|
133
132
|
// view.textContainer.lineBreakMode = NSLineBreakMode.ByCharWrapping;
|
134
133
|
return view;
|
135
134
|
}
|
@@ -140,12 +139,6 @@ export class Label extends LabelBase {
|
|
140
139
|
this._observer['_owner'] = new WeakRef(this);
|
141
140
|
this.nativeViewProtected.addObserverForKeyPathOptionsContext(this._observer, 'contentSize', 1 /* New */, null);
|
142
141
|
this.nativeViewProtected.attributedText = this.attributedString;
|
143
|
-
// this.htmlText = null;
|
144
|
-
// this.needsHTMLUpdate = false;
|
145
|
-
// this.updatingHTML = false;
|
146
|
-
// if (this.htmlText && this.needsHTMLUpdate) {
|
147
|
-
// this.updateHTMLString();
|
148
|
-
// }
|
149
142
|
}
|
150
143
|
disposeNativeView() {
|
151
144
|
this._delegate = null;
|
@@ -169,25 +162,31 @@ export class Label extends LabelBase {
|
|
169
162
|
}
|
170
163
|
computeTextHeight(size) {
|
171
164
|
const tv = this.nativeTextViewProtected;
|
172
|
-
const
|
173
|
-
|
174
|
-
if (
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
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;
|
179
178
|
}
|
180
179
|
updateTextContainerInset(applyVerticalTextAlignment = true) {
|
181
|
-
|
182
|
-
// return;
|
183
|
-
// }
|
180
|
+
var _e, _f;
|
184
181
|
const tv = this.nativeTextViewProtected;
|
185
182
|
const top = layout.toDeviceIndependentPixels(this.effectivePaddingTop + this.effectiveBorderTopWidth);
|
186
183
|
const right = layout.toDeviceIndependentPixels(this.effectivePaddingRight + this.effectiveBorderRightWidth);
|
187
184
|
const bottom = layout.toDeviceIndependentPixels(this.effectivePaddingBottom + this.effectiveBorderBottomWidth);
|
188
185
|
const left = layout.toDeviceIndependentPixels(this.effectivePaddingLeft + this.effectiveBorderLeftWidth);
|
189
|
-
if (!applyVerticalTextAlignment ||
|
190
|
-
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 = {
|
191
190
|
top,
|
192
191
|
left,
|
193
192
|
bottom,
|
@@ -198,7 +197,7 @@ export class Label extends LabelBase {
|
|
198
197
|
switch (this.verticalTextAlignment) {
|
199
198
|
case 'initial': // not supported
|
200
199
|
case 'top':
|
201
|
-
|
200
|
+
tv.textContainerInset = {
|
202
201
|
top,
|
203
202
|
left,
|
204
203
|
bottom,
|
@@ -210,7 +209,7 @@ export class Label extends LabelBase {
|
|
210
209
|
const height = this.computeTextHeight(CGSizeMake(tv.bounds.size.width, 10000));
|
211
210
|
let topCorrect = (tv.bounds.size.height - top - bottom - height * tv.zoomScale) / 2.0;
|
212
211
|
topCorrect = topCorrect < 0.0 ? 0.0 : topCorrect;
|
213
|
-
|
212
|
+
tv.textContainerInset = {
|
214
213
|
top: top + topCorrect,
|
215
214
|
left,
|
216
215
|
bottom,
|
@@ -220,9 +219,9 @@ export class Label extends LabelBase {
|
|
220
219
|
}
|
221
220
|
case 'bottom': {
|
222
221
|
const height = this.computeTextHeight(CGSizeMake(tv.bounds.size.width, 10000));
|
223
|
-
let bottomCorrect = tv.bounds.size.height - bottom - height * tv.zoomScale;
|
222
|
+
let bottomCorrect = tv.bounds.size.height - top - bottom - height * tv.zoomScale;
|
224
223
|
bottomCorrect = bottomCorrect < 0.0 ? 0.0 : bottomCorrect;
|
225
|
-
|
224
|
+
tv.textContainerInset = {
|
226
225
|
top: top + bottomCorrect,
|
227
226
|
left,
|
228
227
|
bottom,
|
@@ -236,78 +235,6 @@ export class Label extends LabelBase {
|
|
236
235
|
get ios() {
|
237
236
|
return this.nativeViewProtected;
|
238
237
|
}
|
239
|
-
// setTextDecorationAndTransform() {
|
240
|
-
// const style = this.style;
|
241
|
-
// const dict = new Map<string, any>();
|
242
|
-
// switch (style.textDecoration) {
|
243
|
-
// case 'none':
|
244
|
-
// break;
|
245
|
-
// case 'underline':
|
246
|
-
// // TODO: Replace deprecated `StyleSingle` with `Single` after the next typings update
|
247
|
-
// dict.set(NSUnderlineStyleAttributeName, NSUnderlineStyle.Single);
|
248
|
-
// break;
|
249
|
-
// case 'line-through':
|
250
|
-
// // TODO: Replace deprecated `StyleSingle` with `Single` after the next typings update
|
251
|
-
// dict.set(NSStrikethroughStyleAttributeName, NSUnderlineStyle.Single);
|
252
|
-
// break;
|
253
|
-
// case 'underline line-through':
|
254
|
-
// // TODO: Replace deprecated `StyleSingle` with `Single` after the next typings update
|
255
|
-
// dict.set(NSUnderlineStyleAttributeName, NSUnderlineStyle.Single);
|
256
|
-
// dict.set(NSStrikethroughStyleAttributeName, NSUnderlineStyle.Single);
|
257
|
-
// break;
|
258
|
-
// default:
|
259
|
-
// throw new Error(`Invalid text decoration value: ${style.textDecoration}. Valid values are: 'none', 'underline', 'line-through', 'underline line-through'.`);
|
260
|
-
// }
|
261
|
-
// if (style.letterSpacing !== 0) {
|
262
|
-
// dict.set(NSKernAttributeName, style.letterSpacing * this.nativeTextViewProtected.font.pointSize);
|
263
|
-
// }
|
264
|
-
// if (style.lineHeight || style.whiteSpace === 'nowrap' || (style['lineBreak'] && style['lineBreak'] !== 'none')) {
|
265
|
-
// const paragraphStyle = NSMutableParagraphStyle.alloc().init();
|
266
|
-
// paragraphStyle.minimumLineHeight = style.lineHeight;
|
267
|
-
// // make sure a possible previously set text alignment setting is not lost when line height is specified
|
268
|
-
// paragraphStyle.alignment = (this.nativeTextViewProtected as UITextField | UITextView | UILabel).textAlignment;
|
269
|
-
// // make sure a possible previously set line break mode is not lost when line height is specified
|
270
|
-
// if (style['lineBreak']) {
|
271
|
-
// paragraphStyle.lineBreakMode = lineBreakToLineBreakMode(style['lineBreak']);
|
272
|
-
// } else if (style.whiteSpace) {
|
273
|
-
// paragraphStyle.lineBreakMode = whiteSpaceToLineBreakMode(style.whiteSpace);
|
274
|
-
// }
|
275
|
-
// dict.set(NSParagraphStyleAttributeName, paragraphStyle);
|
276
|
-
// } else if (isTextView && this.style.textAlignment !== 'initial') {
|
277
|
-
// const paragraphStyle = NSMutableParagraphStyle.alloc().init();
|
278
|
-
// paragraphStyle.alignment = this.nativeTextViewProtected.textAlignment;
|
279
|
-
// dict.set(NSParagraphStyleAttributeName, paragraphStyle);
|
280
|
-
// }
|
281
|
-
// if (style.color && dict.size > 0) {
|
282
|
-
// // dict.set(NSForegroundColorAttributeName, style.color.ios);
|
283
|
-
// }
|
284
|
-
// const text = this.text;
|
285
|
-
// const str = text === undefined || text === null ? '' : text.toString();
|
286
|
-
// const source = getTransformedText(str, this.textTransform);
|
287
|
-
// if (dict.size > 0) {
|
288
|
-
// if (isTextView) {
|
289
|
-
// // UITextView's font seems to change inside.
|
290
|
-
// dict.set(NSFontAttributeName, this.nativeTextViewProtected.font);
|
291
|
-
// }
|
292
|
-
// const result = NSMutableAttributedString.alloc().initWithString(source);
|
293
|
-
// result.setAttributesRange(dict as any, { location: 0, length: source.length });
|
294
|
-
// if (this.nativeTextViewProtected instanceof UIButton) {
|
295
|
-
// this.nativeTextViewProtected.setAttributedTitleForState(result, UIControlState.Normal);
|
296
|
-
// } else {
|
297
|
-
// this.nativeTextViewProtected.attributedText = result;
|
298
|
-
// }
|
299
|
-
// } else {
|
300
|
-
// if (this.nativeTextViewProtected instanceof UIButton) {
|
301
|
-
// // Clear attributedText or title won't be affected.
|
302
|
-
// this.nativeTextViewProtected.setAttributedTitleForState(null, UIControlState.Normal);
|
303
|
-
// this.nativeTextViewProtected.setTitleForState(source, UIControlState.Normal);
|
304
|
-
// } else {
|
305
|
-
// // Clear attributedText or text won't be affected.
|
306
|
-
// this.nativeTextViewProtected.attributedText = undefined;
|
307
|
-
// this.nativeTextViewProtected.text = source;
|
308
|
-
// }
|
309
|
-
// }
|
310
|
-
// }
|
311
238
|
_requestLayoutOnTextChanged() {
|
312
239
|
if (this._fixedSize === FixedSize.BOTH) {
|
313
240
|
return;
|
@@ -395,14 +322,13 @@ export class Label extends LabelBase {
|
|
395
322
|
// when in collectionView or pager
|
396
323
|
// if this is done sync (without DTCoreText) while init the cell
|
397
324
|
// it breaks the UICollectionView :s
|
398
|
-
if (usingIOSDTCoreText()) {
|
399
|
-
|
400
|
-
}
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
}
|
325
|
+
// if (usingIOSDTCoreText()) {
|
326
|
+
// this._updateHTMLString();
|
327
|
+
// } else {
|
328
|
+
// setTimeout(() => {
|
329
|
+
this._updateHTMLString();
|
330
|
+
// }, 0);
|
331
|
+
// }
|
406
332
|
}
|
407
333
|
_setColor(color) {
|
408
334
|
if (this.nativeTextViewProtected instanceof UIButton) {
|
@@ -519,6 +445,7 @@ export class Label extends LabelBase {
|
|
519
445
|
else {
|
520
446
|
super._setNativeText();
|
521
447
|
}
|
448
|
+
this.updateTextContainerInset();
|
522
449
|
this._requestLayoutOnTextChanged();
|
523
450
|
}
|
524
451
|
setTextDecorationAndTransform() {
|
@@ -543,25 +470,18 @@ export class Label extends LabelBase {
|
|
543
470
|
if (style.letterSpacing !== 0 && this.nativeTextViewProtected.font) {
|
544
471
|
const kern = style.letterSpacing * this.nativeTextViewProtected.font.pointSize;
|
545
472
|
dict.set(NSKernAttributeName, kern);
|
546
|
-
if (this.nativeTextViewProtected instanceof UITextField) {
|
547
|
-
this.nativeTextViewProtected.defaultTextAttributes.setValueForKey(kern, NSKernAttributeName);
|
548
|
-
}
|
549
473
|
}
|
550
474
|
const isTextView = false;
|
551
|
-
if (style.lineHeight) {
|
475
|
+
if (style.lineHeight !== undefined) {
|
476
|
+
let lineHeight = style.lineHeight;
|
477
|
+
if (lineHeight === 0) {
|
478
|
+
lineHeight = 0.00001;
|
479
|
+
}
|
552
480
|
const paragraphStyle = NSMutableParagraphStyle.alloc().init();
|
553
|
-
paragraphStyle.
|
481
|
+
paragraphStyle.minimumLineHeight = lineHeight;
|
482
|
+
paragraphStyle.maximumLineHeight = lineHeight;
|
554
483
|
// make sure a possible previously set text alignment setting is not lost when line height is specified
|
555
|
-
|
556
|
-
paragraphStyle.alignment = this.nativeTextViewProtected.titleLabel.textAlignment;
|
557
|
-
}
|
558
|
-
else {
|
559
|
-
paragraphStyle.alignment = this.nativeTextViewProtected.textAlignment;
|
560
|
-
}
|
561
|
-
if (this.nativeTextViewProtected instanceof UILabel) {
|
562
|
-
// make sure a possible previously set line break mode is not lost when line height is specified
|
563
|
-
paragraphStyle.lineBreakMode = this.nativeTextViewProtected.lineBreakMode;
|
564
|
-
}
|
484
|
+
paragraphStyle.alignment = this.nativeTextViewProtected.textAlignment;
|
565
485
|
dict.set(NSParagraphStyleAttributeName, paragraphStyle);
|
566
486
|
}
|
567
487
|
else if (isTextView) {
|
@@ -585,81 +505,27 @@ export class Label extends LabelBase {
|
|
585
505
|
location: 0,
|
586
506
|
length: source.length
|
587
507
|
});
|
588
|
-
|
589
|
-
this.nativeTextViewProtected.setAttributedTitleForState(result, 0 /* Normal */);
|
590
|
-
}
|
591
|
-
else {
|
592
|
-
this.nativeTextViewProtected.attributedText = result;
|
593
|
-
}
|
508
|
+
this.nativeTextViewProtected.attributedText = result;
|
594
509
|
}
|
595
510
|
else {
|
596
|
-
|
597
|
-
|
598
|
-
|
599
|
-
this.nativeTextViewProtected.setTitleForState(source, 0 /* Normal */);
|
600
|
-
}
|
601
|
-
else {
|
602
|
-
// Clear attributedText or text won't be affected.
|
603
|
-
this.nativeTextViewProtected.attributedText = undefined;
|
604
|
-
this.nativeTextViewProtected.text = source;
|
605
|
-
}
|
511
|
+
// Clear attributedText or text won't be affected.
|
512
|
+
this.nativeTextViewProtected.attributedText = undefined;
|
513
|
+
this.nativeTextViewProtected.text = source;
|
606
514
|
}
|
607
515
|
if (!style.color && majorVersion >= 13 && UIColor.labelColor) {
|
608
516
|
this._setColor(UIColor.labelColor);
|
609
517
|
}
|
610
518
|
}
|
611
|
-
|
612
|
-
|
613
|
-
|
614
|
-
|
615
|
-
|
616
|
-
|
617
|
-
|
618
|
-
|
619
|
-
maxFontSize = Math.max(maxFontSize, s.style.fontSize);
|
620
|
-
}
|
621
|
-
}
|
622
|
-
this.currentMaxFontSize = maxFontSize;
|
623
|
-
return super.createNSMutableAttributedString(formattedString);
|
624
|
-
}
|
625
|
-
createMutableStringForSpan(span, text) {
|
626
|
-
const viewFont = this.nativeTextViewProtected.font;
|
627
|
-
const attrDict = {};
|
628
|
-
const style = span.style;
|
629
|
-
let align = style.verticalAlignment || span.parent.style.verticalAlignment;
|
630
|
-
if (!align || align === 'stretch') {
|
631
|
-
align = this.verticalTextAlignment;
|
632
|
-
}
|
633
|
-
const font = new Font(style.fontFamily, style.fontSize, style.fontStyle, style.fontWeight);
|
634
|
-
const iosFont = font.getUIFont(viewFont);
|
635
|
-
attrDict[NSFontAttributeName] = iosFont;
|
636
|
-
if (span.color) {
|
637
|
-
const color = span.color instanceof Color ? span.color : new Color(span.color);
|
638
|
-
attrDict[NSForegroundColorAttributeName] = color.ios;
|
639
|
-
}
|
640
|
-
// We don't use isSet function here because defaultValue for backgroundColor is null.
|
641
|
-
const backgroundColor = style.backgroundColor || span.parent.backgroundColor;
|
642
|
-
if (backgroundColor) {
|
643
|
-
const color = backgroundColor instanceof Color ? backgroundColor : new Color(backgroundColor);
|
644
|
-
attrDict[NSBackgroundColorAttributeName] = color.ios;
|
645
|
-
}
|
646
|
-
const textDecoration = getClosestPropertyValue(textDecorationProperty, span);
|
647
|
-
if (textDecoration) {
|
648
|
-
const underline = textDecoration.indexOf('underline') !== -1;
|
649
|
-
if (underline) {
|
650
|
-
attrDict[NSUnderlineStyleAttributeName] = underline;
|
651
|
-
}
|
652
|
-
const strikethrough = textDecoration.indexOf('line-through') !== -1;
|
653
|
-
if (strikethrough) {
|
654
|
-
attrDict[NSStrikethroughStyleAttributeName] = strikethrough;
|
655
|
-
}
|
656
|
-
}
|
657
|
-
if (align && align !== 'stretch') {
|
658
|
-
if (iosFont) {
|
659
|
-
attrDict[NSBaselineOffsetAttributeName] = -computeBaseLineOffset(align, -iosFont.ascender, -iosFont.descender, -iosFont.ascender, -iosFont.descender, iosFont.pointSize, this.currentMaxFontSize);
|
660
|
-
}
|
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;
|
661
527
|
}
|
662
|
-
|
528
|
+
this.nativeTextViewProtected.attributedText = attrText;
|
663
529
|
}
|
664
530
|
[paddingTopProperty.getDefault]() {
|
665
531
|
return {
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@nativescript-community/ui-label",
|
3
|
-
"version": "1.
|
3
|
+
"version": "1.2.3",
|
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.
|
35
|
+
"@nativescript-community/text": "^1.4.31"
|
36
36
|
},
|
37
|
-
"gitHead": "
|
37
|
+
"gitHead": "69a32f6e41a6bc19b16b479a77c116a94da62fe4"
|
38
38
|
}
|
@@ -8,5 +8,5 @@ dependencies {
|
|
8
8
|
implementation "androidx.appcompat:appcompat:$androidXAppCompat"
|
9
9
|
implementation "androidx.core:core:$androidxVersion"
|
10
10
|
implementation "androidx.annotation:annotation:1.1.0"
|
11
|
-
//
|
11
|
+
// implementation 'com.lsjwzh.widget:FastTextView:1.2.20'
|
12
12
|
}
|
@@ -0,0 +1,15 @@
|
|
1
|
+
{
|
2
|
+
"uses": [
|
3
|
+
"android.text.style:URLSpan*",
|
4
|
+
"android.text.style:ClickableSpan*",
|
5
|
+
"android.text:TextPaint*",
|
6
|
+
"android.text.method:MovementMethod*",
|
7
|
+
"android.text.TextUtils:TruncateAt*",
|
8
|
+
"android.text:Layout*",
|
9
|
+
"android.os:Build*",
|
10
|
+
"android.util:TypedValue*",
|
11
|
+
"android.graphics:Paint*",
|
12
|
+
"android.text:Spanned*",
|
13
|
+
"androidx.core.widget:TextViewCompat*"
|
14
|
+
]
|
15
|
+
}
|