mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-26 11:17:04 +08:00
feat(text): add css text-align justify (#9573)
Co-authored-by: Igor Randjelovic <rigor789@gmail.com> Co-authored-by: Nathan Walker <walkerrunpdx@gmail.com>
This commit is contained in:

committed by
GitHub

parent
35fe4811bf
commit
1de5295ad9
7
packages/core/core-types/index.d.ts
vendored
7
packages/core/core-types/index.d.ts
vendored
@ -104,7 +104,7 @@ export namespace CoreTypes {
|
||||
export const send: string;
|
||||
}
|
||||
|
||||
export type TextAlignmentType = 'initial' | 'left' | 'center' | 'right';
|
||||
export type TextAlignmentType = 'initial' | 'left' | 'center' | 'right' | 'justify';
|
||||
/**
|
||||
* Represents a text-align enumeration.
|
||||
*/
|
||||
@ -123,6 +123,11 @@ export namespace CoreTypes {
|
||||
* Represents right text-align.
|
||||
*/
|
||||
export const right: TextAlignmentType;
|
||||
|
||||
/**
|
||||
* Represents justify text-align.
|
||||
*/
|
||||
export const justify: TextAlignmentType;
|
||||
}
|
||||
|
||||
export type OrientationType = 'horizontal' | 'vertical';
|
||||
|
@ -57,11 +57,12 @@ export namespace CoreTypes {
|
||||
export const send = 'send';
|
||||
}
|
||||
|
||||
export type TextAlignmentType = 'initial' | 'left' | 'center' | 'right';
|
||||
export type TextAlignmentType = 'initial' | 'left' | 'center' | 'right' | 'justify';
|
||||
export module TextAlignment {
|
||||
export const left = 'left';
|
||||
export const center = 'center';
|
||||
export const right = 'right';
|
||||
export const justify = 'justify';
|
||||
}
|
||||
|
||||
export type TextDecorationType = 'none' | 'underline' | 'line-through' | 'underline line-through';
|
||||
|
@ -286,18 +286,22 @@ export class TextBase extends TextBaseCommon {
|
||||
[textAlignmentProperty.setNative](value: CoreTypes.TextAlignmentType) {
|
||||
const verticalGravity = this.nativeTextViewProtected.getGravity() & android.view.Gravity.VERTICAL_GRAVITY_MASK;
|
||||
switch (value) {
|
||||
case 'initial':
|
||||
case 'left':
|
||||
this.nativeTextViewProtected.setGravity(android.view.Gravity.START | verticalGravity);
|
||||
break;
|
||||
|
||||
case 'center':
|
||||
this.nativeTextViewProtected.setGravity(android.view.Gravity.CENTER_HORIZONTAL | verticalGravity);
|
||||
break;
|
||||
|
||||
case 'right':
|
||||
this.nativeTextViewProtected.setGravity(android.view.Gravity.END | verticalGravity);
|
||||
break;
|
||||
default: // initial | left | justify
|
||||
this.nativeTextViewProtected.setGravity(android.view.Gravity.START | verticalGravity);
|
||||
break;
|
||||
}
|
||||
if (android.os.Build.VERSION.SDK_INT >= 25) {
|
||||
if (value === 'justify') {
|
||||
this.nativeTextViewProtected.setJustificationMode(android.text.Layout.JUSTIFICATION_MODE_INTER_WORD);
|
||||
} else {
|
||||
this.nativeTextViewProtected.setJustificationMode(android.text.Layout.JUSTIFICATION_MODE_NONE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -171,6 +171,9 @@ export class TextBase extends TextBaseCommon {
|
||||
case 'right':
|
||||
nativeView.textAlignment = NSTextAlignment.Right;
|
||||
break;
|
||||
case 'justify':
|
||||
nativeView.textAlignment = NSTextAlignment.Justified;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -246,7 +246,7 @@ export function getClosestPropertyValue<T>(property: CssProperty<any, T>, span:
|
||||
}
|
||||
}
|
||||
|
||||
const textAlignmentConverter = makeParser<CoreTypes.TextAlignmentType>(makeValidator<CoreTypes.TextAlignmentType>('initial', 'left', 'center', 'right'));
|
||||
const textAlignmentConverter = makeParser<CoreTypes.TextAlignmentType>(makeValidator<CoreTypes.TextAlignmentType>('initial', 'left', 'center', 'right', 'justify'));
|
||||
export const textAlignmentProperty = new InheritedCssProperty<Style, CoreTypes.TextAlignmentType>({
|
||||
name: 'textAlignment',
|
||||
cssName: 'text-align',
|
||||
|
Reference in New Issue
Block a user