1
- import { htmlProperty , LabelBase , lineBreakProperty , maxLinesProperty } from './label-common' ;
1
+ import { htmlProperty , LabelBase , lineBreakProperty , maxLinesProperty , textShadowProperty } from './label-common' ;
2
2
// import { backgroundColorProperty } from 'tns-core-modules/ui/page/page';
3
- import { TextTransform , WhiteSpace , whiteSpaceProperty } from 'tns-core-modules/ui/text-base/text-base' ;
3
+ import { TextTransform , VerticalAlignment , verticalAlignmentProperty , WhiteSpace , whiteSpaceProperty } from 'tns-core-modules/ui/text-base/text-base' ;
4
4
import { Font } from 'tns-core-modules/ui/styling/font' ;
5
+ import { layout } from 'tns-core-modules/utils/utils' ;
6
+
5
7
Font . prototype . getAndroidTypeface = function ( ) {
6
8
if ( ! this . _typeface ) {
7
9
this . _typeface = createTypeface ( this ) ;
@@ -19,17 +21,25 @@ function useAndroidX() {
19
21
}
20
22
return _useAndroidX ;
21
23
}
22
- let _ContentPackageName : typeof android . support . v4 . content ;
24
+ let _HtmlCompat : typeof androidx . core . text . HtmlCompat ;
25
+ function HtmlCompat ( ) {
26
+ if ( _HtmlCompat === undefined ) {
27
+ _HtmlCompat = useAndroidX ( ) ? ( global as any ) . androidx . core . text . HtmlCompat : android . text . Html ;
28
+ }
29
+ return _HtmlCompat ;
30
+ }
31
+ let _ContentPackageName : typeof androidx . core . content ;
23
32
function ContentPackageName ( ) {
24
33
if ( _ContentPackageName === undefined ) {
25
- _ContentPackageName = useAndroidX ( ) ? ( global as any ) . androidx . core . content : android . support . v4 . content ;
34
+ _ContentPackageName = useAndroidX ( ) ? ( global as any ) . androidx . core . content : ( android as any ) . support . v4 . content ;
26
35
}
27
36
return _ContentPackageName ;
28
37
}
29
38
import * as application from 'tns-core-modules/application' ;
30
39
import * as fs from 'tns-core-modules/file-system' ;
31
40
import { categories as traceCategories , isEnabled as traceEnabled , messageType as traceMessageType , write as traceWrite } from 'tns-core-modules/trace' ;
32
41
import { Font as FontBase , FontWeight , genericFontFamilies , parseFontFamily } from 'tns-core-modules/ui/styling/font-common' ;
42
+ import { TextShadow } from './label' ;
33
43
let appAssets : android . content . res . AssetManager ;
34
44
const typefaceCache = new Map < string , android . graphics . Typeface > ( ) ;
35
45
const FONTS_BASE_PATH = '/fonts/' ;
@@ -171,7 +181,8 @@ export class Label extends LabelBase {
171
181
172
182
// This makes the html <a href...> work
173
183
nativeView . setLinksClickable ( false ) ;
174
- nativeView . setMovementMethod ( android . text . method . LinkMovementMethod . getInstance ( ) ) ;
184
+ nativeView . setMovementMethod ( null ) ;
185
+ // nativeView.setMovementMethod(android.text.method.LinkMovementMethod.getInstance());
175
186
}
176
187
177
188
public resetNativeView ( ) : void {
@@ -182,6 +193,7 @@ export class Label extends LabelBase {
182
193
[ htmlProperty . getDefault ] ( ) : string {
183
194
return '' ;
184
195
}
196
+
185
197
[ htmlProperty . setNative ] ( value : string ) {
186
198
// If the data.newValue actually has a <a...> in it; we need to disable autolink mask
187
199
// it internally disables the coloring, but then the <a> links won't work.. So to support both
@@ -192,7 +204,12 @@ export class Label extends LabelBase {
192
204
}
193
205
const nativeView = this . nativeViewProtected ;
194
206
nativeView . setAutoLinkMask ( mask ) ;
195
- const spannableStringBuilder = createSpannableStringBuilder ( android . text . Html . fromHtml ( value ) ) ;
207
+ let spannableStringBuilder : android . text . SpannableStringBuilder ;
208
+ if ( useAndroidX ( ) ) {
209
+ spannableStringBuilder = createSpannableStringBuilder ( HtmlCompat ( ) . fromHtml ( value , HtmlCompat ( ) . FROM_HTML_MODE_COMPACT ) ) ;
210
+ } else {
211
+ spannableStringBuilder = createSpannableStringBuilder ( android . text . Html . fromHtml ( value ) ) ;
212
+ }
196
213
nativeView . setText ( spannableStringBuilder as any ) ;
197
214
198
215
// textProperty.nativeValueChange(this, value === null || value === undefined ? '' : value.toString());
@@ -212,17 +229,56 @@ export class Label extends LabelBase {
212
229
const nativeView = this . nativeTextViewProtected ;
213
230
switch ( value ) {
214
231
case 'end' :
232
+ nativeView . setSingleLine ( true ) ;
215
233
nativeView . setEllipsize ( android . text . TextUtils . TruncateAt . END ) ;
216
234
break ;
217
235
case 'start' :
236
+ nativeView . setSingleLine ( true ) ;
218
237
nativeView . setEllipsize ( android . text . TextUtils . TruncateAt . START ) ;
219
238
break ;
220
239
case 'middle' :
240
+ nativeView . setSingleLine ( true ) ;
221
241
nativeView . setEllipsize ( android . text . TextUtils . TruncateAt . MIDDLE ) ;
222
242
break ;
223
243
case 'none' :
244
+ nativeView . setSingleLine ( false ) ;
245
+ nativeView . setEllipsize ( null ) ;
246
+ break ;
247
+ }
248
+ }
249
+
250
+ [ whiteSpaceProperty . setNative ] ( value : WhiteSpace ) {
251
+ const nativeView = this . nativeTextViewProtected ;
252
+ switch ( value ) {
253
+ case 'initial' :
254
+ case 'normal' :
255
+ nativeView . setSingleLine ( false ) ;
224
256
nativeView . setEllipsize ( null ) ;
225
257
break ;
258
+ case 'nowrap' :
259
+ nativeView . setSingleLine ( true ) ;
260
+ nativeView . setEllipsize ( android . text . TextUtils . TruncateAt . END ) ;
261
+ break ;
262
+ }
263
+ }
264
+ [ textShadowProperty . setNative ] ( value : TextShadow ) {
265
+ this . nativeViewProtected . setShadowLayer ( layout . toDevicePixels ( value . blurRadius ) , layout . toDevicePixels ( value . offsetX ) , layout . toDevicePixels ( value . offsetY ) , value . color . android ) ;
266
+ }
267
+
268
+ [ verticalAlignmentProperty . setNative ] ( value : VerticalAlignment ) {
269
+ const horizontalGravity = this . nativeTextViewProtected . getGravity ( ) & android . view . Gravity . HORIZONTAL_GRAVITY_MASK ;
270
+ switch ( value ) {
271
+ case 'stretch' :
272
+ case 'top' :
273
+ this . nativeTextViewProtected . setGravity ( android . view . Gravity . TOP | horizontalGravity ) ;
274
+ break ;
275
+ case 'middle' :
276
+ this . nativeTextViewProtected . setGravity ( android . view . Gravity . CENTER_VERTICAL | horizontalGravity ) ;
277
+ break ;
278
+
279
+ case 'bottom' :
280
+ this . nativeTextViewProtected . setGravity ( android . view . Gravity . BOTTOM | horizontalGravity ) ;
281
+ break ;
226
282
}
227
283
}
228
284
}
0 commit comments