@@ -59,14 +59,23 @@ Font.prototype.getAndroidTypeface = function() {
59
59
declare module 'tns-core-modules/text/formatted-string' {
60
60
interface FormattedString {
61
61
toNativeString ( ) : string ;
62
+ addPropertyChangeHandler ( ) : void ;
63
+ removePropertyChangeHandler ( ) : void ;
62
64
}
63
65
}
64
66
declare module 'tns-core-modules/text/span' {
65
67
interface Span {
66
68
toNativeString ( ) : string ;
69
+ addPropertyChangeHandler ( ) : void ;
70
+ removePropertyChangeHandler ( ) : void ;
67
71
}
68
72
}
69
73
74
+ FormattedString . prototype . addPropertyChangeHandler = function ( ) { }
75
+ FormattedString . prototype . removePropertyChangeHandler = function ( ) { }
76
+ Span . prototype . addPropertyChangeHandler = function ( ) { }
77
+ Span . prototype . removePropertyChangeHandler = function ( ) { }
78
+
70
79
FormattedString . prototype . toNativeString = function ( ) {
71
80
let result = '' ;
72
81
const length = this . _spans . length ;
@@ -117,159 +126,9 @@ Span.prototype.toNativeString = function() {
117
126
118
127
return result ;
119
128
} ;
120
- // import { Span } from 'tns-core-modules/text/span';
121
129
122
130
export * from './label-common' ;
123
131
124
- // let _useAndroidX;
125
- // function useAndroidX() {
126
- // if (_useAndroidX === undefined) {
127
- // _useAndroidX = !!(global as any).androidx && !!(global as any).androidx.appcompat;
128
- // }
129
- // return _useAndroidX;
130
- // }
131
- // let _HtmlCompat: typeof androidx.core.text.HtmlCompat;
132
- // function HtmlCompat() {
133
- // if (_HtmlCompat === undefined) {
134
- // _HtmlCompat = useAndroidX() ? (global as any).androidx.core.text.HtmlCompat : android.text.Html;
135
- // }
136
- // return _HtmlCompat;
137
- // }
138
- // let _ContentPackageName: typeof androidx.core.content;
139
- // function ContentPackageName() {
140
- // if (_ContentPackageName === undefined) {
141
- // _ContentPackageName = useAndroidX() ? (global as any).androidx.core.content : (android as any).support.v4.content;
142
- // }
143
- // return _ContentPackageName;
144
- // }
145
- // let appAssets: android.content.res.AssetManager;
146
- // const typefaceCache = new Map<string, android.graphics.Typeface>();
147
- // const FONTS_BASE_PATH = '/fonts/';
148
- // function loadFontFromFile(fontFamily: string): android.graphics.Typeface {
149
- // if (fontFamily.startsWith('res/')) {
150
- // let result = typefaceCache.get(fontFamily);
151
- // if (!result) {
152
- // const context = application.android.context;
153
- // const fontID = context.getResources().getIdentifier(fontFamily.slice(4), 'font', context.getPackageName());
154
- // result = ContentPackageName().res.ResourcesCompat.getFont(context, fontID);
155
- // if (result) {
156
- // typefaceCache.set(fontFamily, result);
157
- // }
158
- // return result;
159
- // }
160
- // }
161
- // appAssets = appAssets || application.android.context.getAssets();
162
- // if (!appAssets) {
163
- // return null;
164
- // }
165
-
166
- // let result = typefaceCache.get(fontFamily);
167
- // // Check for undefined explicitly as null mean we tried to load the font, but failed.
168
- // if (result === undefined) {
169
- // result = null;
170
-
171
- // let fontAssetPath: string;
172
- // const basePath = fs.path.join(fs.knownFolders.currentApp().path, 'fonts', fontFamily);
173
- // if (fs.File.exists(basePath + '.ttf')) {
174
- // fontAssetPath = FONTS_BASE_PATH + fontFamily + '.ttf';
175
- // } else if (fs.File.exists(basePath + '.otf')) {
176
- // fontAssetPath = FONTS_BASE_PATH + fontFamily + '.otf';
177
- // } else {
178
- // if (traceEnabled()) {
179
- // traceWrite('Could not find font file for ' + fontFamily, traceCategories.Error, traceMessageType.error);
180
- // }
181
- // }
182
-
183
- // if (fontAssetPath) {
184
- // try {
185
- // fontAssetPath = fs.path.join(fs.knownFolders.currentApp().path, fontAssetPath);
186
- // result = android.graphics.Typeface.createFromFile(fontAssetPath);
187
- // } catch (e) {
188
- // if (traceEnabled()) {
189
- // traceWrite('Error loading font asset: ' + fontAssetPath, traceCategories.Error, traceMessageType.error);
190
- // }
191
- // }
192
- // }
193
- // typefaceCache.set(fontFamily, result);
194
- // }
195
-
196
- // return result;
197
- // }
198
-
199
- // function createTypeface(font: Font): android.graphics.Typeface {
200
- // let fontStyle = 0;
201
- // if (font.isBold) {
202
- // fontStyle |= android.graphics.Typeface.BOLD;
203
- // }
204
- // if (font.isItalic) {
205
- // fontStyle |= android.graphics.Typeface.ITALIC;
206
- // }
207
-
208
- // // http://stackoverflow.com/questions/19691530/valid-values-for-androidfontfamily-and-what-they-map-to
209
- // const fonts = parseFontFamily(font.fontFamily);
210
- // let result = null;
211
- // for (let i = 0; i < fonts.length; i++) {
212
- // switch (fonts[i].toLowerCase()) {
213
- // case genericFontFamilies.serif:
214
- // result = android.graphics.Typeface.create('serif' + getFontWeightSuffix(font.fontWeight), fontStyle);
215
- // break;
216
-
217
- // case genericFontFamilies.sansSerif:
218
- // case genericFontFamilies.system:
219
- // result = android.graphics.Typeface.create('sans-serif' + getFontWeightSuffix(font.fontWeight), fontStyle);
220
- // break;
221
-
222
- // case genericFontFamilies.monospace:
223
- // result = android.graphics.Typeface.create('monospace' + getFontWeightSuffix(font.fontWeight), fontStyle);
224
- // break;
225
-
226
- // default:
227
- // result = loadFontFromFile(fonts[i]);
228
- // if (result && fontStyle) {
229
- // result = android.graphics.Typeface.create(result, fontStyle);
230
- // }
231
- // break;
232
- // }
233
-
234
- // if (result) {
235
- // // Found the font!
236
- // break;
237
- // }
238
- // }
239
-
240
- // if (!result) {
241
- // result = android.graphics.Typeface.create('sans-serif' + getFontWeightSuffix(font.fontWeight), fontStyle);
242
- // }
243
-
244
- // return result;
245
- // }
246
-
247
- // function getFontWeightSuffix(fontWeight: FontWeight): string {
248
- // switch (fontWeight) {
249
- // case FontWeight.THIN:
250
- // return android.os.Build.VERSION.SDK_INT >= 16 ? '-thin' : '';
251
- // case FontWeight.EXTRA_LIGHT:
252
- // case FontWeight.LIGHT:
253
- // return android.os.Build.VERSION.SDK_INT >= 16 ? '-light' : '';
254
- // case FontWeight.NORMAL:
255
- // case '400':
256
- // case undefined:
257
- // case null:
258
- // return '';
259
- // case FontWeight.MEDIUM:
260
- // case FontWeight.SEMI_BOLD:
261
- // return android.os.Build.VERSION.SDK_INT >= 21 ? '-medium' : '';
262
- // case FontWeight.BOLD:
263
- // case '700':
264
- // case FontWeight.EXTRA_BOLD:
265
- // return '';
266
- // case FontWeight.BLACK:
267
- // return android.os.Build.VERSION.SDK_INT >= 21 ? '-black' : '';
268
- // default:
269
- // throw new Error(`Invalid font weight: "${fontWeight}"`);
270
- // }
271
- // }
272
-
273
132
let TextView : typeof android . widget . TextView ;
274
133
275
134
const CHILD_SPAN = 'Span' ;
@@ -368,12 +227,12 @@ class LabelBase extends View implements LabelViewDefinition {
368
227
this . requestLayout ( ) ;
369
228
}
370
229
371
- eachChild ( callback : ( child : ViewBase ) => boolean ) : void {
372
- let text = this . formattedText ;
373
- if ( text ) {
374
- callback ( text ) ;
375
- }
376
- }
230
+ // eachChild(callback: (child: ViewBase) => boolean): void {
231
+ // let text = this.formattedText;
232
+ // if (text) {
233
+ // callback(text);
234
+ // }
235
+ // }
377
236
378
237
_setNativeText ( reset : boolean = false ) : void {
379
238
//
@@ -424,17 +283,18 @@ export class Label extends LabelBase {
424
283
// })();
425
284
}
426
285
427
- @profile
428
- setHtml ( value : string ) {
429
- const nativeView = this . nativeViewProtected ;
430
- if ( value ) {
431
- nativeView . setText ( ( com as any ) . nativescript . label . Font . stringBuilderFromHtmlString ( context , fontPath , value ) ) ;
432
- } else {
433
- nativeView . setText ( null ) ;
434
- }
435
- }
286
+ // @profile
287
+ // setHtml(value: string) {
288
+ // const nativeView = this.nativeViewProtected;
289
+ // if (value) {
290
+ // nativeView.setText((com as any).nativescript.label.Font.stringBuilderFromHtmlString(context, fontPath, value));
291
+ // } else {
292
+ // nativeView.setText(null);
293
+ // }
294
+ // }
436
295
[ htmlProperty . setNative ] ( value : string ) {
437
- this . setHtml ( value ) ;
296
+ // this.setHtml(value);
297
+ this . _setNativeText ( ) ;
438
298
// textProperty.nativeValueChange(this, value === null || value === undefined ? '' : value.toString());
439
299
}
440
300
@@ -531,7 +391,8 @@ export class Label extends LabelBase {
531
391
532
392
[ formattedTextProperty . setNative ] ( value : FormattedString ) {
533
393
// profile('formattedTextProperty', () => {
534
- const nativeView = this . nativeTextViewProtected ;
394
+ // const nativeView = this.nativeTextViewProtected;
395
+ this . _setNativeText ( ) ;
535
396
// if (!value) {
536
397
// if (nativeView instanceof android.widget.Button && nativeView.getTransformationMethod() instanceof TextTransformation) {
537
398
// nativeView.setTransformationMethod(this._defaultTransformationMethod);
@@ -543,10 +404,10 @@ export class Label extends LabelBase {
543
404
// return;
544
405
// }
545
406
546
- const spannableStringBuilder = createSpannableStringBuilder ( value ) ;
547
- nativeView . setText ( < any > spannableStringBuilder ) ;
407
+ // const spannableStringBuilder = createSpannableStringBuilder(value);
408
+ // nativeView.setText(<any>spannableStringBuilder);
548
409
549
- textProperty . nativeValueChange ( this , value === null || value === undefined ? '' : value . toString ( ) ) ;
410
+ // textProperty.nativeValueChange(this, value === null || value === undefined ? '' : value.toString());
550
411
551
412
// if (spannableStringBuilder && nativeView instanceof android.widget.Button && !(nativeView.getTransformationMethod() instanceof TextTransformation)) {
552
413
// // Replace Android Button's default transformation (in case the developer has not already specified a text-transform) method
@@ -622,13 +483,11 @@ export class Label extends LabelBase {
622
483
// }
623
484
[ colorProperty . setNative ] ( value : Color | android . content . res . ColorStateList ) {
624
485
// profile('colorProperty', () => {
625
- if ( ! this . formattedText || ! ( value instanceof Color ) ) {
626
486
if ( value instanceof Color ) {
627
487
this . nativeTextViewProtected . setTextColor ( value . android ) ;
628
488
} else {
629
489
this . nativeTextViewProtected . setTextColor ( value ) ;
630
490
}
631
- }
632
491
// })();
633
492
}
634
493
@@ -638,13 +497,11 @@ export class Label extends LabelBase {
638
497
// }
639
498
[ fontSizeProperty . setNative ] ( value : number | { nativeSize : number } ) {
640
499
// profile('fontSizeProperty', () => {
641
- if ( ! this . formattedText || typeof value !== 'number' ) {
642
500
if ( typeof value === 'number' ) {
643
501
this . nativeTextViewProtected . setTextSize ( value ) ;
644
502
} else {
645
503
this . nativeTextViewProtected . setTextSize ( android . util . TypedValue . COMPLEX_UNIT_PX , value . nativeSize ) ;
646
504
}
647
- }
648
505
// })();
649
506
}
650
507
@@ -664,7 +521,7 @@ export class Label extends LabelBase {
664
521
// }
665
522
[ fontInternalProperty . setNative ] ( value : Font | android . graphics . Typeface ) {
666
523
// profile('fontInternalProperty', () => {
667
- if ( ! this . formattedText || ! ( value instanceof Font ) ) {
524
+ if ( ! ( value instanceof Font ) ) {
668
525
this . nativeTextViewProtected . setTypeface ( value instanceof Font ? value . getAndroidTypeface ( ) : value ) ;
669
526
}
670
527
// })();
@@ -752,8 +609,12 @@ export class Label extends LabelBase {
752
609
}
753
610
754
611
let transformedText : any ;
755
- if ( this . formattedText ) {
612
+ if ( this . html ) {
613
+ transformedText = ( com as any ) . nativescript . label . Font . stringBuilderFromHtmlString ( context , fontPath , this . html ) ;
614
+ textProperty . nativeValueChange ( this , this . html === null || this . html === undefined ? '' : this . html ) ;
615
+ } else if ( this . formattedText ) {
756
616
transformedText = createSpannableStringBuilder ( this . formattedText ) ;
617
+ textProperty . nativeValueChange ( this , this . formattedText === null || this . formattedText === undefined ? '' : this . formattedText . toString ( ) ) ;
757
618
} else {
758
619
const text = this . text ;
759
620
const stringValue = text === null || text === undefined ? '' : text . toString ( ) ;
@@ -842,11 +703,11 @@ export class Label extends LabelBase {
842
703
this . _resumeNativeUpdates ( SuspendType . UISetup ) ;
843
704
// })();
844
705
845
- this . eachChild ( child => {
846
- child . _setupUI ( context ) ;
706
+ // this.eachChild(child => {
707
+ // child._setupUI(context);
847
708
848
- return true ;
849
- } ) ;
709
+ // return true;
710
+ // });
850
711
}
851
712
}
852
713
0 commit comments